38 lines
744 B
Python
38 lines
744 B
Python
# app/core/database.py
|
|
"""Summary description ....
|
|
|
|
This module provides classes and functions for:
|
|
- ....
|
|
- ....
|
|
- ....
|
|
"""
|
|
|
|
import logging
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
|
|
from .config import settings
|
|
|
|
engine = create_engine(settings.database_url)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
Base = declarative_base()
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Database dependency with connection pooling
|
|
|
|
|
|
def get_db():
|
|
"""Get database object."""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
except Exception as e:
|
|
logger.error(f"Health check failed: {e}")
|
|
db.rollback()
|
|
raise
|
|
finally:
|
|
db.close()
|