本文整理匯總了Python中sqlalchemy.schema.CreateColumn方法的典型用法代碼示例。如果您正苦於以下問題:Python schema.CreateColumn方法的具體用法?Python schema.CreateColumn怎麽用?Python schema.CreateColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.schema
的用法示例。
在下文中一共展示了schema.CreateColumn方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def __init__(
self, element, on=None, bind=None,
include_foreign_key_constraints=None):
"""Create a :class:`.CreateTable` construct.
:param element: a :class:`.Table` that's the subject
of the CREATE
:param on: See the description for 'on' in :class:`.DDL`.
:param bind: See the description for 'bind' in :class:`.DDL`.
:param include_foreign_key_constraints: optional sequence of
:class:`.ForeignKeyConstraint` objects that will be included
inline within the CREATE construct; if omitted, all foreign key
constraints that do not specify use_alter=True are included.
.. versionadded:: 1.0.0
"""
super(CreateTable, self).__init__(element, on=on, bind=bind)
self.columns = [CreateColumn(column)
for column in element.columns
]
self.include_foreign_key_constraints = include_foreign_key_constraints
示例2: get_table_columns_ddl
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def get_table_columns_ddl(self):
col_descriptors = []
cols = list(self.sa_table.columns)
for col in cols:
# We only want the column name and type.
# There are no NOT NULL, DEFAULT, etc. clauses in Spectrum
# Also, we need to replace some types.
rs_col_cls = col.type.__class__
if rs_col_cls in type_map:
spectrum_col_type = type_map[rs_col_cls]()
else:
spectrum_col_type = col.type
spectrum_col = Column(col.description, spectrum_col_type)
# OK, now get the actual SQL snippet for the column
statement = CreateColumn(spectrum_col).compile().statement
col_descriptors.append(str(statement))
return ',\n '.join(col_descriptors)
示例3: __init__
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def __init__(
self, element, bind=None, include_foreign_key_constraints=None
):
"""Create a :class:`.CreateTable` construct.
:param element: a :class:`_schema.Table` that's the subject
of the CREATE
:param on: See the description for 'on' in :class:`.DDL`.
:param bind: See the description for 'bind' in :class:`.DDL`.
:param include_foreign_key_constraints: optional sequence of
:class:`_schema.ForeignKeyConstraint` objects that will be included
inline within the CREATE construct; if omitted, all foreign key
constraints that do not specify use_alter=True are included.
.. versionadded:: 1.0.0
"""
super(CreateTable, self).__init__(element, bind=bind)
self.columns = [CreateColumn(column) for column in element.columns]
self.include_foreign_key_constraints = include_foreign_key_constraints
示例4: __init__
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def __init__(self, element, on=None, bind=None):
"""Create a :class:`.CreateTable` construct.
:param element: a :class:`.Table` that's the subject
of the CREATE
:param on: See the description for 'on' in :class:`.DDL`.
:param bind: See the description for 'bind' in :class:`.DDL`.
"""
super(CreateTable, self).__init__(element, on=on, bind=bind)
self.columns = [CreateColumn(column)
for column in element.columns
]
示例5: test_on_conflict_clause_column_not_null
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def test_on_conflict_clause_column_not_null(self):
c = Column(
"test", Integer, nullable=False, sqlite_on_conflict_not_null="FAIL"
)
self.assert_compile(
schema.CreateColumn(c),
"test INTEGER NOT NULL " "ON CONFLICT FAIL",
dialect=sqlite.dialect(),
)
示例6: test_timestamp_defaults
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def test_timestamp_defaults(self, spec, kw, expected):
"""Exercise funky TIMESTAMP default syntax when used in columns."""
c = Column("t", *spec, **kw)
Table("t", MetaData(), c)
self.assert_compile(schema.CreateColumn(c), "t %s" % expected)
示例7: test_render_check_constraint_inline_sql_literal
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def test_render_check_constraint_inline_sql_literal(self):
t, t2 = self._constraint_create_fixture()
m = MetaData()
t = Table(
"t",
m,
Column("a", Integer, CheckConstraint(Column("a", Integer) > 5)),
)
self.assert_compile(
schema.CreateColumn(t.c.a), "a INTEGER CHECK (a > 5)"
)
示例8: __init__
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def __init__(self, element, on=None, bind=None):
"""Create a :class:`.CreateTable` construct.
:param element: a :class:`.Table` that's the subject
of the CREATE
:param on: See the description for 'on' in :class:`.DDL`.
:param bind: See the description for 'bind' in :class:`.DDL`.
"""
super(CreateTable, self).__init__(element, on=on, bind=bind)
self.columns = [CreateColumn(column)
for column in element.columns
]
示例9: test_custom_create
# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateColumn [as 別名]
def test_custom_create(self):
from sqlalchemy.ext.compiler import compiles, deregister
@compiles(schema.CreateColumn)
def compile_(element, compiler, **kw):
column = element.element
if "special" not in column.info:
return compiler.visit_create_column(element, **kw)
text = "%s SPECIAL DIRECTIVE %s" % (
column.name,
compiler.type_compiler.process(column.type),
)
default = compiler.get_column_default_string(column)
if default is not None:
text += " DEFAULT " + default
if not column.nullable:
text += " NOT NULL"
if column.constraints:
text += " ".join(
compiler.process(const) for const in column.constraints
)
return text
t = Table(
"mytable",
MetaData(),
Column("x", Integer, info={"special": True}, primary_key=True),
Column("y", String(50)),
Column("z", String(20), info={"special": True}),
)
self.assert_compile(
schema.CreateTable(t),
"CREATE TABLE mytable (x SPECIAL DIRECTIVE INTEGER "
"NOT NULL, y VARCHAR(50), "
"z SPECIAL DIRECTIVE VARCHAR(20), PRIMARY KEY (x))",
)
deregister(schema.CreateColumn)