Spaces:
Sleeping
Sleeping
| from sqlmodel import SQLModel, create_engine | |
| from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine | |
| from sqlalchemy.orm import sessionmaker | |
| from src.config import settings | |
| DATABASE_URL = settings.DATABASE_URL | |
| # Pass SSL mode explicitly for asyncpg | |
| engine = create_async_engine( | |
| DATABASE_URL, | |
| echo=True, | |
| future=True, | |
| connect_args={"ssl": "require"} | |
| ) | |
| async def get_session() -> AsyncSession: | |
| async_session = sessionmaker( | |
| engine, class_=AsyncSession, expire_on_commit=False | |
| ) | |
| async with async_session() as session: | |
| yield session | |
| 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) | |