generated from coulomb/repo-seed
Extract the first reusable slice (models, schemas, routers, MCP, migrations) from state-hub with INTENT/SCOPE, agent instructions, workplan, and aligned inter_hub capability registry index.
19 lines
600 B
Python
19 lines
600 B
Python
from collections.abc import AsyncGenerator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
|
|
def make_engine(database_url: str, **kwargs: object) -> AsyncEngine:
|
|
return create_async_engine(database_url, **kwargs)
|
|
|
|
|
|
def make_session_factory(engine: AsyncEngine) -> async_sessionmaker[AsyncSession]:
|
|
return async_sessionmaker(engine, expire_on_commit=False)
|
|
|
|
|
|
async def session_from_factory(
|
|
factory: async_sessionmaker[AsyncSession],
|
|
) -> AsyncGenerator[AsyncSession, None]:
|
|
async with factory() as session:
|
|
yield session
|