Allocates a connection and calls `function` with the connection. If `query_only` is true, allocates read-only connection, otherwise allocates write connection. Returns the result of the function.
(&'a self, query_only: bool, function: F)
| 300 | /// |
| 301 | /// Returns the result of the function. |
| 302 | pub async fn call<'a, F, R>(&'a self, query_only: bool, function: F) -> Result<R> |
| 303 | where |
| 304 | F: 'a + FnOnce(&mut Connection) -> Result<R> + Send, |
| 305 | R: Send + 'static, |
| 306 | { |
| 307 | let lock = self.pool.read().await; |
| 308 | let pool = lock.as_ref().context("no SQL connection")?; |
| 309 | let mut conn = pool.get(query_only).await?; |
| 310 | let res = tokio::task::block_in_place(move || function(&mut conn))?; |
| 311 | Ok(res) |
| 312 | } |
| 313 | |
| 314 | /// Allocates a connection and calls given function, assuming it does write queries, with the |
| 315 | /// connection. |