mirror of
https://github.com/bellingcat/whisperbox-transcribe.git
synced 2026-06-08 03:28:35 +03:00
30 lines
730 B
Python
30 lines
730 B
Python
from typing import Any, Generator
|
|
|
|
from sqlalchemy import create_engine, event
|
|
from sqlalchemy.orm import Session, sessionmaker
|
|
|
|
from app.shared.settings import settings
|
|
|
|
engine = create_engine(settings.DATABASE_URI, connect_args={"check_same_thread": False})
|
|
|
|
|
|
@event.listens_for(engine, "connect")
|
|
def set_sqlite_pragma(conn: Any, _: Any) -> None:
|
|
cursor = conn.cursor()
|
|
cursor.execute("PRAGMA journal_mode=WAL")
|
|
cursor.close()
|
|
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
def get_session() -> Generator[Session, None, None]:
|
|
db: Session = SessionLocal()
|
|
try:
|
|
yield db
|
|
db.commit()
|
|
except Exception:
|
|
db.rollback()
|
|
finally:
|
|
db.close()
|