connect database
This commit is contained in:
18
app/bot/middlewares/database.py
Normal file
18
app/bot/middlewares/database.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from typing import Any, Awaitable, Callable
|
||||
|
||||
from aiogram import BaseMiddleware
|
||||
from aiogram.types import Update
|
||||
|
||||
from app.infrastructure.database import get_session
|
||||
|
||||
|
||||
class DbSessionMiddleware(BaseMiddleware):
|
||||
async def __call__(
|
||||
self,
|
||||
handler: Callable[[Update, dict[str, Any]], Awaitable[Any]],
|
||||
event: Update,
|
||||
data: dict[str, Any],
|
||||
):
|
||||
async with get_session() as session:
|
||||
data["session"] = session
|
||||
return await handler(event, data)
|
||||
Reference in New Issue
Block a user