示例#1
0
文件: db.py 项目: achien/transit-time
def _init():
    global _initted
    if _initted:
        return
    _initted = True

    global _metadata
    global _tables
    _metadata = sa.MetaData()
    _tables = init_tables(_metadata)
示例#2
0
 def __init__(self, engine, pool):
     self.indexes = []
     self.engine = engine
     self.pool = pool
     self.metadata = sa.MetaData(engine)
     self.inspector = reflection.Inspector.from_engine(engine)
     self.tables = {}
     self.aux_tables = {}
     self.files_tables = {}
     self._resources_by_path = {}
     self.schema = {}
示例#3
0
def test_5():

    metadata = sa.MetaData()

    tbl = sa.Table('sensor_values_t', metadata,
                   sa.Column('id', sa.BigInteger, primary_key=True),
                   sa.Column('key', sa.String(50)))

    async def go():
        async with aiopg.sa.create_engine(dsn) as engine:
            async with engine.acquire() as conn:
                await conn.execute("TRUNCATE TABLE foglamp.sensor_values_t;")

                for idx in range(0, ROWS_COUNT):
                    await conn.execute(
                        tbl.insert().values(key=id_generator(10)))

    loop = asyncio.get_event_loop()
    loop.run_until_complete(go())
示例#4
0
def metadata() -> sa.MetaData:
    result = sa.MetaData()

    sa.Table(
        'AccountRolesLog', result,
        sa.Column('id',
                  sa.Integer,
                  index=True,
                  nullable=False,
                  primary_key=True),
        sa.Column('created_at',
                  sa.DateTime,
                  server_default=sa_functions.now(),
                  index=True,
                  nullable=False),
        sa.Column('created_by', sa.Unicode, index=True, nullable=False),
        sa.Column('request_info', sa.UnicodeText, nullable=None),
        sa.Column('account_id', sa.String, index=True, nullable=False),
        sa.Column('action', sa.String(1), index=True, nullable=False),
        sa.Column('role_ids', postgresql.ARRAY(sa.String(32)), nullable=False),
        sa.Index('idx_arl_role_ids', 'role_ids', postgresql_using='gin'))

    sa.Table(
        'AccountRoles', result,
        sa.Column('account_id',
                  sa.String,
                  index=True,
                  nullable=False,
                  primary_key=True),
        sa.Column('role_ids', postgresql.ARRAY(sa.String(32)), nullable=False),
        sa.Column('log_id',
                  sa.Integer,
                  sa.ForeignKey('AccountRolesLog.id'),
                  index=True,
                  nullable=False,
                  unique=True),
        sa.Index('idx_ar_role_ids', 'role_ids', postgresql_using='gin'))

    return result
示例#5
0
async def get_db(dsn: str, **engine_kwargs) -> aiopg.sa.Engine:
    engine = sa.create_engine(dsn)
    meta = sa.MetaData()
    order_table = sa.Table('orders', meta, autoload=True, autoload_with=engine)
    trade_history_table = sa.Table('trade_history',
                                   meta,
                                   autoload=True,
                                   autoload_with=engine)
    order_pairs = sa.Table('order_pairs',
                           meta,
                           autoload=True,
                           autoload_with=engine)
    engine.dispose()

    async_engine = await aiopg.sa.create_engine(dsn=dsn, **engine_kwargs)

    async_engine.meta = meta
    async_engine.tables = {
        'orders': order_table,
        'trade_history': trade_history_table,
        'order_pairs': order_pairs,
    }

    return async_engine
示例#6
0
def test_2():

    metadata = sa.MetaData()

    tbl = sa.Table('sensor_values_t', metadata,
                   sa.Column('id', sa.BigInteger, primary_key=True),
                   sa.Column('key', sa.String(50)))

    async def go():
        async with aiopg.sa.create_engine(dsn) as engine:
            async with engine.acquire() as conn:
                await conn.execute(tbl.insert().values(key=id_generator(10)))

                # !F!
                print("DBG 1")
                #async for row in conn.execute(tbl.select().where(tbl.c.key=='9f2acad687df4ae7b7faeef8affdd0a9') ):
                async for row in conn.execute(
                    tbl.select().where(tbl.c.key == '6b110c8ca02')):
                    print(row.id, row.key)

                print("DBG 2")

    loop = asyncio.get_event_loop()
    loop.run_until_complete(go())
示例#7
0
文件: db.py 项目: stkrizh/colorific
import aiopg.sa
import sqlalchemy as sa
from aiohttp.web import Application

from .settings import config

METADATA = sa.MetaData()

image = sa.Table(
    "image",
    METADATA,
    sa.Column("id", sa.Integer(), primary_key=True),
    sa.Column("origin", sa.String(), nullable=False, unique=True),
    sa.Column("url_big", sa.String(), nullable=False),
    sa.Column("url_thumb", sa.String(), nullable=False),
    sa.Column(
        "indexed_at",
        sa.DateTime(),
        nullable=False,
        server_default=sa.text("(now() at time zone 'utc')"),
    ),
)

image_color = sa.Table(
    "image_color",
    METADATA,
    sa.Column("id", sa.Integer(), primary_key=True),
    sa.Column("image_id",
              sa.Integer(),
              sa.ForeignKey("image.id"),
              nullable=False),
示例#8
0
import aiopg.sa
import sqlalchemy as sa

from sanic_study.main import app

meta = sa.MetaData()

question = sa.Table(
    'question', meta,
    sa.Column('id', sa.Integer, nullable=False),
    sa.Column('question_text', sa.String(200), nullable=False),
    sa.Column('pub_date', sa.Date, nullable=False),

    sa.PrimaryKeyConstraint('id', name='question_id_pkey')
)


choice = sa.Table(
    'choice', meta,
    sa.Column('id', sa.Integer, nullable=False),
    sa.Column('question_id', sa.Integer, nullable=False),
    sa.Column('choice_text', sa.String(200), nullable=False),
    sa.Column('votes', sa.Integer, server_default="0", nullable=False),

    sa.PrimaryKeyConstraint('id', name='choice_id_pkey'),
    sa.ForeignKeyConstraint(['question_id'], [question.c.id],
                            name='choice_question_id_fkey',
                            ondelete='CASCADE')
)

async def init_pg(app):
示例#9
0
文件: db.py 项目: achien/transit-time
def create_tables():
    engine = get_sa_engine()
    metadata = sa.MetaData()
    init_tables(metadata)
    metadata.create_all(engine)