MCPcopy Index your code
hub / github.com/dnote/dnote / fullSyncNote

Function fullSyncNote

pkg/cli/cmd/sync/sync.go:388–410  ·  view source on GitHub ↗
(tx *database.DB, n client.SyncFragNote)

Source from the content-addressed store, hash-verified

386}
387
388func fullSyncNote(tx *database.DB, n client.SyncFragNote) error {
389 var localNote database.Note
390 err := tx.QueryRow("SELECT body, usn, book_uuid, dirty, deleted FROM notes WHERE uuid = ?", n.UUID).
391 Scan(&localNote.Body, &localNote.USN, &localNote.BookUUID, &localNote.Dirty, &localNote.Deleted)
392 if err != nil && err != sql.ErrNoRows {
393 return errors.Wrapf(err, "getting local note %s", n.UUID)
394 }
395
396 // if note exists in the server and does not exist in the client, insert the note.
397 if err == sql.ErrNoRows {
398 note := database.NewNote(n.UUID, n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Deleted, false)
399
400 if err := note.Insert(tx); err != nil {
401 return errors.Wrapf(err, "inserting note with uuid %s", n.UUID)
402 }
403 } else if n.USN > localNote.USN {
404 if err := mergeNote(tx, n, localNote); err != nil {
405 return errors.Wrap(err, "merging local note")
406 }
407 }
408
409 return nil
410}
411
412func syncDeleteNote(tx *database.DB, noteUUID string) error {
413 var localUSN int

Callers 2

fullSyncFunction · 0.85
TestFullSyncNoteFunction · 0.85

Calls 4

InsertMethod · 0.95
NewNoteFunction · 0.92
mergeNoteFunction · 0.85
QueryRowMethod · 0.65

Tested by 1

TestFullSyncNoteFunction · 0.68