Week 4_b/40 — Adding Persistence with SQLite

Tech stack (this week)

  • Backend: FastAPI + Python sqlite3

  • DB: 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.

  1. Create a SQLite DB file and a table (entries).

  2. Update the backend so:

    • POST /entries runs an INSERT

    • GET /entries runs a SELECT

  3. Restart backend, reload frontend, confirm behavior stays the same.

  4. 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.

Previous
Previous

Week 5/40 — First “AI-like” Endpoint

Next
Next

Week 4/40 — First Full-Stack App (React + TS + FastAPI)