from starlette.requests import Request

from src.db.database import DatabaseClient, DatabaseSession


def get_database(request: Request) -> DatabaseClient:
    try:
        database_session = DatabaseSession.get_instance()
        session = database_session.create_session()
        database = DatabaseClient(session)
        yield database
    finally:
        database.disconnect()
