Skip to main content

Notes Repository

Challenge on lesson: Checkpoint: Database-Backed Application

Implement init_notes(conn) creating notes(id INTEGER PRIMARY KEY, title TEXT NOT NULL UNIQUE, body TEXT NOT NULL) and class NotesRepository(conn) with add(title, body) -> int (translate UNIQUE violation to ValueError 'duplicate title'), search(term) -> list[dict] of notes whose title CONTAINS term (LIKE with parameter-bound pattern; survives the injection test), and delete(note_id) -> bool.

Difficulty: intermediate

Back to lesson: Checkpoint: Database-Backed Application