Download backend/app/database.py from modventures/character-studio: direct link, hf CLI and curl.
- Browser
- Download file 794 Bytes
-
https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/database.py
- Command line
-
hf download hf://spaces/modventures/character-studio/backend/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/database.py
794 Bytes
| from collections.abc import Generator | |
| from functools import lru_cache | |
| from pathlib import Path | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.engine import Engine, make_url | |
| from sqlalchemy.orm import DeclarativeBase, Session | |
| from app.config import settings | |
| class Base(DeclarativeBase): | |
| pass | |
| def get_engine() -> Engine: | |
| url = make_url(settings.database_url) | |
| options = {} | |
| if url.get_backend_name() == "sqlite": | |
| options["check_same_thread"] = False | |
| if url.database and url.database != ":memory:": | |
| Path(url.database).parent.mkdir(parents=True, exist_ok=True) | |
| return create_engine(url, connect_args=options) | |
| def get_session() -> Generator[Session, None, None]: | |
| with Session(get_engine()) as session: | |
| yield session | |