pub struct TransactionHandle { /* private fields */ }Expand description
Transaction handle for atomic registry operations
This is a clonable, Send + Sync + ’static handle that can be passed to async functions without lifetime issues.
§Examples
// Start a transaction
let tx = registry.start_transaction().await?;
// Queue operations (they don't execute yet)
let id1 = tx.clone_repo("repo1", "https://github.com/user/repo1.git").await?;
let id2 = tx.clone_repo("repo2", "https://github.com/user/repo2.git").await?;
// Commit atomically (all operations succeed or all fail)
tx.commit().await?;
// Or rollback (discards all operations)
// tx.rollback().await?;Implementations§
Source§impl TransactionHandle
impl TransactionHandle
Sourcepub async fn clone_repo(&self, name: &str, url: &str) -> Git2DBResult<RepoId>
pub async fn clone_repo(&self, name: &str, url: &str) -> Git2DBResult<RepoId>
Clone a repository within the transaction
The operation is queued and will execute on commit.
Sourcepub async fn remove(&self, id: &RepoId) -> Git2DBResult<()>
pub async fn remove(&self, id: &RepoId) -> Git2DBResult<()>
Remove a repository within the transaction
The operation is queued and will execute on commit.
Sourcepub async fn update(&self, id: &RepoId, url: Option<String>) -> Git2DBResult<()>
pub async fn update(&self, id: &RepoId, url: Option<String>) -> Git2DBResult<()>
Update a repository within the transaction
Sourcepub async fn ensure(&self, name: &str, url: &str) -> Git2DBResult<RepoId>
pub async fn ensure(&self, name: &str, url: &str) -> Git2DBResult<RepoId>
Ensure a repository exists (upsert operation)
If a repository with the given name exists, returns its ID. Otherwise, clones it and returns the new ID.
Sourcepub async fn operations(&self) -> Vec<String>
pub async fn operations(&self) -> Vec<String>
Get list of queued operations
Sourcepub async fn commit_to(self, registry: &mut Git2DB) -> Git2DBResult<()>
pub async fn commit_to(self, registry: &mut Git2DB) -> Git2DBResult<()>
Commit the transaction, applying all operations atomically to the registry
On success, all operations are applied to the registry. On failure, the transaction is rolled back and all operations are discarded.
§Examples
let tx = registry.start_transaction().await?;
let id = tx.clone_repo("repo", "https://github.com/user/repo.git").await?;
tx.commit_to(&mut registry).await?; // Apply operationsSourcepub async fn commit(self) -> Git2DBResult<()>
👎Deprecated since 2.1.0: Use commit_to(&mut registry) instead
pub async fn commit(self) -> Git2DBResult<()>
Use commit_to(&mut registry) instead
Commit the transaction without a registry reference
Deprecated: This method doesn’t actually apply operations.
Use commit_to(&mut registry) instead.
Sourcepub async fn rollback(self) -> Git2DBResult<()>
pub async fn rollback(self) -> Git2DBResult<()>
Rollback the transaction, discarding all operations
All queued operations are discarded and the worktree is removed.
Trait Implementations§
Source§impl Clone for TransactionHandle
impl Clone for TransactionHandle
Source§fn clone(&self) -> TransactionHandle
fn clone(&self) -> TransactionHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TransactionHandle
impl !RefUnwindSafe for TransactionHandle
impl Send for TransactionHandle
impl Sync for TransactionHandle
impl Unpin for TransactionHandle
impl UnsafeUnpin for TransactionHandle
impl !UnwindSafe for TransactionHandle
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more