Files
OSIT-AE-API-FastAPI/app/db_connection.py
2026-01-06 18:06:45 -05:00

28 lines
781 B
Python

"""
Independent database connection module to prevent circular imports.
"""
import logging
from sqlalchemy import create_engine
from app.config import settings
# Use local logger to avoid importing app.log (which might create cycles)
log = logging.getLogger(__name__)
db_uri = settings.SQLALCHEMY_DB_URI
engine = create_engine(
url = db_uri,
echo = False,
pool_use_lifo = True,
pool_pre_ping = True,
pool_recycle = settings.DB['pool_recycle'],
isolation_level = 'READ COMMITTED',
connect_args = {'connect_timeout': settings.DB['connect_timeout']}
)
log.info('DB Connection initializing...')
db = None
try:
db = engine.connect()
log.info(f'Connected to database: {db_uri}')
except Exception:
log.exception('Could not connect to database.')