Implement get by ID

This commit is contained in:
Micheal Wilkinson
2026-03-17 23:15:25 +00:00
parent bdc7b5b1b6
commit f86bca9323

View File

@@ -3,6 +3,7 @@ package sqlite
import ( import (
"context" "context"
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"time" "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) { 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 { func (s *SQLiteStore) validateSchema(ctx context.Context) error {