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


Python schema.CreateTable方法代码示例

本文整理汇总了Python中sqlalchemy.schema.CreateTable方法的典型用法代码示例。如果您正苦于以下问题:Python schema.CreateTable方法的具体用法?Python schema.CreateTable怎么用?Python schema.CreateTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.schema的用法示例。


在下文中一共展示了schema.CreateTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def create_table(request, sa_table, database, loop, create_entries):
    async def f(rows):
        create_expr = CreateTable(sa_table)
        async with database.acquire() as conn:
            await conn.execute(create_expr)
            values = create_entries(rows)
            query1 = sa_table.insert().values(values)
            await conn.execute(query1)
            await conn.execute('commit;')
        return sa_table

    yield f

    async def fin():
        drop_expr = DropTable(sa_table)
        async with database.acquire() as conn:
            await conn.execute(drop_expr)
            await conn.execute('commit;')

    loop.run_until_complete(fin()) 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:22,代码来源:db_fixtures.py

示例2: create_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def create_table(self, table):
        table.dispatch.before_create(
            table, self.connection, checkfirst=False, _ddl_runner=self
        )
        self._exec(schema.CreateTable(table))
        table.dispatch.after_create(
            table, self.connection, checkfirst=False, _ddl_runner=self
        )
        for index in table.indexes:
            self._exec(schema.CreateIndex(index))

        with_comment = (
            sqla_compat._dialect_supports_comments(self.dialect)
            and not self.dialect.inline_comments
        )
        comment = sqla_compat._comment_attribute(table)
        if comment and with_comment:
            self.create_table_comment(table)

        for column in table.columns:
            comment = sqla_compat._comment_attribute(column)
            if comment and with_comment:
                self.create_column_comment(column) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:25,代码来源:impl.py

示例3: print_create_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def print_create_table(tables):
    app.config.from_object('config.default')
    database.init_app(app)

    engine = database.session.get_bind()

    for class_name in tables:
        cls = get_class(class_name)

        for c in cls.__table__.columns:
            if not isinstance(c.type, Enum):
                continue
            t = c.type
            sql = str(CreateEnumType(t).compile(engine))
            click.echo(sql.strip() + ';')

        for index in cls.__table__.indexes:
            sql = str(CreateIndex(index).compile(engine))
            click.echo(sql.strip() + ';')

        sql = str(CreateTable(cls.__table__).compile(engine))
        click.echo(sql.strip() + ';') 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:24,代码来源:cli.py

示例4: test_create_table_simple

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_simple(self, compiler):

        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True),
                      Column('name', String))

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:18,代码来源:test_ddl_compiler.py

示例5: test_create_table_with_identity

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_with_identity(self, compiler):

        table = Table(
            't1',
            MetaData(),
            Column('id', Integer, primary_key=True, redshift_identity=[1, 2]),
            Column('name', String),
        )

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER IDENTITY(1,2) NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:20,代码来源:test_ddl_compiler.py

示例6: test_create_table_with_diststyle

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_with_diststyle(self, compiler):

        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True),
                      Column('name', String),
                      redshift_diststyle="EVEN")

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n) "
            u"DISTSTYLE EVEN\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:20,代码来源:test_ddl_compiler.py

示例7: test_create_table_with_distkey

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_with_distkey(self, compiler):

        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True),
                      Column('name', String),
                      redshift_distkey="id")

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n) "
            u"DISTKEY (id)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:20,代码来源:test_ddl_compiler.py

示例8: test_create_table_with_sortkey

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_with_sortkey(self, compiler):

        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True),
                      Column('name', String),
                      redshift_sortkey="id")

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n) "
            u"SORTKEY (id)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:20,代码来源:test_ddl_compiler.py

示例9: test_create_table_with_unicode_sortkey

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_with_unicode_sortkey(self, compiler):
        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True),
                      Column('name', String),
                      redshift_sortkey=u"id")

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n) "
            u"SORTKEY (id)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:19,代码来源:test_ddl_compiler.py

