示例#1
0
文件: links.py 项目: haikyuu/edgedb
    def _apply_field_ast(self, schema, context, node, op):
        objtype = context.get(LinkSourceCommandContext)

        if op.property == 'required':
            # Due to how SDL is processed the underlying AST may be an
            # AlterConcreteLink, which requires different handling.
            if isinstance(node, qlast.CreateConcreteLink):
                node.is_required = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name='required',
                        value=op.new_value,
                    ))
        elif op.property == 'cardinality':
            node.cardinality = op.new_value
        elif op.property == 'target' and objtype:
            # Due to how SDL is processed the underlying AST may be an
            # AlterConcreteLink, which requires different handling.
            if isinstance(node, qlast.CreateConcreteLink):
                if not node.target:
                    expr = self.get_attribute_value('expr')
                    if expr is not None:
                        node.target = expr.qlast
                    else:
                        t = op.new_value
                        node.target = utils.typeref_to_ast(schema, t)
            else:
                node.commands.append(
                    qlast.SetLinkType(
                        type=utils.typeref_to_ast(schema, op.new_value)))
        elif op.property == 'on_target_delete':
            node.commands.append(qlast.OnTargetDelete(cascade=op.new_value))
        else:
            super()._apply_field_ast(schema, context, node, op)
示例#2
0
    def _apply_field_ast(self, schema, context, node, op):
        link = context.get(PropertySourceContext)

        if op.property == 'required':
            if isinstance(node, qlast.CreateConcreteProperty):
                node.is_required = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name='required',
                        value=op.new_value,
                    ),
                )
        elif op.property == 'cardinality':
            node.cardinality = op.new_value
        elif op.property == 'target' and link:
            if isinstance(node, qlast.CreateConcreteProperty):
                expr = self.get_attribute_value('expr')
                if expr is not None:
                    node.target = expr.qlast
                else:
                    t = op.new_value
                    node.target = utils.typeref_to_ast(schema, t)
            else:
                node.commands.append(
                    qlast.SetPropertyType(
                        type=utils.typeref_to_ast(schema, op.new_value)
                    )
                )
        else:
            super()._apply_field_ast(schema, context, node, op)
示例#3
0
    def _apply_field_ast(self, schema, context, node, op):
        objtype = context.get(LinkSourceCommandContext)

        if op.property == 'required':
            if isinstance(node, qlast.CreateConcreteLink):
                node.is_required = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name=qlast.ObjectRef(name='required'),
                        value=op.new_value,
                    )
                )
        elif op.property == 'cardinality':
            node.cardinality = op.new_value
        elif op.property == 'target' and objtype:
            if isinstance(node, qlast.CreateConcreteLink):
                if not node.target:
                    t = op.new_value
                    node.target = utils.typeref_to_ast(schema, t)
            else:
                node.commands.append(
                    qlast.SetLinkType(
                        type=utils.typeref_to_ast(schema, op.new_value)
                    )
                )
        else:
            super()._apply_field_ast(schema, context, node, op)
示例#4
0
    def _apply_field_ast(
        self,
        schema: s_schema.Schema,
        context: sd.CommandContext,
        node: qlast.DDLOperation,
        op: sd.AlterObjectProperty,
    ) -> None:
        if op.property == 'delegated':
            if isinstance(node, qlast.CreateConcreteConstraint):
                assert isinstance(op.new_value, bool)
                node.delegated = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name='delegated',
                        value=op.new_value,
                    )
                )
            return
        elif op.property == 'args':
            assert isinstance(op.new_value, s_expr.ExpressionList)
            node.args = [arg.qlast for arg in op.new_value]
            return

        super()._apply_field_ast(schema, context, node, op)
示例#5
0
文件: delta.py 项目: joe2hpimn/edgedb
 def _apply_field_ast(self, schema, context, node, op):
     if op.property in {'is_abstract', 'is_final'}:
         node.commands.append(
             qlast.SetSpecialField(name=op.property, value=op.new_value))
     elif op.property == 'bases':
         self._apply_rebase_ast(context, node, op)
     else:
         super()._apply_field_ast(schema, context, node, op)
