You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AQuery/engine/ddl.py

32 lines
1.0 KiB

# code-gen for data decl languages
from engine.ast import TableInfo, ast_node, include
class create_table(ast_node):
name = 'create_table'
def produce(self, node):
ct = node[self.name]
tbl = self.context.add_table(ct['name'], ct['columns'])
# create tables in k9
for c in ct['columns']:
self.emit(f"{tbl.get_k9colname(c['name'])}:()")
class insert(ast_node):
name = 'insert'
def produce(self, node):
ct = node[self.name]
table:TableInfo = self.context.tables_byname[ct]
values = node['query']['select']
if len(values) != table.n_cols:
raise ValueError("Column Mismatch")
for i, s in enumerate(values):
if 'value' in s:
k9name = table.columns[i][0]
self.emit(f"{k9name}:{k9name},{s['value']}")
else:
# subquery, dispatch to select astnode
pass
import sys
include(sys.modules[__name__])