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


Python schema.DropTable方法代码示例

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


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

示例1: create_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [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: drop_all_tables

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def drop_all_tables(engine, inspector, schema=None, include_names=None):
    from sqlalchemy import Column, Table, Integer, MetaData, \
        ForeignKeyConstraint
    from sqlalchemy.schema import DropTable, DropConstraint

    if include_names is not None:
        include_names = set(include_names)

    with engine.connect() as conn:
        for tname, fkcs in reversed(
                inspector.get_sorted_table_and_fkc_names(schema=schema)):
            if tname:
                if include_names is not None and tname not in include_names:
                    continue
                conn.execute(DropTable(
                    Table(tname, MetaData(), schema=schema)
                ))
            elif fkcs:
                if not engine.dialect.supports_alter:
                    continue
                for tname, fkc in fkcs:
                    if include_names is not None and \
                            tname not in include_names:
                        continue
                    tb = Table(
                        tname, MetaData(),
                        Column('x', Integer),
                        Column('y', Integer),
                        schema=schema
                    )
                    conn.execute(DropConstraint(
                        ForeignKeyConstraint(
                            [tb.c.x], [tb.c.y], name=fkc)
                    )) 
开发者ID:jpush,项目名称:jbox,代码行数:36,代码来源:util.py

示例3: drop_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def drop_table(self, table):
        self._exec(schema.DropTable(table)) 
开发者ID:jpush,项目名称:jbox,代码行数:4,代码来源:impl.py

示例4: delete_tables

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def delete_tables(pg, tables):
    async with pg.acquire() as conn:
        for table in reversed(tables):
            drop_expr = DropTable(table)
            try:
                await conn.execute(drop_expr)
            except psycopg2.ProgrammingError:
                pass 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:10,代码来源:generate_data.py

示例5: preapre_tables

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def preapre_tables(pg):
    tables = [db.question, db.choice]
    async with pg.acquire() as conn:
        for table in reversed(tables):
            drop_expr = DropTable(table)
            try:
                await conn.execute(drop_expr)
            except psycopg2.ProgrammingError:
                pass

    async with pg.acquire() as conn:
        for table in tables:
            create_expr = CreateTable(table)
            await conn.execute(create_expr) 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:16,代码来源:generate_data.py

示例6: drop_all_objects

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def drop_all_objects(self, engine):
        """Drop all database objects.

        Drops all database objects remaining on the default schema of the
        given engine.

        Per-db implementations will also need to drop items specific to those
        systems, such as sequences, custom types (e.g. pg ENUM), etc.

        """

        with engine.begin() as conn:
            inspector = sqlalchemy.inspect(engine)
            metadata = schema.MetaData()
            tbs = []
            all_fks = []

            for table_name in inspector.get_table_names():
                fks = []
                for fk in inspector.get_foreign_keys(table_name):
                    # note that SQLite reflection does not have names
                    # for foreign keys until SQLAlchemy 1.0
                    if not fk['name']:
                        continue
                    fks.append(
                        schema.ForeignKeyConstraint((), (), name=fk['name'])
                        )
                table = schema.Table(table_name, metadata, *fks)
                tbs.append(table)
                all_fks.extend(fks)

            if self.supports_drop_fk:
                for fkc in all_fks:
                    conn.execute(schema.DropConstraint(fkc))

            for table in tbs:
                conn.execute(schema.DropTable(table))

            self.drop_additional_objects(conn) 
开发者ID:openstack,项目名称:oslo.db,代码行数:41,代码来源:provision.py

示例7: connect

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def connect(make_engine):
    async def go(**kwargs):
        engine = await make_engine(**kwargs)
        with (await engine) as conn:
            try:
                await conn.execute(DropTable(tbl))
            except psycopg2.ProgrammingError:
                pass
            try:
                await conn.execute(DropTable(tbl2))
            except psycopg2.ProgrammingError:
                pass
            await conn.execute("DROP TYPE IF EXISTS simple_enum CASCADE;")
            await conn.execute("""CREATE TYPE simple_enum AS ENUM
                                       ('first', 'second');""")
            try:
                await conn.execute(CreateTable(tbl))
                ret_tbl = tbl
                has_hstore = True
            except psycopg2.ProgrammingError:
                await conn.execute(CreateTable(tbl2))
                ret_tbl = tbl2
                has_hstore = False
        return engine, ret_tbl, has_hstore

    yield go 
开发者ID:aio-libs,项目名称:aiopg,代码行数:28,代码来源:test_sa_types.py

示例8: test_create_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def test_create_table(connect):
    conn = await connect()
    res = await conn.execute(DropTable(tbl))
    with pytest.raises(sa.ResourceClosedError):
        await res.fetchmany()

    with pytest.raises(psycopg2.ProgrammingError):
        await conn.execute("SELECT * FROM sa_tbl")

    res = await conn.execute(CreateTable(tbl))
    with pytest.raises(sa.ResourceClosedError):
        await res.fetchmany()

    res = await conn.execute("SELECT * FROM sa_tbl")
    assert 0 == len(await res.fetchall()) 
开发者ID:aio-libs,项目名称:aiopg,代码行数:17,代码来源:test_sa_connection.py

示例9: _assert_drop_tables

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def _assert_drop_tables(self, elements, generator, argument):
        self._assert_ddl(schema.DropTable, elements, generator, argument) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:4,代码来源:test_ddlemit.py

示例10: _assert_drop

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def _assert_drop(self, elements, generator, argument):
        self._assert_ddl(
            (schema.DropTable, schema.DropSequence),
            elements,
            generator,
            argument,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:9,代码来源:test_ddlemit.py

示例11: _assert_drop_w_alter

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def _assert_drop_w_alter(self, elements, generator, argument):
        self._assert_ddl(
            (schema.DropTable, schema.DropSequence, schema.DropConstraint),
            elements,
            generator,
            argument,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:9,代码来源:test_ddlemit.py

示例12: _prep_testing_database

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def _prep_testing_database(options, file_config):
    from sqlalchemy.testing import config
    from sqlalchemy import schema, inspect

    if options.dropfirst:
        for cfg in config.Config.all_configs():
            e = cfg.db
            inspector = inspect(e)
            try:
                view_names = inspector.get_view_names()
            except NotImplementedError:
                pass
            else:
                for vname in view_names:
                    e.execute(schema._DropView(schema.Table(vname, schema.MetaData())))

            if config.requirements.schemas.enabled_for_config(cfg):
                try:
                    view_names = inspector.get_view_names(schema="test_schema")
                except NotImplementedError:
                    pass
                else:
                    for vname in view_names:
                        e.execute(schema._DropView(
                                    schema.Table(vname,
                                                schema.MetaData(), schema="test_schema")))

            for tname in reversed(inspector.get_table_names(order_by="foreign_key")):
                e.execute(schema.DropTable(schema.Table(tname, schema.MetaData())))

            if config.requirements.schemas.enabled_for_config(cfg):
                for tname in reversed(inspector.get_table_names(
                                        order_by="foreign_key", schema="test_schema")):
                    e.execute(schema.DropTable(
                        schema.Table(tname, schema.MetaData(), schema="test_schema"))) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:37,代码来源:plugin_base.py

示例13: test_raw_insert_with_executemany

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def test_raw_insert_with_executemany(sa_connect):
    conn = await sa_connect()
    # with pytest.raises(sa.ArgumentError):
    await conn.execute(
        "INSERT INTO sa_tbl (id, name) VALUES (%(id)s, %(name)s)",
        [{"id": 2, "name": 'third'}, {"id": 3, "name": 'forth'}])
    await conn.execute(
        tbl.update().where(
            tbl.c.id == bindparam("id")
        ).values(
            {"name": bindparam("name")}
        ),
        [
            {"id": 2, "name": "t2"},
            {"id": 3, "name": "t3"}
        ]
    )
    with pytest.raises(sa.ArgumentError):
        await conn.execute(
            DropTable(tbl),
            [{}, {}]
        )
    with pytest.raises(sa.ArgumentError):
        await conn.execute(
            {},
            [{}, {}]
        ) 
开发者ID:aio-libs,项目名称:aiomysql,代码行数:29,代码来源:test_sa_connection.py

示例14: test_create_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def test_create_table(sa_connect):
    conn = await sa_connect()
    res = await conn.execute(DropTable(tbl))
    with pytest.raises(sa.ResourceClosedError):
        await res.fetchmany()

    with pytest.raises(aiomysql.ProgrammingError):
        await conn.execute("SELECT * FROM sa_tbl")

    res = await conn.execute(CreateTable(tbl))
    with pytest.raises(sa.ResourceClosedError):
        await res.fetchmany()

    res = await conn.execute("SELECT * FROM sa_tbl")
    assert 0 == len(await res.fetchall()) 
开发者ID:aio-libs,项目名称:aiomysql,代码行数:17,代码来源:test_sa_connection.py

示例15: _prep_testing_database

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DropTable [as 别名]
def _prep_testing_database(options, file_config):
    from alembic.testing import config
    from alembic.testing.exclusions import against
    from sqlalchemy import schema
    from alembic import util

    if util.sqla_08:
        from sqlalchemy import inspect
    else:
        from sqlalchemy.engine.reflection import Inspector
        inspect = Inspector.from_engine

    if options.dropfirst:
        for cfg in config.Config.all_configs():
            e = cfg.db
            inspector = inspect(e)
            try:
                view_names = inspector.get_view_names()
            except NotImplementedError:
                pass
            else:
                for vname in view_names:
                    e.execute(schema._DropView(
                        schema.Table(vname, schema.MetaData())
                    ))

            if config.requirements.schemas.enabled_for_config(cfg):
                try:
                    view_names = inspector.get_view_names(
                        schema="test_schema")
                except NotImplementedError:
                    pass
                else:
                    for vname in view_names:
                        e.execute(schema._DropView(
                            schema.Table(vname, schema.MetaData(),
                                         schema="test_schema")
                        ))

            for tname in reversed(inspector.get_table_names(
                    order_by="foreign_key")):
                e.execute(schema.DropTable(
                    schema.Table(tname, schema.MetaData())
                ))

            if config.requirements.schemas.enabled_for_config(cfg):
                for tname in reversed(inspector.get_table_names(
                        order_by="foreign_key", schema="test_schema")):
                    e.execute(schema.DropTable(
                        schema.Table(tname, schema.MetaData(),
                                     schema="test_schema")
                    ))

            if against(cfg, "postgresql") and util.sqla_100:
                from sqlalchemy.dialects import postgresql
                for enum in inspector.get_enums("*"):
                    e.execute(postgresql.DropEnumType(
                        postgresql.ENUM(
                            name=enum['name'],
                            schema=enum['schema']))) 
开发者ID:jpush,项目名称:jbox,代码行数:62,代码来源:plugin_base.py


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