Spaces:
Sleeping
Sleeping
Download src/db/session.py from LS8/natural-hygiene-rag: direct link, hf CLI and curl.
- Browser
- Download file 617 Bytes
-
https://huggingface.co/spaces/LS8/natural-hygiene-rag/resolve/main/src/db/session.py
- Command line
-
hf download hf://spaces/LS8/natural-hygiene-rag/src/db/session.py
-
curl -L -o session.py https://huggingface.co/spaces/LS8/natural-hygiene-rag/resolve/main/src/db/session.py
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) | |