Spaces:
Runtime error
Runtime error
Download database/connection.py from elampt/Finsight-Backend: direct link, hf CLI and curl.
- Browser
- Download file 642 Bytes
-
https://huggingface.co/spaces/elampt/Finsight-Backend/resolve/main/database/connection.py
- Command line
-
hf download hf://spaces/elampt/Finsight-Backend/database/connection.py
-
curl -L -o connection.py https://huggingface.co/spaces/elampt/Finsight-Backend/resolve/main/database/connection.py
642 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from config import settings | |
| DATABASE_URL = f"postgresql://{settings.database_username}:{settings.database_password}@{settings.database_hostname}:{settings.database_port}/{settings.database_name}" | |
| engine = create_engine(DATABASE_URL) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| # This code sets up a connection to a PostgreSQL database using SQLAlchemy. |