(
&self,
id: &str,
)
| 337 | } |
| 338 | |
| 339 | pub async fn get_task( |
| 340 | &self, |
| 341 | id: &str, |
| 342 | ) -> Result<Option<Task>, Box<dyn std::error::Error + Send + Sync>> { |
| 343 | let conn = Arc::clone(&self.conn); |
| 344 | let id = id.to_string(); |
| 345 | tokio::task::spawn_blocking(move || { |
| 346 | let conn = conn.lock().map_err(|e| format!("Lock error: {e}"))?; |
| 347 | let mut stmt = conn.prepare("SELECT * FROM tasks WHERE id = ?1")?; |
| 348 | let mut rows = stmt.query_map(rusqlite::params![id], row_to_task)?; |
| 349 | match rows.next() { |
| 350 | Some(row) => Ok(Some(row?)), |
| 351 | None => Ok(None), |
| 352 | } |
| 353 | }) |
| 354 | .await? |
| 355 | } |
| 356 | |
| 357 | pub async fn list_tasks(&self) -> Result<Vec<Task>, Box<dyn std::error::Error + Send + Sync>> { |
| 358 | let conn = Arc::clone(&self.conn); |
no outgoing calls