MCPcopy
hub / github.com/dnote/dnote / listNotes

Function listNotes

pkg/cli/cmd/view/book.go:107–149  ·  view source on GitHub ↗
(ctx context.DnoteCtx, w io.Writer, bookName string)

Source from the content-addressed store, hash-verified

105}
106
107func listNotes(ctx context.DnoteCtx, w io.Writer, bookName string) error {
108 db := ctx.DB
109
110 var bookUUID string
111 err := db.QueryRow("SELECT uuid FROM books WHERE label = ?", bookName).Scan(&bookUUID)
112 if err == sql.ErrNoRows {
113 return errors.New("book not found")
114 } else if err != nil {
115 return errors.Wrap(err, "querying the book")
116 }
117
118 rows, err := db.Query(`SELECT rowid, body FROM notes WHERE book_uuid = ? AND deleted = ? ORDER BY added_on ASC;`, bookUUID, false)
119 if err != nil {
120 return errors.Wrap(err, "querying notes")
121 }
122 defer rows.Close()
123
124 infos := []noteInfo{}
125 for rows.Next() {
126 var info noteInfo
127 err = rows.Scan(&info.RowID, &info.Body)
128 if err != nil {
129 return errors.Wrap(err, "scanning a row")
130 }
131
132 infos = append(infos, info)
133 }
134
135 fmt.Fprintf(w, "on book %s\n", bookName)
136
137 for _, info := range infos {
138 body, isExcerpt := formatBody(info.Body)
139
140 rowid := log.ColorYellow.Sprintf("(%d)", info.RowID)
141 if isExcerpt {
142 body = fmt.Sprintf("%s %s", body, log.ColorYellow.Sprintf("[---More---]"))
143 }
144
145 fmt.Fprintf(w, "%s %s\n", rowid, body)
146 }
147
148 return nil
149}

Callers 2

TestListNotesFunction · 0.85
newRunFunction · 0.85

Calls 5

formatBodyFunction · 0.85
NewMethod · 0.80
QueryRowMethod · 0.65
QueryMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestListNotesFunction · 0.68