Saving our work just in case.
This commit is contained in:
28
app/db_connection.py
Normal file
28
app/db_connection.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
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.')
|
||||
Reference in New Issue
Block a user