Lesson Complete!
From JSON to SQLite
What you built
models.py—Expense(SQLModel, table=True)with a database-assignedid, andExpenseUpdate(SQLModel)for partial updates.ExpenseOutis gone —Expensehandles input, storage, and output.database.py— the SQLite engine withcheck_same_thread=False,create_db_and_tables()to set up the schema on startup,get_session()to give each request its own database session, andSessionDepto inject that session into endpoint signatures.main.py— imports frommodelsanddatabase, alifespanfunction that creates the database on startup, andFastAPI(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.