示例#6
0
文件: sdl.py 项目: Hadryan/edgedb
 def reduce_CreateAliasShortStmt(self, *kids):
     r"""%reduce
         ALIAS NodeName ASSIGN Expr
     """
     self.val = qlast.CreateAlias(
         name=kids[1].val,
         commands=[qlast.SetSpecialField(
             name='expr',
             value=kids[3].val,
         )])
示例#7
0
 def _apply_field_ast(self, schema, context, node, op):
     if op.property == 'delegated':
         if isinstance(node, qlast.CreateConcreteConstraint):
             node.delegated = op.new_value
         else:
             node.commands.append(
                 qlast.SetSpecialField(
                     name=qlast.ObjectRef(name='delegated'),
                     value=op.new_value,
                 )
             )
     else:
         super()._apply_field_ast(schema, context, node, op)
示例#8
0
 def _apply_field_ast(
     self,
     schema: s_schema.Schema,
     context: sd.CommandContext,
     node: qlast.DDLOperation,
     op: sd.AlterObjectProperty,
 ) -> None:
     if (op.property in {'is_abstract', 'is_final'}
             and not isinstance(self, sd.DeleteObject)):
         node.commands.append(
             qlast.SetSpecialField(name=op.property, value=op.new_value))
     else:
         super()._apply_field_ast(schema, context, node, op)
示例#9
0
 def _apply_field_ast(
     self,
     schema: s_schema.Schema,
     context: sd.CommandContext,
     node: qlast.DDLOperation,
     op: sd.AlterObjectProperty,
 ) -> None:
     assert isinstance(node, qlast.ObjectDDL)
     if op.property in {'is_abstract', 'is_final'}:
         node.commands.append(
             qlast.SetSpecialField(name=op.property, value=op.new_value))
     elif op.property == 'bases':
         self._apply_rebase_ast(context, node, op)
     else:
         super()._apply_field_ast(schema, context, node, op)
示例#10
0
    def _apply_field_ast(self, schema, context, node, op):
        if op.property == 'delegated':
            if isinstance(node, qlast.CreateConcreteConstraint):
                node.delegated = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name='delegated',
                        value=op.new_value,
                    ))
            return
        elif op.property == 'args':
            node.args = [arg.qlast for arg in op.new_value]
            return

        super()._apply_field_ast(schema, context, node, op)
示例#11
0
文件: links.py 项目: pnijhara/edgedb
    def _apply_field_ast(
        self,
        schema: s_schema.Schema,
        context: sd.CommandContext,
        node: qlast.DDLOperation,
        op: sd.AlterObjectProperty,
    ) -> None:
        objtype = self.get_referrer_context(context)

        if op.property == 'required':
            # Due to how SDL is processed the underlying AST may be an
            # AlterConcreteLink, which requires different handling.
            if isinstance(node, qlast.CreateConcreteLink):
                assert isinstance(op.new_value, bool)
                node.is_required = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name='required',
                        value=op.new_value,
                    )
                )
        elif op.property == 'cardinality':
            node.cardinality = op.new_value
        elif op.property == 'target' and objtype:
            # Due to how SDL is processed the underlying AST may be an
            # AlterConcreteLink, which requires different handling.
            if isinstance(node, qlast.CreateConcreteLink):
                if not node.target:
                    expr = self.get_attribute_value('expr')
                    if expr is not None:
                        node.target = expr.qlast
                    else:
                        t = op.new_value
                        assert isinstance(t, (so.Object, so.ObjectShell))
                        node.target = utils.typeref_to_ast(schema, t)
            else:
                assert isinstance(op.new_value, (so.Object, so.ObjectShell))
                node.commands.append(
                    qlast.SetLinkType(
                        type=utils.typeref_to_ast(schema, op.new_value)
                    )
                )
        elif op.property == 'on_target_delete':
            node.commands.append(qlast.OnTargetDelete(cascade=op.new_value))
        else:
            super()._apply_field_ast(schema, context, node, op)
