Python sqlalchemy.sql.ddl.CreateTable() Examples

The following are 9 code examples of sqlalchemy.sql.ddl.CreateTable(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.sql.ddl , or try the search function .
Example #1
Source File: test_asyncio.py    From hiku with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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'),
            ])) 
Example #2
Source File: sql.py    From kotori with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #3
Source File: util.py    From asgard-api with MIT License 5 votes vote down vote up
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)) 
Example #4
Source File: target_ddl_factory.py    From boxball with Apache License 2.0 5 votes vote down vote up
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" 
Example #5
Source File: types_field_sa.py    From aiopg with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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)) 
Example #6
Source File: isolation_sa_transaction.py    From aiopg with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def create_sa_transaction_tables(conn):
    await conn.execute(CreateTable(users)) 
Example #7
Source File: default_field_sa.py    From aiopg with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def create_table(conn):
    await conn.execute('DROP TABLE IF EXISTS tbl')
    await conn.execute(CreateTable(tbl)) 
Example #8
Source File: test_sa_default.py    From aiopg with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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()) 
Example #9
Source File: test_connection.py    From asyncpgsa with Apache License 2.0 5 votes vote down vote up
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