本文整理汇总了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'),
]))
示例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
示例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))
示例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"
示例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))
示例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))
示例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))
示例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())
示例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