summaryrefslogtreecommitdiff
path: root/internal/store/sqlite.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/store/sqlite.go')
-rw-r--r--internal/store/sqlite.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/internal/store/sqlite.go b/internal/store/sqlite.go
index fa8f2b1..c97d0af 100644
--- a/internal/store/sqlite.go
+++ b/internal/store/sqlite.go
@@ -126,7 +126,7 @@ func (s *Store) GetTasks() ([]models.Task, error) {
rows, err := s.db.Query(`
SELECT id, content, description, project_id, project_name, due_date, priority, completed, labels, url, created_at
FROM tasks
- ORDER BY completed ASC, due_date ASC, priority DESC
+ ORDER BY completed ASC, CASE WHEN due_date IS NULL THEN 1 ELSE 0 END, due_date ASC, priority DESC
`)
if err != nil {
return nil, err
@@ -248,6 +248,44 @@ func (s *Store) GetNotes(limit int) ([]models.Note, error) {
return notes, rows.Err()
}
+// SearchNotes searches notes by title or content
+func (s *Store) SearchNotes(query string) ([]models.Note, error) {
+ searchPattern := "%" + query + "%"
+ rows, err := s.db.Query(`
+ SELECT filename, title, content, modified, path, tags
+ FROM notes
+ WHERE title LIKE ? OR content LIKE ?
+ ORDER BY modified DESC
+ `, searchPattern, searchPattern)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ var notes []models.Note
+ for rows.Next() {
+ var note models.Note
+ var tagsJSON string
+
+ err := rows.Scan(
+ &note.Filename,
+ &note.Title,
+ &note.Content,
+ &note.Modified,
+ &note.Path,
+ &tagsJSON,
+ )
+ if err != nil {
+ return nil, err
+ }
+
+ json.Unmarshal([]byte(tagsJSON), &note.Tags)
+ notes = append(notes, note)
+ }
+
+ return notes, rows.Err()
+}
+
// Meals operations
// SaveMeals saves multiple meals to the database