Deleting notes

This commit is contained in:
Micheal Wilkinson
2026-03-17 23:30:59 +00:00
parent 4fc10c8a5b
commit ade767312e

View File

@@ -156,7 +156,20 @@ func (s *SQLiteStore) GetAllNotes(ctx context.Context) ([]models.Note, error) {
}
func (s *SQLiteStore) DeleteNoteByID(ctx context.Context, id int) error {
return fmt.Errorf("not implemented")
result, err := s.write.ExecContext(ctx, `
DELETE FROM notes WHERE id = ?;
`, id)
if err != nil {
return fmt.Errorf("failed to delete note: %w", err)
}
rowsAffected, err := result.RowsAffected()
if err != nil {
return fmt.Errorf("failed to get rows affected: %w", err)
}
if rowsAffected == 0 {
return fmt.Errorf("note with ID %d not found", id)
}
return nil
}
func (s *SQLiteStore) validateSchema(ctx context.Context) error {