24 lines
703 B
Python
24 lines
703 B
Python
from sqlmodel import SQLModel, Field, create_engine, Session
|
|
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from datetime import datetime
|
|
import datetime as dt
|
|
|
|
from app.config import settings
|
|
|
|
DATABASE_URL = settings.DATABASE_URL
|
|
|
|
engine = create_async_engine(DATABASE_URL, echo=False)
|
|
|
|
|
|
async def init_db():
|
|
async with engine.begin() as conn:
|
|
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
|