(cg: &crate::tracedecay::TraceDecay, sql: &str)
| 307 | } |
| 308 | |
| 309 | async fn scalar_count(cg: &crate::tracedecay::TraceDecay, sql: &str) -> Result<u64> { |
| 310 | let mut rows = cg |
| 311 | .db() |
| 312 | .conn() |
| 313 | .query(sql, ()) |
| 314 | .await |
| 315 | .map_err(|e| TraceDecayError::Database { |
| 316 | message: format!("scalar query failed: {e}"), |
| 317 | operation: "scalar_count".to_string(), |
| 318 | })?; |
| 319 | let row = rows |
| 320 | .next() |
| 321 | .await |
| 322 | .map_err(|e| TraceDecayError::Database { |
| 323 | message: format!("scalar row read failed: {e}"), |
| 324 | operation: "scalar_count".to_string(), |
| 325 | })? |
| 326 | .ok_or_else(|| TraceDecayError::Database { |
| 327 | message: "no scalar row".to_string(), |
| 328 | operation: "scalar_count".to_string(), |
| 329 | })?; |
| 330 | let v: i64 = row.get(0).map_err(|e| TraceDecayError::Database { |
| 331 | message: format!("scalar decode failed: {e}"), |
| 332 | operation: "scalar_count".to_string(), |
| 333 | })?; |
| 334 | Ok(u64::try_from(v).unwrap_or(0)) |
| 335 | } |
| 336 | |
| 337 | // --------------------------------------------------------------------------- |
| 338 | // Helpers |
no test coverage detected