On the structure of Import Table of aiomysql and sqlalchemy

import asyncio
import sqlalchemy as sa

from aiomysql.sa import create_engine


@asyncio.coroutine
def go():
    engine = yield from create_engine(user="root",db="test",host="127.0.0.1",password="root")

    metadata = sa.MetaData(bind=engine)
    tbl = sa.Table("tbl", metadata
        ,sa.Column("id", sa.Integer, primary_key=True)
        ,sa.Column("val", sa.String(255))
    )
    with (yield from engine) as conn:
        res = yield from conn.execute(tbl.select())
        for row in res:
            print(row.id, row.val)

asyncio.get_event_loop().run_until_complete(go())


this is the official example given by aiomysql. What I want to ask is that for each table, the sa.Table () method is used to map the data table in the above case, and all the data columns must be listed in this mapping.
when using sqlalchemy alone (without aiomysql), you can import

in the following ways
alphaTable = Table("alpha", metadata, autoload=True)

but there will be an error after cooperating with aiomysql. Is there any way to import information columns directly through some methods without enumerating the information columns yourself?

Mar.04,2021

create an extra normal SQLAlchemy engine, and replace autoload=True with autoload_with=blocking_engine . Because table mapping should only happen once, it should be acceptable not to use asynchrony at this time.

Menu