Spaces:
Sleeping
Sleeping
Download src/core/database.py from shrisdiablo/dev-yuvabe-app-api: direct link, hf CLI and curl.
- Browser
- Download file 818 Bytes
-
https://huggingface.co/spaces/shrisdiablo/dev-yuvabe-app-api/resolve/main/src/core/database.py
- Command line
-
hf download hf://spaces/shrisdiablo/dev-yuvabe-app-api/src/core/database.py
-
curl -L -o database.py https://huggingface.co/spaces/shrisdiablo/dev-yuvabe-app-api/resolve/main/src/core/database.py
818 Bytes
| from typing import AsyncGenerator | |
| from sqlmodel import SQLModel | |
| from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine | |
| from sqlmodel.ext.asyncio.session import AsyncSession | |
| from src.core.config import settings | |
| async_engine = create_async_engine( | |
| settings.ASYNC_DATABASE_URL, | |
| echo=False, | |
| future=True, | |
| pool_size=20, | |
| max_overflow=40, | |
| pool_timeout=30, | |
| connect_args={"ssl": True}, | |
| ) | |
| async_session = async_sessionmaker( | |
| async_engine, | |
| class_=AsyncSession, | |
| expire_on_commit=False, | |
| autoflush=False | |
| ) | |
| async def init_db(): | |
| async with async_engine.begin() as conn: | |
| await conn.run_sync(SQLModel.metadata.create_all) | |
| async def get_async_session() -> AsyncGenerator[AsyncSession, None]: | |
| async with async_session() as session: | |
| yield session | |