Spaces:
Sleeping
Sleeping
Download app/database.py from personalaiagents/Personal-AI: direct link, hf CLI and curl.
- Browser
- Download file 749 Bytes
-
https://huggingface.co/spaces/personalaiagents/Personal-AI/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/personalaiagents/Personal-AI/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/personalaiagents/Personal-AI/resolve/main/app/database.py
749 Bytes
| import os | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import declarative_base, sessionmaker | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| # Get the URL and fix the postgres:// scheme for SQLAlchemy | |
| SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL") | |
| if SQLALCHEMY_DATABASE_URL and SQLALCHEMY_DATABASE_URL.startswith("postgres://"): | |
| SQLALCHEMY_DATABASE_URL = SQLALCHEMY_DATABASE_URL.replace("postgres://", "postgresql://", 1) | |
| engine = create_engine(SQLALCHEMY_DATABASE_URL) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| # Dependency to get the database session for each request | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() |