irandoc_ocr / src /storage /database.py
Alizmoh98's picture
deploy-app
e8e33af
raw
history blame
711 Bytes
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
from pathlib import Path
from collections.abc import AsyncGenerator
# Create data directory if it doesn't exist
DATA_DIR = Path("./data/database")
DATA_DIR.mkdir(parents=True, exist_ok=True)
DATABASE_URL = "sqlite+aiosqlite:///./data/database/ocr_results.db"
engine = create_async_engine(
DATABASE_URL,
echo=False
)
async_session_maker = async_sessionmaker(
bind=engine,
class_=AsyncSession,
expire_on_commit=False
)
async def get_session() -> AsyncGenerator[AsyncSession]:
"""Dependency to get async database session."""
async with async_session_maker() as session:
yield session