示例#12
0
    def _apply_field_ast(self, schema, context, node, op):
        link = context.get(PropertySourceContext)

        if op.property == 'required':
            if isinstance(node, qlast.CreateConcreteProperty):
                node.is_required = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name=qlast.ObjectRef(name='required'),
                        value=op.new_value,
                    ),
                )
        elif op.property == 'cardinality':
            node.cardinality = op.new_value
        elif op.property == 'target' and link:
            node.target = utils.typeref_to_ast(schema, op.new_value)
        else:
            super()._apply_field_ast(schema, context, node, op)
示例#13
0
    def _apply_field_ast(self, schema, context, node, op):
        subjectexpr = self.get_attribute_value('subjectexpr')
        if subjectexpr is not None:
            # add subjectexpr to the node
            node.subjectexpr = subjectexpr.qlast

        if op.property == 'delegated':
            if isinstance(node, qlast.CreateConcreteConstraint):
                node.delegated = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name=qlast.ObjectRef(name='delegated'),
                        value=op.new_value,
                    )
                )
        elif op.property == 'args':
            node.args = [arg.qlast for arg in op.new_value]
        else:
            super()._apply_field_ast(schema, context, node, op)
示例#14
0
    def _apply_field_ast(
        self,
        schema: s_schema.Schema,
        context: sd.CommandContext,
        node: qlast.DDLOperation,
        op: sd.AlterObjectProperty,
    ) -> None:
        # type ignore below, because the class is used as mixin
        link = context.get(PropertySourceContext)  # type: ignore

        if op.property == 'required':
            if isinstance(node, qlast.CreateConcreteProperty):
                node.is_required = bool(op.new_value)
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name='required',
                        value=op.new_value,
                    ),
                )
        elif op.property == 'cardinality':
            node.cardinality = op.new_value
        elif op.property == 'target' and link:
            if isinstance(node, qlast.CreateConcreteProperty):
                expr = self.get_attribute_value('expr')
                if expr is not None:
                    node.target = expr.qlast
                else:
                    ref = op.new_value
                    assert isinstance(ref, (so.Object, so.ObjectShell))
                    node.target = utils.typeref_to_ast(schema, ref)
            else:
                ref = op.new_value
                assert isinstance(ref, (so.Object, so.ObjectShell))
                node.commands.append(
                    qlast.SetPropertyType(
                        type=utils.typeref_to_ast(schema, ref)
                    )
                )
        else:
            super()._apply_field_ast(schema, context, node, op)
示例#15
0
 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.SetLinkType(type=utils.typeref_to_ast(
                     schema, op.new_value), ), )
     elif op.property == 'required':
         node.commands.append(
             qlast.SetSpecialField(
                 name='required',
                 value=op.new_value,
             ), )
     else:
         super()._apply_field_ast(schema, context, node, op)
示例#16
0
文件: sdl.py 项目: Hadryan/edgedb
 def reduce_USING_ParenExpr(self, *kids):
     self.val = qlast.SetSpecialField(name='expr', value=kids[1].val)
示例#17
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_SET_ABSTRACT(self, *kids):
     self.val = qlast.SetSpecialField(name='is_abstract', value=True)
示例#18
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_DROP_REQUIRED(self, *kids):
     self.val = qlast.SetSpecialField(
         name='required',
         value=False,
     )
示例#19
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_SET_REQUIRED(self, *kids):
     self.val = qlast.SetSpecialField(
         name='required',
         value=True,
     )
示例#20
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_DROP_ABSTRACT(self, *kids):
     self.val = qlast.SetSpecialField(name='is_abstract', value=False)
示例#21
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_DROP_FINAL(self, *kids):
     self.val = qlast.SetSpecialField(name='is_final', value=False)
示例#22
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_SET_FINAL(self, *kids):
     self.val = qlast.SetSpecialField(name='is_final', value=True)
示例#23
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_SET_MULTI(self, *kids):
     self.val = qlast.SetSpecialField(
         name='cardinality',
         value=qltypes.Cardinality.MANY,
     )
示例#24
0
文件: ddl.py 项目: alipqb/edgedb
 def reduce_SET_SINGLE(self, *kids):
     self.val = qlast.SetSpecialField(
         name='cardinality',
         value=qltypes.Cardinality.ONE,
     )