def _rewrite_config_insert(ir_set: irast.Set, *, ctx: context.CompilerContextLevel) -> irast.Set: relctx.add_type_rel_overlay( ir_set.typeref, 'replace', pgast.NullRelation(path_id=ir_set.path_id), path_id=ir_set.path_id, ctx=ctx, ) # Config objects have derived computed ids, # so the autogenerated id must not be returned. ir_set.shape = list( filter( lambda el: el[0].rptr.ptrref.shortname.name != 'id', ir_set.shape, )) for el, _ in ir_set.shape: if isinstance(el.expr, irast.InsertStmt): el.shape = list( filter( lambda e: e[0].rptr.ptrref.shortname.name != 'id', el.shape, )) result = _rewrite_config_insert(el.expr.subject, ctx=ctx) el.expr = irast.SelectStmt( result=result, parent_stmt=el.expr.parent_stmt, ) return ir_set
def new_empty_rvar(ir_set: irast.EmptySet, *, ctx: context.CompilerContextLevel) -> pgast.BaseRangeVar: nullrel = pgast.NullRelation(path_id=ir_set.path_id) rvar = dbobj.rvar_for_rel(nullrel, env=ctx.env) pathctx.put_rvar_path_bond(rvar, ir_set.path_id) rvar.value_scope.add(ir_set.path_id) return rvar
def _rewrite_config_insert(ir_set: irast.Set, *, ctx: context.CompilerContextLevel) -> irast.Set: overwrite_query = pgast.SelectStmt() id_expr = pgast.FuncCall( name=( 'edgedbext', 'uuid_generate_v1mc', ), args=[], ) pathctx.put_path_identity_var(overwrite_query, ir_set.path_id, id_expr, force=True, env=ctx.env) pathctx.put_path_value_var(overwrite_query, ir_set.path_id, id_expr, force=True, env=ctx.env) pathctx.put_path_source_rvar(overwrite_query, ir_set.path_id, relctx.rvar_for_rel(pgast.NullRelation(), ctx=ctx), env=ctx.env) relctx.add_type_rel_overlay( ir_set.typeref, 'replace', overwrite_query, path_id=ir_set.path_id, ctx=ctx, ) # Config objects have derived computed ids, # so the autogenerated id must not be returned. ir_set.shape = tuple( filter( lambda el: ((rptr := el[0].rptr) is not None and rptr.ptrref. shortname.name != 'id'), ir_set.shape, )) for el, _ in ir_set.shape: if isinstance(el.expr, irast.InsertStmt): el.shape = tuple( filter( lambda e: ((rptr := e[0].rptr) is not None and rptr.ptrref. shortname.name != 'id'), el.shape, )) result = _rewrite_config_insert(el.expr.subject, ctx=ctx) el.expr = irast.SelectStmt( result=result, parent_stmt=el.expr.parent_stmt, ) return ir_set
def new_empty_rvar(ir_set: irast.EmptySet, *, ctx: context.CompilerContextLevel) -> pgast.PathRangeVar: nullrel = pgast.NullRelation(path_id=ir_set.path_id) rvar = rvar_for_rel(nullrel, ctx=ctx) pathctx.put_rvar_path_bond(rvar, ir_set.path_id) return rvar