Пример #1
0
result, error = loop.run_until_complete(pool.query(sql))
print("-- query", result, error)
result, error = loop.run_until_complete(pool.queryrow(sql))
print("-- queryrow", result, error)
table = pool.table("color")

# TODO: Implement the ORM
db = asyncORM(db=pool, loop=loop)
result = db.table(
    "color",
    loop=loop).all()  # .filter(hex='#ffffff').fields(['name', 'hex']).one()
print("-- db.table", result)


async def select():
    conn = pool._connection
    cur = await conn.cursor()
    await cur.execute(sql)
    r = await cur.fetchone()
    print(r)

    async with pool._connection as conn:
        async with conn.cursor() as cur:
            await cur.execute(sql)
            r = await cur.fetchone()
            print(r)


loop.run_until_complete(select())
pool.terminate()
Пример #2
0
        print(conn)
        result, error = await conn.test_connection()
        print(result)
        result, error = await conn.query(sql)
        if not error:
            print(result)
        # execute a sentence
        result, error = await conn.execute("SET TIMEZONE TO 'America/New_York'"
                                           )
        print(result)


loop.run_until_complete(connect(p))

# call closing provider
p.terminate()

from sqlalchemy import (Column, Integer, MetaData, Table, Text, create_engine,
                        select)
from sqlalchemy.schema import CreateTable, DropTable

## In-memory sqlite database cannot be accessed from different threads
sqlite = "sqlite:///test.db"
sa = AsyncDB("sa", loop=loop, dsn=sqlite)

metadata = MetaData()
users = Table(
    "users",
    metadata,
    Column("id", Integer, primary_key=True),
    Column("name", Text),