示例10: test_create_table_with_multiple_sortkeys

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_with_multiple_sortkeys(self, compiler):

        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True),
                      Column('name', String),
                      redshift_sortkey=["id", "name"])

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n) "
            u"SORTKEY (id, name)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:20,代码来源:test_ddl_compiler.py

示例11: test_create_table_all_together

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_table_all_together(self, compiler):
        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True),
                      Column('name', String),
                      redshift_diststyle="KEY",
                      redshift_distkey="id",
                      redshift_sortkey=["id", "name"])

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n) "
            u"DISTSTYLE KEY DISTKEY (id) SORTKEY (id, name)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:21,代码来源:test_ddl_compiler.py

示例12: test_create_column_with_distkey

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_column_with_distkey(self, compiler):
        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True,
                             redshift_distkey=True),
                      Column('name', String)
                      )

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER DISTKEY NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:19,代码来源:test_ddl_compiler.py

示例13: test_create_column_with_encoding

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_create_column_with_encoding(self, compiler):
        table = Table('t1',
                      MetaData(),
                      Column('id', Integer, primary_key=True,
                             redshift_encode="LZO"),
                      Column('name', String)
                      )

        create_table = CreateTable(table)
        actual = compiler.process(create_table)
        expected = (
            u"\nCREATE TABLE t1 ("
            u"\n\tid INTEGER ENCODE LZO NOT NULL, "
            u"\n\tname VARCHAR, "
            u"\n\tPRIMARY KEY (id)\n)\n\n"
        )
        assert expected == actual, self._compare_strings(expected, actual) 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:19,代码来源:test_ddl_compiler.py

示例14: test_sqlalchemy_compilation

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_sqlalchemy_compilation():
    engine = create_engine('impala://localhost')
    metadata = MetaData(engine)
    # TODO: add other types to this table (e.g., functional.all_types)
    mytable = Table("mytable",
                    metadata,
                    Column('col1', STRING),
                    Column('col2', TINYINT),
                    Column('col3', INT),
                    Column('col4', DOUBLE),
                    impala_partition_by='HASH PARTITIONS 16',
                    impala_stored_as='KUDU',
                    impala_table_properties={
                        'kudu.table_name': 'my_kudu_table',
                        'kudu.master_addresses': 'kudu-master.example.com:7051'
                    })
    observed = str(CreateTable(mytable, bind=engine))
    expected = ('\nCREATE TABLE mytable (\n\tcol1 STRING, \n\tcol2 TINYINT, '
                '\n\tcol3 INT, \n\tcol4 DOUBLE\n)'
                '\nPARTITION BY HASH PARTITIONS 16\nSTORED AS KUDU\n'
                "TBLPROPERTIES ('kudu.table_name' = 'my_kudu_table', "
                "'kudu.master_addresses' = 'kudu-master.example.com:7051')\n\n")
    assert expected == observed 
开发者ID:cloudera,项目名称:impyla,代码行数:25,代码来源:test_sqlalchemy.py

示例15: test_default_reflection_3

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateTable [as 别名]
def test_default_reflection_3(self):
        db = testing.db
        table = """CREATE TABLE r_defaults (
            data VARCHAR(40) DEFAULT 'my_default',
            val INTEGER NOT NULL DEFAULT 0
            )"""
        try:
            exec_sql(db, table)
            m1 = MetaData(db)
            t1 = Table("r_defaults", m1, autoload=True)
            exec_sql(db, "DROP TABLE r_defaults")
            t1.create()
            m2 = MetaData(db)
            t2 = Table("r_defaults", m2, autoload=True)
            self.assert_compile(
                CreateTable(t2),
                "CREATE TABLE r_defaults (data VARCHAR(40) "
                "DEFAULT 'my_default', val INTEGER DEFAULT 0 "
                "NOT NULL)",
            )
        finally:
            exec_sql(db, "DROP TABLE r_defaults") 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_sqlite.py


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