Struct redb::WriteTransaction

source ·
pub struct WriteTransaction<'db> { /* private fields */ }
Expand description

A read/write transaction

Only a single WriteTransaction may exist at a time

Implementations§

source§

impl<'db> WriteTransaction<'db>

source

pub fn persistent_savepoint(&self) -> Result<u64, SavepointError>

Creates a snapshot of the current database state, which can be used to rollback the database. This savepoint will exist until it is deleted with [delete_savepoint()].

Note that while a savepoint exists, pages that become unused after it was created are not freed. Therefore, the lifetime of a savepoint should be minimized.

Returns [SavepointError::InvalidSavepoint], if the transaction is “dirty” (any tables have been opened) or if the transaction’s durability is less than [Durability::Immediate]

source

pub fn get_persistent_savepoint( &self, id: u64 ) -> Result<Savepoint, SavepointError>

Get a persistent savepoint given its id

source

pub fn delete_persistent_savepoint( &self, id: u64 ) -> Result<bool, SavepointError>

Delete the given persistent savepoint.

Note that if the transaction is abort()’ed this deletion will be rolled back.

Returns true if the savepoint existed Returns [SavepointError::InvalidSavepoint] if the transaction’s durability is less than [Durability::Immediate]

source

pub fn list_persistent_savepoints( &self ) -> Result<impl Iterator<Item = u64>, StorageError>

List all persistent savepoints

source

pub fn ephemeral_savepoint(&self) -> Result<Savepoint, SavepointError>

Creates a snapshot of the current database state, which can be used to rollback the database

This savepoint will be freed as soon as the returned [Savepoint] is dropped.

Returns [SavepointError::InvalidSavepoint], if the transaction is “dirty” (any tables have been opened)

source

pub fn restore_savepoint( &mut self, savepoint: &Savepoint ) -> Result<(), SavepointError>

Restore the state of the database to the given Savepoint

Calling this method invalidates all Savepoints created after savepoint

source

pub fn set_durability(&mut self, durability: Durability)

Set the desired durability level for writes made in this transaction Defaults to Durability::Immediate

Will panic if the durability is reduced below [Durability::Immediate] after a persistent savepoint has been created or deleted.

source

pub fn open_table<'txn, K: RedbKey + 'static, V: RedbValue + 'static>( &'txn self, definition: TableDefinition<'_, K, V> ) -> Result<Table<'db, 'txn, K, V>, TableError>

Open the given table

The table will be created if it does not exist

source

pub fn open_multimap_table<'txn, K: RedbKey + 'static, V: RedbKey + 'static>( &'txn self, definition: MultimapTableDefinition<'_, K, V> ) -> Result<MultimapTable<'db, 'txn, K, V>, TableError>

Open the given table

The table will be created if it does not exist

source

pub fn delete_table( &self, definition: impl TableHandle ) -> Result<bool, TableError>

Delete the given table

Returns a bool indicating whether the table existed

source

pub fn delete_multimap_table( &self, definition: impl MultimapTableHandle ) -> Result<bool, TableError>

Delete the given table

Returns a bool indicating whether the table existed

source

pub fn list_tables( &self ) -> Result<impl Iterator<Item = UntypedTableHandle> + '_, StorageError>

List all the tables

source

pub fn list_multimap_tables( &self ) -> Result<impl Iterator<Item = UntypedMultimapTableHandle> + '_, StorageError>

List all the multimap tables

source

pub fn commit(self) -> Result<(), CommitError>

Commit the transaction

All writes performed in this transaction will be visible to future transactions, and are durable as consistent with the Durability level set by Self::set_durability

source

pub fn abort(self) -> Result<(), StorageError>

Abort the transaction

All writes performed in this transaction will be rolled back

source

pub fn stats(&self) -> Result<DatabaseStats, StorageError>

Retrieves information about storage usage in the database

Trait Implementations§

source§

impl<'a> Drop for WriteTransaction<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'db> RefUnwindSafe for WriteTransaction<'db>

§

impl<'db> !Send for WriteTransaction<'db>

§

impl<'db> Sync for WriteTransaction<'db>

§

impl<'db> Unpin for WriteTransaction<'db>

§

impl<'db> UnwindSafe for WriteTransaction<'db>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.