Spaces:
Sleeping
Sleeping
Download backend/src/config/database.py from Wenluo/Humainoid-robotics: direct link, hf CLI and curl.
- Browser
- Download file 646 Bytes
-
https://huggingface.co/spaces/Wenluo/Humainoid-robotics/resolve/main/backend/src/config/database.py
- Command line
-
hf download hf://spaces/Wenluo/Humainoid-robotics/backend/src/config/database.py
-
curl -L -o database.py https://huggingface.co/spaces/Wenluo/Humainoid-robotics/resolve/main/backend/src/config/database.py
646 Bytes
| """Database configuration for Neon Postgres.""" | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| from .settings import settings | |
| # Create SQLAlchemy engine | |
| engine = create_engine( | |
| settings.DATABASE_URL, | |
| pool_pre_ping=True, | |
| echo=settings.DEBUG, | |
| ) | |
| # Create SessionLocal class | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| # Create Base class for models | |
| Base = declarative_base() | |
| def get_db(): | |
| """Get database session dependency.""" | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |