This commit is contained in:
Redsandy
2026-03-14 18:48:57 +03:00
parent 1d1350fc13
commit 3ea4fb4771
40 changed files with 2150 additions and 0 deletions

25
app/database.py Normal file
View File

@@ -0,0 +1,25 @@
from sqlmodel import SQLModel, Session, create_engine
from app.config import DATABASE_URL
# SQLite requires check_same_thread=False for FastAPI
_connect_args: dict = {}
if DATABASE_URL.startswith("sqlite"):
_connect_args = {"check_same_thread": False}
engine = create_engine(
DATABASE_URL,
echo=True,
connect_args=_connect_args,
)
def create_db_and_tables() -> None:
"""Create all tables from SQLModel metadata.
Called once at application startup."""
SQLModel.metadata.create_all(engine)
def get_session():
"""FastAPI dependency — yields a SQLModel Session."""
with Session(engine) as session:
yield session