about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoan Lledó <jlledom@member.fsf.org>2023-09-16 11:07:56 +0200
committerJoan Lledó <jlledom@member.fsf.org>2023-09-30 13:14:36 +0200
commit549803558d22b36ac6ac178722f2a8cc0548531e (patch)
tree6d21ed21e870149f30ab27682e80865393ba4487
parent28a73d4af630398cfa0818bdefa57e50f76dc4f4 (diff)
downloadFurtherance-549803558d22b36ac6ac178722f2a8cc0548531e.tar.zst
Query DB by task name
-rw-r--r--src/database.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/database.rs b/src/database.rs
index 7050cbb..6c558fe 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -343,6 +343,29 @@ pub fn get_list_by_id(id_list: Vec<i32>) -> Result<Vec<Task>, rusqlite::Error> {
     Ok(tasks_vec)
 }
 
+pub fn get_list_by_name_or_tag(task_name: String) -> Result<Vec<Task>, rusqlite::Error> {
+    let conn = Connection::open(get_directory())?;
+    let mut tasks_vec: Vec<Task> = Vec::new();
+    let name_param = format!("%{}%", task_name);
+
+    let mut query = conn.prepare("SELECT * FROM tasks WHERE lower(task_name) LIKE lower(:task_name)")?;
+    let task_iter = query.query_map(&[(":task_name", &name_param)], |row| {
+        Ok(Task {
+            id: row.get(0)?,
+            task_name: row.get(1)?,
+            start_time: row.get(2)?,
+            stop_time: row.get(3)?,
+            tags: row.get(4)?,
+        })
+    })?;
+
+    for task_item in task_iter {
+        tasks_vec.push(task_item.unwrap());
+    }
+
+    Ok(tasks_vec)
+}
+
 pub fn check_for_tasks() -> Result<String> {
     let conn = Connection::open(get_directory())?;