MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / with_auto_commit

Method with_auto_commit

crates/engine/src/relational_db.rs:927–935  ·  view source on GitHub ↗

Run a fallible function in a transaction. If the supplied function returns `Ok`, the transaction is automatically committed. Otherwise, the transaction is rolled back. This method is provided for convenience, as it allows to safely use the `?` operator in code running within a transaction context. Recall that a [`MutTx`] does not follow the RAII pattern, so the following code is wrong: ```ignor

(&self, workload: Workload, f: F)

Source from the content-addressed store, hash-verified

925 /// })?;
926 /// ```
927 pub fn with_auto_commit<F, A, E>(&self, workload: Workload, f: F) -> Result<A, E>
928 where
929 F: FnOnce(&mut MutTx) -> Result<A, E>,
930 E: From<DBError>,
931 {
932 let mut tx = self.begin_mut_tx(IsolationLevel::Serializable, workload);
933 let res = f(&mut tx);
934 self.finish_tx(tx, res)
935 }
936
937 /// Run a fallible function in a transaction, rolling it back if the
938 /// function returns `Err`.

Callers 15

clear_tableMethod · 0.80
try_initMethod · 0.80
run_view_cleanupFunction · 0.80
clear_all_clientsMethod · 0.80
open_dbMethod · 0.80
with_auto_commitFunction · 0.80
create_view_for_testFunction · 0.80
evalFunction · 0.80

Calls 2

finish_txMethod · 0.80
begin_mut_txMethod · 0.45

Tested by 1

create_snapshotFunction · 0.64