Spaces:
Paused

yaz / src /apps /shared /db /__init__.py
anaselamr's picture
feat(pillars): v6.6.0 — Pillars 8-13 LIVE — THIRTEEN PILLARS COMPLETE 🏛️
8eb630b
Raw History Blame Contribute Delete
963 Bytes
"""
Shared database functionality for YAZ Care Platform apps
"""
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import sessionmaker, Session
from typing import Generator
import os
# Database URL from environment
DATABASE_URL = os.getenv('DATABASE_URL', 'sqlite:///./data/databases/yaz_care.db')
# Create engine
engine = create_engine(DATABASE_URL)
# Create session factory
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Base class for models
Base = declarative_base()
def get_db_session() -> Generator[Session, None, None]:
"""
Dependency to get database session
"""
db = SessionLocal()
try:
yield db
finally:
db.close()
def get_db():
"""
Alternative function to get database session
"""
return SessionLocal()
# Export commonly used items
__all__ = ['get_db_session', 'get_db', 'Base', 'engine', 'SessionLocal']