Read a single task by ID from the database, returning an error if not found.
(
conn: &Connection,
id: &str,
)
| 113 | |
| 114 | /// Read a single task by ID from the database, returning an error if not found. |
| 115 | fn read_task_by_id( |
| 116 | conn: &Connection, |
| 117 | id: &str, |
| 118 | ) -> Result<Task, Box<dyn std::error::Error + Send + Sync>> { |
| 119 | let mut stmt = conn.prepare("SELECT * FROM tasks WHERE id = ?1")?; |
| 120 | let task = stmt |
| 121 | .query_row(rusqlite::params![id], row_to_task) |
| 122 | .map_err(|e| match e { |
| 123 | rusqlite::Error::QueryReturnedNoRows => { |
| 124 | Box::<dyn std::error::Error + Send + Sync>::from("Task not found") |
| 125 | } |
| 126 | other => Box::<dyn std::error::Error + Send + Sync>::from(other), |
| 127 | })?; |
| 128 | Ok(task) |
| 129 | } |
| 130 | |
| 131 | fn insert_task( |
| 132 | conn: &Connection, |
no outgoing calls
no test coverage detected