mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-11 22:30:41 +03:00
* update chat_microservice * reformat logger_conf * add database * add service and repository logic * fix constants gpt base url * add models endpoints
21 lines
500 B
Python
21 lines
500 B
Python
from typing import AsyncGenerator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from starlette.requests import Request
|
|
|
|
|
|
async def get_db_session(request: Request) -> AsyncGenerator[AsyncSession, None]:
|
|
"""
|
|
Create and get database session.
|
|
|
|
:param request: current request.
|
|
:yield: database session.
|
|
"""
|
|
session: AsyncSession = request.app.state.db_session_factory()
|
|
|
|
try:
|
|
yield session
|
|
finally:
|
|
await session.commit()
|
|
await session.close()
|