Skip to content

Commit efa09b5

Browse files
EstrellaXDclaude
andcommitted
fix: update database engine to async (fixes import error)
combine.py imports async_session_factory from engine.py but the committed version only had sync Session. Update to the async implementation needed by the passkey feature. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e4f6b8e commit efa09b5

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
from sqlmodel import Session, create_engine
1+
from sqlalchemy import event
2+
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
3+
from sqlalchemy.orm import sessionmaker
4+
from sqlalchemy.pool import StaticPool
25

36
from module.conf import DATA_PATH
47

5-
engine = create_engine(DATA_PATH)
8+
# Convert sqlite:///path to sqlite+aiosqlite:///path for async support
9+
ASYNC_DATA_PATH = DATA_PATH.replace("sqlite:///", "sqlite+aiosqlite:///")
610

7-
db_session = Session(engine)
11+
engine = create_async_engine(
12+
ASYNC_DATA_PATH,
13+
echo=False,
14+
poolclass=StaticPool,
15+
connect_args={"check_same_thread": False},
16+
)
17+
18+
19+
@event.listens_for(engine.sync_engine, "connect")
20+
def _set_sqlite_pragma(dbapi_connection, connection_record):
21+
cursor = dbapi_connection.cursor()
22+
cursor.execute("PRAGMA journal_mode=WAL")
23+
cursor.execute("PRAGMA synchronous=NORMAL")
24+
cursor.execute("PRAGMA cache_size=-64000") # 64MB
25+
cursor.execute("PRAGMA busy_timeout=5000")
26+
cursor.execute("PRAGMA foreign_keys=ON")
27+
cursor.close()
28+
29+
30+
async_session_factory = sessionmaker(
31+
engine, class_=AsyncSession, expire_on_commit=False
32+
)

0 commit comments

Comments
 (0)