18 lines
562 B
Python
18 lines
562 B
Python
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from ..config import config
|
|
|
|
import logging
|
|
logger = logging.getLogger('sqlalchemy.engine')
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
async_engine = create_async_engine(config.DATABASE_URI)
|
|
async_session = sessionmaker[AsyncSession](
|
|
async_engine, class_=AsyncSession, expire_on_commit=False
|
|
)
|
|
|
|
async def get_db() -> AsyncSession: # type: ignore
|
|
async with async_session() as session:
|
|
yield session |