當前位置: 首頁>>代碼示例>>Python>>正文


Python ddl.CreateTable方法代碼示例

本文整理匯總了Python中sqlalchemy.sql.ddl.CreateTable方法的典型用法代碼示例。如果您正苦於以下問題:Python ddl.CreateTable方法的具體用法?Python ddl.CreateTable怎麽用?Python ddl.CreateTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.sql.ddl的用法示例。


在下文中一共展示了ddl.CreateTable方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_db

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def setup_db(db_dsn, *, loop):
    async with aiopg.sa.create_engine(db_dsn, loop=loop) as db_engine:
        async with db_engine.acquire() as conn:
            await conn.execute(CreateTable(character_table))
            await conn.execute(CreateTable(actor_table))

            await conn.execute(character_table.insert().values([
                dict(id=1, name='James T. Kirk', species='Human'),
                dict(id=2, name='Spock', species='Vulcan/Human'),
                dict(id=3, name='Leonard McCoy', species='Human'),
            ]))
            await conn.execute(actor_table.insert().values([
                dict(id=1, character_id=1, name='William Shatner'),
                dict(id=2, character_id=2, name='Leonard Nimoy'),
                dict(id=3, character_id=3, name='DeForest Kelley'),
                dict(id=4, character_id=1, name='Chris Pine'),
                dict(id=5, character_id=2, name='Zachary Quinto'),
                dict(id=6, character_id=3, name='Karl Urban'),
            ])) 
開發者ID:vmagamedov,項目名稱:hiku,代碼行數:21,代碼來源:test_asyncio.py

示例2: startDatabase

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def startDatabase(self):
        self.engine = create_engine(

            # sqlite in-memory
            #"sqlite://", reactor=reactor, strategy=TWISTED_STRATEGY

            # sqlite on filesystem
            "sqlite:////tmp/kotori.sqlite", reactor=reactor, strategy=TWISTED_STRATEGY

            # mysql... todo
        )

        # Create the table
        yield self.engine.execute(CreateTable(self.telemetry))
        #yield self.engine 
開發者ID:daq-tools,項目名稱:kotori,代碼行數:17,代碼來源:sql.py

示例3: _create_schema

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def _create_schema(self):
        await self._drop_schema_only()
        async with self.pool.acquire() as conn:
            await conn.execute(f"CREATE SCHEMA IF NOT EXISTS {self.schema}")
            for table in self._used_tables:
                await conn.execute(CreateTable(table)) 
開發者ID:b2wdigital,項目名稱:asgard-api,代碼行數:8,代碼來源:util.py

示例4: make_create_ddl

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def make_create_ddl(self, metadata: MetaData) -> DdlString:
        if not self.dialect:
            raise ValueError("Dialect must be specified to use default metadata creation function")

        ddl = []
        if metadata.schema:
            schema_ddl = str(CreateSchema(metadata.schema).compile(dialect=self.dialect))
            ddl.append(schema_ddl)
        for table_obj in metadata.tables.values():
            table_ddl = str(CreateTable(table_obj).compile(dialect=self.dialect))
            ddl.append(table_ddl)
        return ";\n".join(d for d in ddl) + ";\n" 
開發者ID:droher,項目名稱:boxball,代碼行數:14,代碼來源:target_ddl_factory.py

示例5: create_table

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def create_table(conn):
    await conn.execute('DROP TABLE IF EXISTS tbl')
    await conn.execute('DROP TYPE IF EXISTS s_enum CASCADE')
    await conn.execute("CREATE TYPE s_enum AS ENUM ('f', 's')")
    await conn.execute(CreateTable(tbl)) 
開發者ID:aio-libs,項目名稱:aiopg,代碼行數:7,代碼來源:types_field_sa.py

示例6: create_sa_transaction_tables

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def create_sa_transaction_tables(conn):
    await conn.execute(CreateTable(users)) 
開發者ID:aio-libs,項目名稱:aiopg,代碼行數:4,代碼來源:isolation_sa_transaction.py

示例7: create_table

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def create_table(conn):
    await conn.execute('DROP TABLE IF EXISTS tbl')
    await conn.execute(CreateTable(tbl)) 
開發者ID:aio-libs,項目名稱:aiopg,代碼行數:5,代碼來源:default_field_sa.py

示例8: engine

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def engine(make_engine, loop):
    async def start():
        engine = await make_engine()
        with (await engine) as conn:
            await conn.execute('DROP TABLE IF EXISTS sa_tbl4')
            await conn.execute('DROP SEQUENCE IF EXISTS id_sequence_seq')
            await conn.execute(CreateTable(tbl))
            await conn.execute('CREATE SEQUENCE id_sequence_seq')

        return engine

    return loop.run_until_complete(start()) 
開發者ID:aio-libs,項目名稱:aiopg,代碼行數:14,代碼來源:test_sa_default.py

示例9: test_compile_create_table_ddl

# 需要導入模塊: from sqlalchemy.sql import ddl [as 別名]
# 或者: from sqlalchemy.sql.ddl import CreateTable [as 別名]
def test_compile_create_table_ddl():
    create_statement = CreateTable(ddl_test_table)
    result, params = connection.compile_query(create_statement)
    assert result == (
        '\nCREATE TABLE ddl_test_table (\n\tint_col'
        ' INTEGER, \n\tstr_col VARCHAR\n)\n\n'
    )
    assert len(params) == 0 
開發者ID:CanopyTax,項目名稱:asyncpgsa,代碼行數:10,代碼來源:test_connection.py


注:本文中的sqlalchemy.sql.ddl.CreateTable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。