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

Function getNotesBaseQuery

pkg/server/app/notes.go:201–224  ·  view source on GitHub ↗
(db *gorm.DB, userID int, q GetNotesParams)

Source from the content-addressed store, hash-verified

199}
200
201func getNotesBaseQuery(db *gorm.DB, userID int, q GetNotesParams) *gorm.DB {
202 conn := db.Where(
203 "notes.user_id = ? AND notes.deleted = ?",
204 userID, false,
205 )
206
207 if q.Search != "" {
208 conn = selectFTSFields(conn, nil)
209 conn = conn.Joins("INNER JOIN notes_fts ON notes_fts.rowid = notes.id")
210 conn = conn.Where("notes_fts MATCH ?", q.Search)
211 }
212
213 if len(q.Books) > 0 {
214 conn = conn.Joins("INNER JOIN books ON books.uuid = notes.book_uuid").
215 Where("books.label in (?)", q.Books)
216 }
217
218 if q.Year != 0 || q.Month != 0 {
219 dateLowerbound, dateUpperbound := getDateBounds(q.Year, q.Month)
220 conn = conn.Where("notes.added_on >= ? AND notes.added_on < ?", dateLowerbound, dateUpperbound)
221 }
222
223 return conn
224}
225
226func getDateBounds(year, month int) (int64, int64) {
227 var yearUpperbound, monthUpperbound int

Callers 1

GetNotesMethod · 0.85

Calls 2

selectFTSFieldsFunction · 0.85
getDateBoundsFunction · 0.85

Tested by

no test coverage detected