Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc8b67d585 |
No files matched your search
@@ -10,7 +10,8 @@
|
||||
"Bash(python *)",
|
||||
"Bash(DATABASE_URL=\"sqlite+aiosqlite:////tmp/claude-1000/-home-iroddis-dev-armament-fitguide/41e5e14d-88fe-45e7-ba3a-be5a2cbde2cd/scratchpad/mig_test.db\" uv run alembic upgrade head)",
|
||||
"Bash(sqlite3 /tmp/claude-1000/-home-iroddis-dev-armament-fitguide/41e5e14d-88fe-45e7-ba3a-be5a2cbde2cd/scratchpad/mig_test.db '.schema users')",
|
||||
"Bash(docker build *)"
|
||||
"Bash(docker build *)",
|
||||
"Bash(git status *)"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ venv/
|
||||
|
||||
# Databases
|
||||
*.db
|
||||
*.db-shm
|
||||
*.db-wal
|
||||
*.sqlite3
|
||||
|
||||
# Test / tooling
|
||||
|
||||
@@ -5,6 +5,7 @@ Works with SQLite (aiosqlite) or Postgres (asyncpg) depending on DATABASE_URL.
|
||||
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
AsyncSession,
|
||||
async_sessionmaker,
|
||||
@@ -21,6 +22,19 @@ class Base(DeclarativeBase):
|
||||
|
||||
engine = create_async_engine(settings.database_url, echo=settings.debug, future=True)
|
||||
|
||||
if engine.sync_engine.dialect.name == "sqlite":
|
||||
|
||||
@event.listens_for(engine.sync_engine, "connect")
|
||||
def _set_sqlite_pragma(dbapi_connection, connection_record) -> None:
|
||||
"""WAL mode lets readers/writers avoid blocking each other; busy_timeout
|
||||
makes a connection wait for a lock instead of immediately raising
|
||||
"database is locked" (the pysqlite/aiosqlite default is 0ms).
|
||||
"""
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute("PRAGMA journal_mode=WAL")
|
||||
cursor.execute("PRAGMA busy_timeout=5000")
|
||||
cursor.close()
|
||||
|
||||
AsyncSessionLocal = async_sessionmaker(
|
||||
engine,
|
||||
class_=AsyncSession,
|
||||
|
||||
Reference in new issue
Block a user