Implement get by ID
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user