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())
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())
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)
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
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
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
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
def visit_ColumnDef(self, node): self.write(common.quote_ident(node.name)) if node.typename: self.write(' ') self.visit(node.typename)
def visit_UpdateTarget(self, node): self.write(common.quote_ident(node.name)) self.write(' = ') self.visit(node.val)
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(')')
def visit_ResTarget(self, node): self.visit(node.val) if node.name: self.write(' AS ' + common.quote_ident(node.name))
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
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)