Spaces:
Runtime error
Runtime error
Download src/core/database.py from abdullah9873/backend-rag-chatbot-v3: direct link, hf CLI and curl.
- Browser
- Download file 681 Bytes
-
https://huggingface.co/spaces/abdullah9873/backend-rag-chatbot-v3/resolve/main/src/core/database.py
- Command line
-
hf download hf://spaces/abdullah9873/backend-rag-chatbot-v3/src/core/database.py
-
curl -L -o database.py https://huggingface.co/spaces/abdullah9873/backend-rag-chatbot-v3/resolve/main/src/core/database.py
681 Bytes
| from sqlmodel import SQLModel, create_engine, Session | |
| from typing import Generator | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| DATABASE_URL = os.getenv("DATABASE_URL") | |
| if not DATABASE_URL: | |
| raise ValueError("DATABASE_URL environment variable is not set") | |
| # Neon/Postgres requires postgresql:// but some libs output postgres:// | |
| if DATABASE_URL.startswith("postgres://"): | |
| DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://", 1) | |
| engine = create_engine(DATABASE_URL, echo=True) | |
| def get_session() -> Generator[Session, None, None]: | |
| with Session(engine) as session: | |
| yield session | |
| def init_db(): | |
| SQLModel.metadata.create_all(engine) |