MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / execute_with_auto_commit

Method execute_with_auto_commit

graphlite/src/session/transaction_state.rs:583–616  ·  view source on GitHub ↗

Execute a function with auto-commit wrapping if needed

(&self, f: F)

Source from the content-addressed store, hash-verified

581
582 /// Execute a function with auto-commit wrapping if needed
583 pub fn execute_with_auto_commit<F, R>(&self, f: F) -> Result<R, ExecutionError>
584 where
585 F: FnOnce() -> Result<R, ExecutionError>,
586 {
587 let needs_auto_commit = self.is_auto_commit()? && !self.has_active_transaction()?;
588
589 if needs_auto_commit {
590 // Start auto-commit transaction
591 let txn_id = self.begin_transaction()?;
592
593 // Execute the function
594 match f() {
595 Ok(result) => {
596 // Commit on success
597 self.commit_transaction()?;
598 Ok(result)
599 }
600 Err(e) => {
601 // Rollback on error
602 if let Err(rollback_err) = self.rollback_transaction() {
603 log::error!(
604 "Failed to rollback transaction {}: {}",
605 txn_id,
606 rollback_err
607 );
608 }
609 Err(e)
610 }
611 }
612 } else {
613 // No auto-commit needed, just execute
614 f()
615 }
616 }
617}

Callers

nothing calls this directly

Calls 5

is_auto_commitMethod · 0.80
begin_transactionMethod · 0.80
commit_transactionMethod · 0.45
rollback_transactionMethod · 0.45

Tested by

no test coverage detected