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>
impl<M: Manifest> DatabaseTransaction<M>
Sourcepub fn new<S: Storage>(database: &Database<S, M>) -> Self
pub fn new<S: Storage>(database: &Database<S, M>) -> Self
Creates a new empty transaction. Should be used by Database::create_transaction.
pub fn new_with_serialization_config( serialization_config: Configuration, ) -> Self
pub fn insert<K: RecordKey<Record = R>, R>( &mut self, record: R, ) -> Result<K, SerializationError>
pub fn put<S: Storage, R: DatabaseEntry>( &mut self, record: R, database: &mut Database<S, M>, ) -> Result<R::Key, DatabaseError<S::StoreError>>
Sourcepub fn write(&mut self, key: Vec<u8>, value: Vec<u8>)
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.
Sourcepub fn delete(&mut self, key: Vec<u8>)
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).
Sourcepub fn write_count(&self) -> usize
pub fn write_count(&self) -> usize
Returns the number of pending write operations.
Sourcepub fn delete_count(&self) -> usize
pub fn delete_count(&self) -> usize
Returns the number of pending delete operations.
Sourcepub fn pending_writes(&self) -> impl Iterator<Item = &(Vec<u8>, Vec<u8>)>
pub fn pending_writes(&self) -> impl Iterator<Item = &(Vec<u8>, Vec<u8>)>
Returns an iterator over the pending write operations.
Sourcepub fn pending_deletes(&self) -> impl Iterator<Item = &Vec<u8>>
pub fn pending_deletes(&self) -> impl Iterator<Item = &Vec<u8>>
Returns an iterator over the pending delete keys.
Sourcepub fn commit<S: AtomicStorage>(
self,
storage: &mut S,
) -> Result<Vec<Option<Vec<u8>>>, DatabaseError<S::StoreError>>
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.
Sourcepub fn rollback(self)
pub fn rollback(self)
Discards all pending operations without applying them. The transaction is consumed by this operation.