# backend/app/db.py
from sqlmodel import Session, SQLModel, create_engine

from .config import get_settings

settings = get_settings()
# SQLite + FastAPI: check_same_thread=False 필요
connect_args = (
    {"check_same_thread": False} if settings.database_url.startswith("sqlite") else {}
)
engine = create_engine(settings.database_url, echo=False, connect_args=connect_args)


def init_db() -> None:
    SQLModel.metadata.create_all(engine)


def get_session():
    with Session(engine) as session:
        yield session
