DatabaseTransaction

Struct DatabaseTransaction 

Source
pub struct DatabaseTransaction<Manifest> { /* private fields */ }
Expand description

A database transaction that accumulates low-level byte operations (writes and deletes) without immediately applying them to storage.

This struct is always available, but the commit method is only available when the “atomic” feature is enabled.

Implementations§

Source§

impl<M: Manifest> DatabaseTransaction<M>

Source

pub fn new<S: Storage>(database: &Database<S, M>) -> Self

Creates a new empty transaction. Should be used by Database::create_transaction.

Source

pub fn new_with_serialization_config( serialization_config: Configuration, ) -> Self

Source

pub fn insert<K: RecordKey<Record = R>, R>( &mut self, record: R, ) -> Result<K, SerializationError>
where R: DeriveKey<Key = K> + DatabaseEntry<Key = K>, M: Manifests<R>,

Source

pub fn put<S: Storage, R: DatabaseEntry>( &mut self, record: R, database: &mut Database<S, M>, ) -> Result<R::Key, DatabaseError<S::StoreError>>
where R::Key: RecordKey<Record = R> + Incrementable + Ord, M: Manifests<R>,

Source

pub fn write(&mut self, key: Vec<u8>, value: Vec<u8>)

Adds a write operation to the transaction.

If the same key is written multiple times, only the last value is kept. If a key is both written and deleted, the write takes precedence.

Source

pub fn delete(&mut self, key: Vec<u8>)

Adds a delete operation to the transaction.

If a key is both written and deleted, the write takes precedence (so this delete will be ignored if the key was already written).

Source

pub fn is_empty(&self) -> bool

Returns true if the transaction has no pending operations.

Source

pub fn write_count(&self) -> usize

Returns the number of pending write operations.

Source

pub fn delete_count(&self) -> usize

Returns the number of pending delete operations.

Source

pub fn pending_writes(&self) -> impl Iterator<Item = &(Vec<u8>, Vec<u8>)>

Returns an iterator over the pending write operations.

Source

pub fn pending_deletes(&self) -> impl Iterator<Item = &Vec<u8>>

Returns an iterator over the pending delete keys.

Source

pub fn commit<S: AtomicStorage>( self, storage: &mut S, ) -> Result<Vec<Option<Vec<u8>>>, DatabaseError<S::StoreError>>

Commits all pending operations to the storage atomically.

Either all operations succeed, or none of them are applied. The transaction is consumed by this operation.

This method is only available when the “atomic” feature is enabled.

Source

pub fn rollback(self)

Discards all pending operations without applying them. The transaction is consumed by this operation.

Source

pub fn consume( self, ) -> (impl Iterator<Item = (Vec<u8>, Vec<u8>)>, impl Iterator<Item = Vec<u8>>)

Auto Trait Implementations§

§

impl<Manifest> Freeze for DatabaseTransaction<Manifest>

§

impl<Manifest> RefUnwindSafe for DatabaseTransaction<Manifest>
where Manifest: RefUnwindSafe,

§

impl<Manifest> Send for DatabaseTransaction<Manifest>
where Manifest: Send,

§

impl<Manifest> Sync for DatabaseTransaction<Manifest>
where Manifest: Sync,

§

impl<Manifest> Unpin for DatabaseTransaction<Manifest>
where Manifest: Unpin,

§

impl<Manifest> UnwindSafe for DatabaseTransaction<Manifest>
where Manifest: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.