MCPcopy Create free account
hub / github.com/Vanderhoof/PyDBML / parse_table

Function parse_table

pydbml/definitions/table.py:79–119  ·  view source on GitHub ↗

Table bookings as bb [headercolor: #cccccc] { id integer country varchar [NOT NULL, ref: > countries.country_name] booking_date date unique pk created_at timestamp indexes { (id, country) [pk] // composite primary key } }

(s, loc, tok)

Source from the content-addressed store, hash-verified

77
78
79def parse_table(s, loc, tok):
80 '''
81 Table bookings as bb [headercolor: #cccccc] {
82 id integer
83 country varchar [NOT NULL, ref: > countries.country_name]
84 booking_date date unique pk
85 created_at timestamp
86
87 indexes {
88 (id, country) [pk] // composite primary key
89 }
90 }
91 '''
92 init_dict = {
93 'name': tok['name'],
94 }
95 if 'schema' in tok:
96 init_dict['schema'] = tok['schema']
97 if 'settings' in tok:
98 init_dict.update(tok['settings'])
99 if 'alias' in tok:
100 init_dict['alias'] = tok['alias'][0]
101 if 'note' in tok:
102 # will override one from settings
103 init_dict['note'] = tok['note'][0]
104 if 'indexes' in tok:
105 init_dict['indexes'] = tok['indexes'][0]
106 if 'columns' in tok:
107 init_dict['columns'] = tok['columns']
108 if 'comment_before' in tok:
109 comment = '\n'.join(c[0] for c in tok['comment_before'])
110 init_dict['comment'] = comment
111 if 'property' in tok:
112 init_dict['properties'] = {k: v for k, v in tok['property']}
113
114 if not init_dict.get('columns'):
115 raise SyntaxError(f'Table {init_dict["name"]} at position {loc} has no columns!')
116
117 result = TableBlueprint(**init_dict)
118
119 return result
120
121
122table.set_parse_action(parse_table)

Callers

nothing calls this directly

Calls 2

TableBlueprintClass · 0.90
getMethod · 0.80

Tested by

no test coverage detected