From f86bca932304d784d1b9ec521be09ec994f55243 Mon Sep 17 00:00:00 2001 From: Micheal Wilkinson Date: Tue, 17 Mar 2026 23:15:25 +0000 Subject: [PATCH] Implement get by ID --- internal/store/sqlite/sqlite.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/store/sqlite/sqlite.go b/internal/store/sqlite/sqlite.go index abf9fd0..3537f9b 100644 --- a/internal/store/sqlite/sqlite.go +++ b/internal/store/sqlite/sqlite.go @@ -3,6 +3,7 @@ package sqlite import ( "context" "database/sql" + "errors" "fmt" "time" @@ -114,7 +115,17 @@ func (s *SQLiteStore) SaveNote(ctx context.Context, note models.Note) (models.No } func (s *SQLiteStore) GetNoteByID(ctx context.Context, id int) (models.Note, error) { - return models.Note{}, fmt.Errorf("not implemented") + row := s.read.QueryRowContext(ctx, ` + SELECT id, content, last_update FROM notes WHERE id = ?; + `, id) + note, err := s.scanNote(row) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return models.Note{}, fmt.Errorf("note with ID %d not found: %w", id, err) + } + return models.Note{}, fmt.Errorf("failed to get note by ID: %w", err) + } + return note, nil } func (s *SQLiteStore) validateSchema(ctx context.Context) error {