Table reflection doesn't work when using aiosqlite
#6192
Unanswered
ruimartinsptl
asked this question in
Usage Questions
Replies: 1 comment 1 reply
-
hey there - the example uses the Using For SQLAlchemy APIs that don't explicitly provide an awaitable interface, the run_sync approach is provided so that non-async APIs like import asyncio
import os
from sqlalchemy import MetaData
from sqlalchemy import Table
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
metadata = MetaData()
if os.path.exists("file.db"):
os.unlink("file.db")
engine = create_async_engine(
"sqlite+aiosqlite:///file.db",
echo=True,
future=True,
)
# Table Reflection (Loading existing table)
async def main(engine):
async with engine.begin() as conn:
await conn.execute(text("create table users (id integer primary key)"))
async with engine.connect() as conn:
users = await conn.run_sync(
lambda conn: Table("users", metadata, autoload_with=conn)
)
print(users.select())
asyncio.run(main(engine)) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
Table reflection doesn't work when I'm using aiosqlite, it will fail when run
Table("users", metadata, autoload_with=engine)
To Reproduce
Error
Versions.
Additional context
If I use the default DBAPI instead of
aiosqlite
, it worksHave a nice day! 🍻
JUST A NOTE AFTER I READ THE zzzeek commentary: I ran my code inside an async main, I forgot to refer that in the issue, but my code was:
Beta Was this translation helpful? Give feedback.
All reactions