def _get_ast(self, schema, context): value = self.new_value new_value_empty = \ (value is None or (isinstance(value, collections.abc.Container) and not value)) old_value_empty = \ (self.old_value is None or (isinstance(self.old_value, collections.abc.Container) and not self.old_value)) if new_value_empty and not old_value_empty: op = qlast.DropAnnotationValue( name=qlast.ObjectRef(module='', name=self.property)) return op if new_value_empty and old_value_empty: return if isinstance(value, s_expr.Expression): value = edgeql.parse(value.text) elif utils.is_nontrivial_container(value): value = qlast.Tuple( elements=[qlast.BaseConstant.from_python(el) for el in value]) else: value = qlast.BaseConstant.from_python(value) op = qlast.SetField(name=qlast.ObjectRef(module='', name=self.property), value=value) return op
def reduce_SET_NodeName_AS_SchemaItemClass_NodeName(self, *kids): ref = kids[4].val ref.itemclass = kids[3].val.itemclass self.val = qlast.SetField( name=kids[1].val, value=ref )
def _apply_field_ast( self, schema: s_schema.Schema, context: sd.CommandContext, node: qlast.DDLOperation, op: sd.AlterObjectProperty, ) -> None: if op.property == 'target': if op.new_value: assert isinstance(op.new_value, so.ObjectShell) node.commands.append( qlast.SetPointerType(value=utils.typeref_to_ast( schema, op.new_value), ), ) elif op.property == 'computable': if not op.new_value: node.commands.append( qlast.SetField( name='expr', value=None, special_syntax=True, ), ) elif op.property == 'on_target_delete': node.commands.append(qlast.OnTargetDelete(cascade=op.new_value)) else: super()._apply_field_ast(schema, context, node, op)
def reduce_CreateViewShortStmt(self, *kids): r"""%reduce \ VIEW ShortNodeName ASSIGN Expr \ """ self.val = qlast.CreateView(name=kids[1].val, commands=[ qlast.SetField( name=qlast.ObjectRef(name='expr'), value=kids[3].val, ) ])
def reduce_CreateAliasShortStmt(self, *kids): r"""%reduce ALIAS NodeName ASSIGN Expr """ self.val = qlast.CreateAlias(name=kids[1].val, commands=[ qlast.SetField( name='expr', value=kids[3].val, special_syntax=True, ) ])
def _get_ast(self, schema, context): value = self.new_value new_value_empty = \ (value is None or (isinstance(value, collections.abc.Container) and not value)) old_value_empty = \ (self.old_value is None or (isinstance(self.old_value, collections.abc.Container) and not self.old_value)) parent_ctx = context.current() parent_op = parent_ctx.op field = parent_op.get_schema_metaclass().get_field(self.property) if field is None: raise errors.SchemaDefinitionError( f'{self.property!r} is not a valid field', context=self.context) if not field.allow_ddl_set: return if self.source == 'inheritance': return if new_value_empty and old_value_empty: return if isinstance(value, s_expr.Expression): value = value.qlast elif utils.is_nontrivial_container(value): value = qlast.Tuple( elements=[qlast.BaseConstant.from_python(el) for el in value]) else: value = qlast.BaseConstant.from_python(value) op = qlast.SetField(name=qlast.ObjectRef(module='', name=self.property), value=value) return op
def reduce_ShortNodeName_ASSIGN_Expr(self, *kids): self.val = qlast.SetField(name=kids[0].val, value=kids[2].val)
def reduce_Identifier_ASSIGN_Expr(self, *kids): self.val = qlast.SetField(name=kids[0].val, value=kids[2].val)
def reduce_USING_ParenExpr(self, *kids): self.val = qlast.SetField( name='expr', value=kids[1].val, special_syntax=True, )
def reduce_SET_NodeName_ASSIGN_Expr(self, *kids): self.val = qlast.SetField( name=kids[1].val, value=kids[3].val, )