mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
unify logging with rich
This commit is contained in:
@@ -4,11 +4,10 @@ from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from app import config
|
||||
from app.utils import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
from app.logging import AppLogger
|
||||
|
||||
global_settings = config.get_settings()
|
||||
logger = AppLogger.__call__().get_logger()
|
||||
|
||||
engine = create_async_engine(
|
||||
global_settings.asyncpg_url,
|
||||
@@ -18,13 +17,11 @@ engine = create_async_engine(
|
||||
|
||||
# expire_on_commit=False will prevent attributes from being expired
|
||||
# after commit.
|
||||
AsyncSessionFactory = sessionmaker(
|
||||
engine, autoflush=False, expire_on_commit=False, class_=AsyncSession
|
||||
)
|
||||
AsyncSessionFactory = sessionmaker(engine, autoflush=False, expire_on_commit=False, class_=AsyncSession)
|
||||
|
||||
|
||||
# Dependency
|
||||
async def get_db() -> AsyncGenerator:
|
||||
async with AsyncSessionFactory() as session:
|
||||
logger.debug(f"ASYNC Pool: {engine.pool.status()}")
|
||||
# logger.debug(f"ASYNC Pool: {engine.pool.status()}")
|
||||
yield session
|
||||
|
||||
Reference in New Issue
Block a user