natural-hygiene-rag / src /db /session.py
LS8's picture
Upload folder using huggingface_hub
847db01 verified
Raw History Blame Contribute Delete
617 Bytes
from collections.abc import AsyncGenerator
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from src.config import settings
engine = create_async_engine(settings.sqlite_url, echo=False)
async_session_factory = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async def get_session() -> AsyncGenerator[AsyncSession]:
async with async_session_factory() as session:
yield session
async def init_db() -> None:
from src.db.models import Base
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)