Lesson Complete!

From JSON to SQLite

What you built

  • models.pyExpense(SQLModel, table=True) with a database-assigned id, and ExpenseUpdate(SQLModel) for partial updates. ExpenseOut is gone — Expense handles input, storage, and output.
  • database.py — the SQLite engine with check_same_thread=False, create_db_and_tables() to set up the schema on startup, get_session() to give each request its own database session, and SessionDep to inject that session into endpoint signatures.
  • main.py — imports from models and database, a lifespan function that creates the database on startup, and FastAPI(lifespan=lifespan) to register it.

What comes next

The JSON storage functions (save_expenses, load_expenses) and the old dict-based endpoint logic are still in main.py. The endpoints are wired to the database session but not using it yet.

Lesson 2 rewrites each endpoint one by one — replacing the dict and counter logic with database session calls.