当前位置: 首页>>代码示例>>Python>>正文


Python schema.CreateColumn方法代码示例

本文整理汇总了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 
开发者ID:jpush,项目名称:jbox,代码行数:24,代码来源:ddl.py

示例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) 
开发者ID:hellonarrativ,项目名称:spectrify,代码行数:22,代码来源:create.py

示例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 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:ddl.py

示例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
                        ] 
开发者ID:gltn,项目名称:stdm,代码行数:15,代码来源:ddl.py

示例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(),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:12,代码来源:test_sqlite.py

示例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) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:8,代码来源:test_types.py

示例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)"
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:15,代码来源:test_constraints.py

示例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
        ] 
开发者ID:binhex,项目名称:moviegrabber,代码行数:15,代码来源:ddl.py

示例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) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:45,代码来源:test_metadata.py


注:本文中的sqlalchemy.schema.CreateColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。