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

Function listBooks

pkg/cli/cmd/view/book.go:75–105  ·  view source on GitHub ↗
(ctx context.DnoteCtx, w io.Writer, nameOnly bool)

Source from the content-addressed store, hash-verified

73}
74
75func listBooks(ctx context.DnoteCtx, w io.Writer, nameOnly bool) error {
76 db := ctx.DB
77
78 rows, err := db.Query(`SELECT books.label, count(notes.uuid) note_count
79 FROM books
80 LEFT JOIN notes ON notes.book_uuid = books.uuid AND notes.deleted = false
81 WHERE books.deleted = false
82 GROUP BY books.uuid
83 ORDER BY books.label ASC;`)
84 if err != nil {
85 return errors.Wrap(err, "querying books")
86 }
87 defer rows.Close()
88
89 infos := []bookInfo{}
90 for rows.Next() {
91 var info bookInfo
92 err = rows.Scan(&info.BookLabel, &info.NoteCount)
93 if err != nil {
94 return errors.Wrap(err, "scanning a row")
95 }
96
97 infos = append(infos, info)
98 }
99
100 for _, info := range infos {
101 printBookLine(w, info, nameOnly)
102 }
103
104 return nil
105}
106
107func listNotes(ctx context.DnoteCtx, w io.Writer, bookName string) error {
108 db := ctx.DB

Callers 2

TestListBooksFunction · 0.85
newRunFunction · 0.85

Calls 3

printBookLineFunction · 0.85
QueryMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestListBooksFunction · 0.68