Spaces:
Sleeping
Sleeping
File size: 768 Bytes
ed5cf78 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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)
|