Download app/db/base.py from minhbe65/RAG-api: direct link, hf CLI and curl.
- Browser
- Download file 625 Bytes
-
https://huggingface.co/spaces/minhbe65/RAG-api/resolve/main/app/db/base.py
- Command line
-
hf download hf://spaces/minhbe65/RAG-api/app/db/base.py
-
curl -L -o base.py https://huggingface.co/spaces/minhbe65/RAG-api/resolve/main/app/db/base.py
625 Bytes
| """Engine + session SQLAlchemy (đồng bộ, psycopg3).""" | |
| from __future__ import annotations | |
| from collections.abc import Iterator | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker | |
| from app.config import get_settings | |
| settings = get_settings() | |
| engine = create_engine(settings.sqlalchemy_url, pool_pre_ping=True, future=True) | |
| SessionLocal = sessionmaker(bind=engine, autoflush=False, expire_on_commit=False) | |
| class Base(DeclarativeBase): | |
| pass | |
| def get_db() -> Iterator[Session]: | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |