Execute a query which is expected to return one row.
(
&self,
query: &str,
params: impl rusqlite::Params + Send,
f: F,
)
| 421 | |
| 422 | /// Execute a query which is expected to return one row. |
| 423 | pub async fn query_row<T, F>( |
| 424 | &self, |
| 425 | query: &str, |
| 426 | params: impl rusqlite::Params + Send, |
| 427 | f: F, |
| 428 | ) -> Result<T> |
| 429 | where |
| 430 | F: FnOnce(&rusqlite::Row) -> rusqlite::Result<T> + Send, |
| 431 | T: Send + 'static, |
| 432 | { |
| 433 | let query_only = true; |
| 434 | self.call(query_only, move |conn| { |
| 435 | let res = conn.query_row(query, params, f)?; |
| 436 | Ok(res) |
| 437 | }) |
| 438 | .await |
| 439 | } |
| 440 | |
| 441 | /// Execute the function inside a transaction assuming that it does writes. |
| 442 | /// |