79769317

Date: 2025-09-19 09:07:23
Score: 1
Natty:
Report link

I added the following functionality for interacting with the database:

@asynccontextmanager
async def runtime_engine(db_url: str = settings.db_url):
    engine = create_async_engine(db_url, pool_pre_ping=True)
    try:
        yield engine
    finally:
        await engine.dispose()


def make_session_factory(engine) -> async_sessionmaker[AsyncSession]:
    return async_sessionmaker(engine, expire_on_commit=False)
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: hhhscvx