redb

Struct WriteTransaction

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

A read/write transaction

Only a single WriteTransaction may exist at a time

Implementations§

Source§

impl WriteTransaction

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

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: Key + 'static, V: Value + 'static>( &'txn self, definition: TableDefinition<'_, K, V>, ) -> Result<Table<'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: Key + 'static, V: Key + 'static>( &'txn self, definition: MultimapTableDefinition<'_, K, V>, ) -> Result<MultimapTable<'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> + '_>

List all the tables

Source

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

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

Abort the transaction

All writes performed in this transaction will be rolled back

Source

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

Retrieves information about storage usage in the database

Trait Implementations§

Source§

impl Drop for WriteTransaction

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> 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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 704 bytes