def serialize_ast(node, context): if node.is_enum: # <ast::op>'Add' return IR.enum_member(node.base_name, node.kind_name) else: # (INSERT ast::BinOp {.left := ..., ...}) reference = apply_ast(node, context) context.new_reference(reference.id) # (SELECT ast::expr FILTER .id = ... LIMIT 1) return IR.select( node.base_name, filters=IR.object_ref(reference), limit=1 )
from reiz.serialization.statistics import Insertion, Statistics from reiz.utilities import _available_cores, guarded, logger @guarded(Insertion.FAILED, ignored_exceptions=(InternalDatabaseError, )) def insert_file(context): if context.is_cached(): return Insertion.CACHED if not (tree := context.as_ast()): return Insertion.SKIPPED with context.connection.transaction(): module = apply_ast(tree, context) module_select = IR.select(tree.kind_name, filters=IR.object_ref(module), limit=1) update_filter = IR.filter( IR.attribute(None, "id"), IR.call("array_unpack", [IR.cast("array<uuid>", IR.variable("ids"))]), "IN", ) for base_type in Schema.module_annotated_types: update = IR.update( base_type.kind_name, filters=update_filter, assignments={"_module": module_select}, ) context.connection.query(IR.construct(update),