Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

Transaction

Struct Transaction 

Source
pub struct Transaction { /* private fields */ }
Expand description

Represents a single, atomic transaction for modifying a Database.

An Transaction encapsulates a mutable EntryBuilder being constructed. Users interact with specific Store instances obtained via Transaction::get_store to stage changes. All staged changes across different subtrees within the transaction are recorded in the internal EntryBuilder.

When commit() is called, the transaction:

  1. Finalizes the EntryBuilder by building an immutable Entry
  2. Calculates the entry’s content-addressable ID
  3. Ensures the correct parent links are set based on the tree’s state
  4. Removes any empty subtrees that didn’t have data staged
  5. Signs the entry if authentication is configured
  6. Persists the resulting immutable Entry to the backend

Transaction instances are typically created via Database::new_transaction().

Implementations§

Source§

impl Transaction

Source

pub fn get_settings(&self) -> Result<SettingsStore>

Get a SettingsStore handle for the settings subtree within this transaction.

This method returns a SettingsStore that provides specialized access to the _settings subtree, allowing you to read and modify settings data within this atomic transaction. The DocStore automatically merges historical settings from the database with any staged changes in this transaction.

§Returns

Returns a Result<SettingsStore> that can be used to:

  • Read current settings values (including both historical and staged data)
  • Stage new settings changes within this transaction
  • Access nested settings structures
§Example
let txn = database.new_transaction().await?;
let settings = txn.get_settings()?;

// Read a setting
if let Ok(name) = settings.get_name().await {
    println!("Database name: {}", name);
}

// Modify a setting
settings.set_name("Updated Database Name").await?;
§Errors

Returns an error if:

  • Unable to create the SettingsStore for the settings subtree
  • Operation has already been committed
Source

pub async fn get_index(&self) -> Result<Registry>

Gets a handle to the Index for managing subtree registry and metadata.

The Index provides access to the _index subtree, which stores metadata about all subtrees in the database including their type identifiers and configurations.

§Returns

A Result<Registry> containing the handle for managing the index.

§Errors

Returns an error if:

  • Unable to create the Registry for the _index subtree
  • Operation has already been committed
Source

pub async fn get_store<T>( &self, subtree_name: impl Into<String> + Send, ) -> Result<T>
where T: Store + Send,

Gets a handle to a specific Store for modification within this transaction.

This method creates and returns an instance of the specified Store type T, associated with this Transaction. The returned Store handle can be used to stage changes (e.g., using DocStore::set). These changes are recorded within this Transaction.

If this is the first time this subtree is accessed within the transaction, its parent tips will be fetched and stored.

§Type Parameters
  • T - The concrete Store implementation type to create.
§Arguments
  • subtree_name - The name of the subtree to get a modification handle for.
§Returns

A Result<T> containing the Store handle.

Source

pub fn get_local_data<T>( &self, subtree_name: impl AsRef<str>, ) -> Result<Option<T>>
where T: Data,

Gets the currently staged data for a specific subtree within this transaction.

This is intended for use by Store implementations to retrieve the data they have staged locally within the Transaction before potentially merging it with historical data.

§Type Parameters
  • T - The data type (expected to be a CRDT) to deserialize the staged data into.
§Arguments
  • subtree_name - The name of the subtree whose staged data is needed.
§Returns

A Result<Option<T>>:

§Behavior
  • If the subtree doesn’t exist or has no data, returns Ok(None)
  • If the subtree exists but has empty data (empty string or whitespace), returns Ok(None)
  • Otherwise deserializes the JSON data to type T and returns Ok(Some(T))
§Errors

Returns an error if the transaction has already been committed or if the subtree data exists but cannot be deserialized to type T.

Source

pub async fn commit(self) -> Result<ID>

Commits the transaction, finalizing and persisting the entry to the backend.

This method:

  1. Takes ownership of the EntryBuilder from the internal Option
  2. Removes any empty subtrees
  3. Adds metadata if appropriate
  4. Sets authentication if configured
  5. Builds the immutable Entry using EntryBuilder::build()
  6. Signs the entry if authentication is configured
  7. Validates authentication if present
  8. Calculates the entry’s content-addressable ID
  9. Persists the entry to the backend
  10. Returns the ID of the newly created entry

After commit, the transaction cannot be used again, as the internal EntryBuilder has been consumed.

§Returns

A Result<ID> containing the ID of the committed entry.

Trait Implementations§

Source§

impl Clone for Transaction

Source§

fn clone(&self) -> Transaction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more