MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / with_batch_transaction

Method with_batch_transaction

src/db/tx.rs:6–35  ·  view source on GitHub ↗
(
        &self,
        operation: &str,
        work: impl std::future::Future<Output = Result<T>>,
    )

Source from the content-addressed store, hash-verified

4
5impl Database {
6 pub(super) async fn with_batch_transaction<T>(
7 &self,
8 operation: &str,
9 work: impl std::future::Future<Output = Result<T>>,
10 ) -> Result<T> {
11 self.conn()
12 .execute("BEGIN", ())
13 .await
14 .map_err(|e| TraceDecayError::Database {
15 message: format!("failed to begin: {e}"),
16 operation: operation.to_string(),
17 })?;
18
19 match work.await {
20 Ok(value) => {
21 if let Err(e) = self.conn().execute("COMMIT", ()).await {
22 let _ = self.conn().execute("ROLLBACK", ()).await;
23 return Err(TraceDecayError::Database {
24 message: format!("failed to commit: {e}"),
25 operation: operation.to_string(),
26 });
27 }
28 Ok(value)
29 }
30 Err(e) => {
31 let _ = self.conn().execute("ROLLBACK", ()).await;
32 Err(e)
33 }
34 }
35 }
36}

Callers 4

upsert_filesMethod · 0.80
insert_edgesMethod · 0.80
insert_nodesMethod · 0.80

Calls 1

connMethod · 0.45

Tested by

no test coverage detected