fix: changed detected by scanner but no updated by render layer
This commit is contained in:
@ -22,7 +22,9 @@ func (h *NotesHandler) HandleCreate(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
h.storage.Create(note)
|
if err := h.storage.Create(note); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
log.Printf("Created or updated note '%s'\n", path)
|
log.Printf("Created or updated note '%s'\n", path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,6 +113,13 @@ func (s *SQLiteStorage) Create(n *note.Note) error {
|
|||||||
_, err := s.db.Exec(`
|
_, err := s.db.Exec(`
|
||||||
INSERT INTO notes (id, path, title, content, updated_at, size, published)
|
INSERT INTO notes (id, path, title, content, updated_at, size, published)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
|
path = excluded.path,
|
||||||
|
title = excluded.title,
|
||||||
|
content = excluded.content,
|
||||||
|
updated_at = excluded.updated_at,
|
||||||
|
size = excluded.size,
|
||||||
|
published = excluded.published
|
||||||
`,
|
`,
|
||||||
n.ID,
|
n.ID,
|
||||||
n.Path,
|
n.Path,
|
||||||
|
|||||||
@ -211,3 +211,28 @@ func TestSQLiteStorage_SearchByTag(t *testing.T) {
|
|||||||
t.Fatalf("expected tag match to be n2")
|
t.Fatalf("expected tag match to be n2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSQLiteStorage_Create_Upsert(t *testing.T) {
|
||||||
|
st := newSQLiteStorage(t)
|
||||||
|
|
||||||
|
ts := time.Date(2026, 2, 3, 12, 0, 0, 0, time.UTC)
|
||||||
|
n := sampleNote("n1", "notes/alpha.md", "Alpha", "one", ts)
|
||||||
|
if err := st.Create(n); err != nil {
|
||||||
|
t.Fatalf("create note: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
n.Content = "updated"
|
||||||
|
n.Title = "Alpha Updated"
|
||||||
|
n.UpdatedAt = ts.Add(2 * time.Hour)
|
||||||
|
if err := st.Create(n); err != nil {
|
||||||
|
t.Fatalf("upsert note: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := st.Get("n1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get note: %v", err)
|
||||||
|
}
|
||||||
|
if got.Title != "Alpha Updated" || got.Content != "updated" {
|
||||||
|
t.Fatalf("expected note to be updated, got %+v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user