The*_*ser 8 python sqlite sqlalchemy python-asyncio aiosqlite
当尝试使用 asyncio 扩展连接到 SQLite 引擎时,从 SQLAlchemy 版本升级1.4.0b2到 会导致以下错误。1.4.0b3
>>> from sqlalchemy.ext.asyncio import create_async_engine
>>> engine = create_async_engine('sqlite:///database.db', echo=True, future=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<...>/venv/lib/python3.9/site-packages/sqlalchemy/ext/asyncio/engine.py", line 41, in create_async_engine
return AsyncEngine(sync_engine)
File "/.../venv/lib/python3.9/site-packages/sqlalchemy/ext/asyncio/engine.py", line 531, in __init__
raise exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: The asyncio extension requires an async driver to be used. The loaded 'pysqlite' is not async.
Run Code Online (Sandbox Code Playgroud)
这是由于 SQLite 驱动程序和 asyncio 扩展之间不兼容造成的吗?但是,如果是这种情况,为什么它适用于 version 1.4.0b2?
>>> from sqlalchemy.ext.asyncio import create_async_engine
>>> engine = create_async_engine('sqlite:///database.db', echo=True, future=True)
>>> engine
<sqlalchemy.ext.asyncio.engine.AsyncEngine object at 0x7f9530101180>
Run Code Online (Sandbox Code Playgroud)
另请注意,使用asyncpgpostgres 驱动程序可以工作(url 开头postgresql+asyncpg://)。所有测试均使用 python 版本进行3.9.2。
我知道 asyncio 扩展应该被视为“alpha 级别”,因此可能会发生变化,但我想知道这是否是一个错误,或者是 SQLite 特有的问题。
Nun*_*dré 13
aiosqlite 支持,但需要在连接字符串中指定驱动程序。否则它将默认使用sqlite3(ie )。pysqlite
from sqlalchemy.ext.asyncio import create_async_engine
engine = create_async_engine('sqlite+aiosqlite:///database.db')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7763 次 |
| 最近记录: |