def foreignkeyconstraint_repr(self): data = { 'name': repr(self.name), 'names': repr([x.parent.name for x in self.elements]), 'specs': repr([x._get_colspec() for x in self.elements]) } return util.as_out_str(constants.FOREIGN_KEY % data)
def table_repr(self): data = { 'name': self.name, 'columns': constants.NLTAB.join([repr(cl) for cl in self.columns]), 'constraints': constants.NLTAB.join([ repr(cn) for cn in self.constraints if not isinstance(cn, sqlalchemy.PrimaryKeyConstraint) ]), 'index': '', 'schema': self.schema != None and ",\n%sschema='%s'" % (constants.TAB, self.schema) or '', } if data['constraints']: data['constraints'] = '\n%s%s,' % (constants.TAB, data['constraints']) if data['columns']: data['columns'] = '\n%s%s' % (constants.TAB, data['columns']) return util.as_out_str(constants.TABLE % data)
def column_repr(self): kwarg = [] if self.key != self.name: kwarg.append('key') if hasattr(self, 'primary_key'): kwarg.append('primary_key') if not self.nullable: kwarg.append('nullable') if self.onupdate: kwarg.append('onupdate') #issue: #http://www.sqlalchemy.org/trac/wiki/06Migration#AnImportantExpressionLanguageGotcha if self.default is not None: kwarg.append('default') elif self.server_default: self.default = self.server_default.arg kwarg.append('default') ks = ', '.join('%s=%r' % (k, getattr(self, k)) for k in kwarg) name = self.name if not hasattr(config, 'options') and config.options.generictypes: coltype = repr(self.type) elif type(self.type).__module__ == 'sqlalchemy.types': coltype = repr(self.type) else: # Try to 'cast' this column type to a cross-platform type # from sqlalchemy.types, dropping any database-specific type # arguments. for base in type(self.type).__mro__: if (base.__module__ == 'sqlalchemy.types' and base.__name__ in sqlalchemy.__all__): coltype = _repr_coltype_as(self.type, base) break # FIXME: if a dialect has a non-standard type that does not # derive from an ANSI type, there's no choice but to ignore # generic-types and output the exact type. However, import # headers have already been output and lack the required # dialect import. else: coltype = repr(self.type) data = { 'name': self.name, 'type': coltype, 'constraints': ', '.join([repr(cn) for cn in self.constraints]), 'args': ks and ks or '', } if data['constraints']: data['constraints'] = ', ' + data['constraints'] if data['args']: data['args'] = ', ' + data['args'] return util.as_out_str(constants.COLUMN % data)
def column_repr(self): kwarg = [] if self.key != self.name: kwarg.append( 'key') if hasattr(self, 'primary_key'): kwarg.append( 'primary_key') if not self.nullable: kwarg.append( 'nullable') if self.onupdate: kwarg.append( 'onupdate') #issue: #http://www.sqlalchemy.org/trac/wiki/06Migration#AnImportantExpressionLanguageGotcha if self.default is not None: kwarg.append( 'default') elif self.server_default: self.default = self.server_default.arg kwarg.append( 'default') ks = ', '.join('%s=%r' % (k, getattr(self, k)) for k in kwarg ) name = self.name if not hasattr(config, 'options') and config.options.generictypes: coltype = repr(self.type) elif type(self.type).__module__ == 'sqlalchemy.types': coltype = repr(self.type) else: # Try to 'cast' this column type to a cross-platform type # from sqlalchemy.types, dropping any database-specific type # arguments. for base in type(self.type).__mro__: if (base.__module__ == 'sqlalchemy.types' and base.__name__ in sqlalchemy.__all__): coltype = _repr_coltype_as(self.type, base) break # FIXME: if a dialect has a non-standard type that does not # derive from an ANSI type, there's no choice but to ignore # generic-types and output the exact type. However, import # headers have already been output and lack the required # dialect import. else: coltype = repr(self.type) data = {'name': self.name, 'type': coltype, 'constraints': ', '.join([repr(cn) for cn in self.constraints]), 'args': ks and ks or '', } if data['constraints']: data['constraints'] = ', ' + data['constraints'] if data['args']: data['args'] = ', ' + data['args'] return util.as_out_str(constants.COLUMN % data)
def index_repr(index): cols = [] for column in index.columns: # FIXME: still punting on the issue of unicode table names if util.is_python_identifier(column.name): cols.append('%s.c.%s' % (column.table.name, column.name)) else: cols.append('%s.c[%r]' % (column.table.name, column.name)) data = {'name': repr(index.name), 'columns': ', '.join(cols), 'unique': repr(index.unique), } return util.as_out_str(constants.INDEX % data)
def table_repr(self): data = { 'name': self.name, 'columns': constants.NLTAB.join([repr(cl) for cl in self.columns]), 'constraints': constants.NLTAB.join( [repr(cn) for cn in self.constraints if not isinstance(cn, sqlalchemy.PrimaryKeyConstraint)]), 'index': '', 'schema': self.schema != None and "schema='%s'" % self.schema or '', } if data['constraints']: data['constraints'] = data['constraints'] + ',' return util.as_out_str(constants.TABLE % data)
def foreignkeyconstraint_repr(self): specs = [] for x in self.elements: """Return a string based 'column specification' for this :class:`.ForeignKey`. This is usually the equivalent of the string-based "tablename.colname" argument first passed to the object's constructor. """ _, tname, colname = x._column_tokens specs.append("%s.%s" % (tname, colname)) data = { 'name': repr(self.name), 'names': repr([x.parent.name for x in self.elements]), # 'specs': repr([x._get_colspec() for x in self.elements]) 'specs': repr(specs) } return util.as_out_str(constants.FOREIGN_KEY % data)
def table_repr(self): data = { 'name': self.name, 'columns': constants.NLTAB.join([repr(cl) for cl in self.columns]), 'constraints': constants.NLTAB.join([ repr(cn) for cn in self.constraints if not isinstance(cn, sqlalchemy.PrimaryKeyConstraint) ]), 'index': '', 'schema': self.schema is not None and "schema='%s'" % self.schema or '', } if data['constraints']: data['constraints'] = data['constraints'] + ',' return util.as_out_str(constants.TABLE % data)
def foreignkeyconstraint_repr(self): data = {'name': repr(self.name), 'names': repr([x.parent.name for x in self.elements]), 'specs': repr([x._get_colspec() for x in self.elements]) } return util.as_out_str(constants.FOREIGN_KEY % data)
def check_constraint_repr(cc): data = {'sqltext': cc.sqltext} return util.as_out_str(constants.CHECK_CONSTRAINT % data)