Spaces:
Sleeping
Sleeping
Download app/core/database.py from vithariumz/TalentaTalkBackend: direct link, hf CLI and curl.
- Browser
- Download file 759 Bytes
-
https://huggingface.co/spaces/vithariumz/TalentaTalkBackend/resolve/main/app/core/database.py
- Command line
-
hf download hf://spaces/vithariumz/TalentaTalkBackend/app/core/database.py
-
curl -L -o database.py https://huggingface.co/spaces/vithariumz/TalentaTalkBackend/resolve/main/app/core/database.py
759 Bytes
| from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker | |
| from sqlalchemy.orm import DeclarativeBase | |
| from app.core.config import settings | |
| from typing import AsyncGenerator | |
| engine = create_async_engine( | |
| settings.SQLALCHEMY_DATABASE_URI, | |
| echo=False, | |
| future=True, | |
| pool_pre_ping=True, | |
| pool_size=10, | |
| max_overflow=20 | |
| ) | |
| AsyncSessionLocal = async_sessionmaker( | |
| bind=engine, | |
| class_=AsyncSession, | |
| expire_on_commit=False, | |
| autocommit=False, | |
| autoflush=False, | |
| ) | |
| class Base(DeclarativeBase): | |
| pass | |
| async def get_db() -> AsyncGenerator[AsyncSession, None]: | |
| async with AsyncSessionLocal() as session: | |
| try: | |
| yield session | |
| finally: | |
| await session.close() |