0

我正在尝试做相当于

engine = create_engine('sqlite:///./test.db')
stmt = session.query(MyTable)
data = pd.read_sql(stmt, engine) 

但它因错误而失败AttributeError: 'AsyncConnection' object has no attribute 'cursor'

完成这项工作的正确方法是什么?

asyn_engine = create_async_engine('sqlite+aiosqlite:///./test.db')
stmt = select(MyTable)
data = pd.read_sql(stmt, async_engine)
4

1 回答 1

0

此代码原则上正在工作...

# Making pd.read_sql connection the first argument to make it compatible 
# with conn.run_syn()
def _read_sql(con, stmt):
    return pd.read_sql(stmt, con)


async def get_df(stmt, engine):
    async with engine.begin() as conn:
        data = await conn.run_sync(_read_sql, stmt)
    return data

asyn_engine = create_async_engine('sqlite+aiosqlite:///./test.db')
stmt = select(MyTable)

data = get_df(stmt, asyn_engine )
于 2022-01-26T09:35:20.813 回答