MCPcopy Create free account
hub / github.com/chatmail/core / call

Method call

src/sql.rs:302–312  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 11

importMethod · 0.80
call_writeMethod · 0.80
query_mapMethod · 0.80
query_rowMethod · 0.80
transaction_exMethod · 0.80
table_existsMethod · 0.80
col_existsMethod · 0.80
query_row_optionalMethod · 0.80
test_auto_vacuumFunction · 0.80
mainFunction · 0.80

Calls 2

as_refMethod · 0.45
getMethod · 0.45

Tested by 1

test_auto_vacuumFunction · 0.64