from sqlmodel import SQLModel, create_engine
from sqlalchemy.orm import sessionmaker
from sqlmodel.ext.asyncio.session import AsyncSession, AsyncEngine
from app.settings import Settings

settings = Settings()

engine = AsyncEngine(create_engine(settings.ASYNC_DATABASE_URI, echo=True, future=True))

async def init_db():
    async with engine.begin() as conn:
        # await conn.run_sync(SQLModel.metadata.drop_all)
        await conn.run_sync(SQLModel.metadata.create_all)


async def get_session() -> AsyncSession:
    async_session = sessionmaker(
        engine, class_=AsyncSession, expire_on_commit=False
    )
    async with async_session() as session:
        yield session

sqlalchemy.orm.sessionmaker sqlmodel.create_engine app.settings.Settings
[((198, 208), 'app.settings.Settings', 'Settings', ([], {}), '()\n', (206, 208), False, 'from app.settings import Settings\n'), ((231, 297), 'sqlmodel.create_engine', 'create_engine', (['settings.ASYNC_DATABASE_URI'], {'echo': '(True)', 'future': '(True)'}), '(settings.ASYNC_DATABASE_URI, echo=True, future=True)\n', (244, 297), False, 'from sqlmodel import SQLModel, create_engine\n'), ((539, 604), 'sqlalchemy.orm.sessionmaker', 'sessionmaker', (['engine'], {'class_': 'AsyncSession', 'expire_on_commit': '(False)'}), '(engine, class_=AsyncSession, expire_on_commit=False)\n', (551, 604), False, 'from sqlalchemy.orm import sessionmaker\n')]