Week 4_b/40 — Adding Persistence with SQLite
Tech stack (this week)
Backend: FastAPI + Python
sqlite3DB: SQLite (local file)
Frontend: unchanged (still calls the same HTTP API)
New topic: persistence + “good APIs let internals evolve.”
Why this week?
As a stretch goal, I replaced in-memory storage with SQLite so data survives restarts — a small change that makes the app feel dramatically more real.
What I shipped
Same Learning Log UI, but entries now persist in SQLite.
The One Feature Rule
One feature: swap in-memory list → SQL-backed storage.
Not doing: ORM, migrations framework, multi-user support.
What I learned
If your HTTP API contract stays stable, you can change storage without breaking the client.
Follow along (code it yourself): This week’s task
Task: Replace in-memory storage with SQLite without changing the frontend.
Create a SQLite DB file and a table (
entries).Update the backend so:
POST /entriesruns anINSERTGET /entriesruns aSELECT
Restart backend, reload frontend, confirm behavior stays the same.
Create entries, restart backend again — confirm they still exist.
Success criteria: Data survives backend restarts, and frontend didn’t need changes.
Extra help & hints
Keep SQL simple: start with
id,text,created_at,is_favorite.Avoid ORMs for now—raw SQL helps you learn what’s happening.
If the DB “disappears,” verify your working directory and relative paths.