Download src/backend/database.py from anas-ahmed/Agentex-Hyper-Personalized-Tutor: direct link, hf CLI and curl.
- Browser
- Download file 681 Bytes
-
https://huggingface.co/spaces/anas-ahmed/Agentex-Hyper-Personalized-Tutor/resolve/main/src/backend/database.py
- Command line
-
hf download hf://spaces/anas-ahmed/Agentex-Hyper-Personalized-Tutor/src/backend/database.py
-
curl -L -o database.py https://huggingface.co/spaces/anas-ahmed/Agentex-Hyper-Personalized-Tutor/resolve/main/src/backend/database.py
681 Bytes
| from collections.abc import AsyncGenerator | |
| from sqlalchemy.ext.asyncio import create_async_engine | |
| from sqlmodel import SQLModel | |
| from sqlmodel.ext.asyncio.session import AsyncSession | |
| from backend.config import settings | |
| engine = create_async_engine( | |
| settings.database_url, | |
| echo=settings.debug, | |
| future=True, | |
| ) | |
| async def init_db() -> None: | |
| """Create all database tables.""" | |
| async with engine.begin() as conn: | |
| await conn.run_sync(SQLModel.metadata.create_all) | |
| async def get_session() -> AsyncGenerator[AsyncSession, None]: | |
| """Dependency for getting async database sessions.""" | |
| async with AsyncSession(engine) as session: | |
| yield session | |