Example #1
0
    def get_id(self):
        raw_name = self.constraint.raw_constraint_name()
        name = common.edgedb_name_to_pg_name('{}#{}'.format(
            raw_name, self.index))
        name = common.quote_ident(name)

        return '{} ON {} {}'.format(name, self.constraint.get_subject_type(),
                                    self.constraint.get_subject_name())
Example #2
0
    def get_id(self):
        raw_name = self.constraint.raw_constraint_name()
        name = common.edgedb_name_to_pg_name(
            '{}#{}'.format(raw_name, self.index))
        name = common.quote_ident(name)

        return '{} ON {} {}'.format(
            name, self.constraint.get_subject_type(),
            self.constraint.get_subject_name())
Example #3
0
    def visit_RangeVar(self, node):
        rel = node.relation

        if isinstance(rel, pgast.Relation):
            self.visit(rel)
        elif isinstance(rel, pgast.CommonTableExpr):
            self.write(common.quote_ident(rel.name))
        else:
            raise SQLSourceGeneratorError(
                'unexpected relation in RangeVar: {!r}'.format(rel))

        if node.alias:
            self.write(' AS ')
            self.visit(node.alias)
Example #4
0
    def visit_RangeVar(self, node):
        rel = node.relation

        if isinstance(rel, pgast.Relation):
            self.visit(rel)
        elif isinstance(rel, pgast.CommonTableExpr):
            self.write(common.quote_ident(rel.name))
        else:
            raise SQLSourceGeneratorError(
                'unexpected relation in RangeVar: {!r}'.format(rel))

        if node.alias:
            self.write(' AS ')
            self.visit(node.alias)
Example #5
0
    def gen_ctes(self, ctes):
        self.write('WITH')
        count = len(ctes)
        for i, cte in enumerate(ctes):
            self.new_lines = 1
            if getattr(cte, 'recursive', None):
                self.write('RECURSIVE ')
            self.write(common.quote_ident(cte.name))
            self.write(' AS ')
            self.indentation += 1
            self.new_lines = 1
            self.write('(')
            self.visit(cte.query)
            self.write(')')
            if i != count - 1:
                self.write(',')
            self.indentation -= 1

        self.new_lines = 1
Example #6
0
    def gen_ctes(self, ctes):
        self.write('WITH')
        count = len(ctes)
        for i, cte in enumerate(ctes):
            self.new_lines = 1
            if getattr(cte, 'recursive', None):
                self.write('RECURSIVE ')
            self.write(common.quote_ident(cte.name))
            self.write(' AS ')
            self.indentation += 1
            self.new_lines = 1
            self.write('(')
            self.visit(cte.query)
            self.write(')')
            if i != count - 1:
                self.write(',')
            self.indentation -= 1

        self.new_lines = 1
Example #7
0
    async def creation_code(self, context):
        link_map = await context.get_class_map()

        ids = tuple(sorted(list(link_map[n] for n in self.link_names)))
        id_str = '_'.join(str(i) for i in ids)

        name = '%s_%s_%s_cardinality_idx' % (
            self.name_prefix, id_str, self.cardinality)
        name = common.edgedb_name_to_pg_name(name)
        predicate = 'ptr_item_id IN (%s)' % ', '.join(str(id) for id in ids)

        code = '''
            CREATE {unique} INDEX {name} ON {table}s ({cols}) {predicate}
        '''.format(unique='UNIQUE',
                   name=common.qname(name),
                   table=common.qname(*self.table_name),
                   cols=', '.join(common.quote_ident(c) for c in self.columns),
                   predicate=('WHERE {}'.format(predicate)))

        return code
Example #8
0
    async def creation_code(self, context):
        link_map = await context.get_class_map()

        ids = tuple(sorted(list(link_map[n] for n in self.link_names)))
        id_str = '_'.join(str(i) for i in ids)

        name = '%s_%s_%s_cardinality_idx' % (self.name_prefix, id_str,
                                             self.cardinality)
        name = common.edgedb_name_to_pg_name(name)
        predicate = 'ptr_item_id IN (%s)' % ', '.join(str(id) for id in ids)

        code = '''
            CREATE {unique} INDEX {name} ON {table}s ({cols}) {predicate}
        '''.format(unique='UNIQUE',
                   name=common.qname(name),
                   table=common.qname(*self.table_name),
                   cols=', '.join(common.quote_ident(c) for c in self.columns),
                   predicate=('WHERE {}'.format(predicate)))

        return code
Example #9
0
 def numbered_constraint_name(self, i, quote=True):
     raw_name = self.raw_constraint_name()
     name = common.edgedb_name_to_pg_name('{}#{}'.format(raw_name, i))
     return common.quote_ident(name) if quote else name
Example #10
0
 def visit_ColumnDef(self, node):
     self.write(common.quote_ident(node.name))
     if node.typename:
         self.write(' ')
         self.visit(node.typename)
Example #11
0
 def visit_UpdateTarget(self, node):
     self.write(common.quote_ident(node.name))
     self.write(' = ')
     self.visit(node.val)
Example #12
0
 def visit_Alias(self, node):
     self.write(common.quote_ident(node.aliasname))
     if node.colnames:
         self.write('(')
         self.write(', '.join(common.quote_ident(n) for n in node.colnames))
         self.write(')')
Example #13
0
 def visit_Alias(self, node):
     self.write(common.quote_ident(node.aliasname))
     if node.colnames:
         self.write('(')
         self.write(', '.join(common.quote_ident(n) for n in node.colnames))
         self.write(')')
Example #14
0
 def visit_UpdateTarget(self, node):
     self.write(common.quote_ident(node.name))
     self.write(' = ')
     self.visit(node.val)
Example #15
0
 def visit_ResTarget(self, node):
     self.visit(node.val)
     if node.name:
         self.write(' AS ' + common.quote_ident(node.name))
Example #16
0
 def constraint_name(self, quote=True):
     name = self.raw_constraint_name()
     name = common.edgedb_name_to_pg_name(name)
     return common.quote_ident(name) if quote else name
Example #17
0
 def visit_ColumnDef(self, node):
     self.write(common.quote_ident(node.name))
     if node.typename:
         self.write(' ')
         self.visit(node.typename)
Example #18
0
 def numbered_constraint_name(self, i, quote=True):
     raw_name = self.raw_constraint_name()
     name = common.edgedb_name_to_pg_name('{}#{}'.format(raw_name, i))
     return common.quote_ident(name) if quote else name
Example #19
0
 def constraint_name(self, quote=True):
     name = self.raw_constraint_name()
     name = common.edgedb_name_to_pg_name(name)
     return common.quote_ident(name) if quote else name
Example #20
0
 def visit_ResTarget(self, node):
     self.visit(node.val)
     if node.name:
         self.write(' AS ' + common.quote_ident(node.name))
Example #21
0
 async def code(self, context):
     name = common.quote_ident(self.get_extension_name())
     schema = common.quote_ident(self.schema)
     return 'CREATE EXTENSION {} WITH SCHEMA {}'.format(name, schema)
Example #22
0
 async def code(self, context):
     name = common.quote_ident(self.get_extension_name())
     schema = common.quote_ident(self.schema)
     return 'CREATE EXTENSION {} WITH SCHEMA {}'.format(name, schema)