Skip to main content

Practice ยท 1 of 3

Repository Pattern

Write makeRepo(db) โ€” db is { rows: [], nextId: 1 }. The repo exposes create(data), findById(id), update(id, patch), remove(id). create assigns id ("r<n>") and returns the row; findById returns the row or null; update returns { ok: true, row } or { ok: false, error: "not-found" }; remove returns { ok: true } or { ok: false, error: "not-found" }. The repo is the ONLY code that touches db.

Difficulty: intermediate

Back to lesson: Practice: API โ†” Database โ€” Practice