Struct redb::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
impl WriteTransaction
sourcepub fn persistent_savepoint(&self) -> Result<u64, SavepointError>
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]
sourcepub fn get_persistent_savepoint(
&self,
id: u64,
) -> Result<Savepoint, SavepointError>
pub fn get_persistent_savepoint( &self, id: u64, ) -> Result<Savepoint, SavepointError>
Get a persistent savepoint given its id
sourcepub fn delete_persistent_savepoint(
&self,
id: u64,
) -> Result<bool, SavepointError>
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]
sourcepub fn list_persistent_savepoints(&self) -> Result<impl Iterator<Item = u64>>
pub fn list_persistent_savepoints(&self) -> Result<impl Iterator<Item = u64>>
List all persistent savepoints
sourcepub fn ephemeral_savepoint(&self) -> Result<Savepoint, SavepointError>
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)
sourcepub fn restore_savepoint(
&mut self,
savepoint: &Savepoint,
) -> Result<(), SavepointError>
pub fn restore_savepoint( &mut self, savepoint: &Savepoint, ) -> Result<(), SavepointError>
sourcepub fn set_durability(&mut self, durability: Durability)
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.
sourcepub fn open_table<'txn, K: Key + 'static, V: Value + 'static>(
&'txn self,
definition: TableDefinition<'_, K, V>,
) -> Result<Table<'txn, K, V>, TableError>
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
sourcepub fn open_multimap_table<'txn, K: Key + 'static, V: Key + 'static>(
&'txn self,
definition: MultimapTableDefinition<'_, K, V>,
) -> Result<MultimapTable<'txn, K, V>, TableError>
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
sourcepub fn delete_table(
&self,
definition: impl TableHandle,
) -> Result<bool, TableError>
pub fn delete_table( &self, definition: impl TableHandle, ) -> Result<bool, TableError>
Delete the given table
Returns a bool indicating whether the table existed
sourcepub fn delete_multimap_table(
&self,
definition: impl MultimapTableHandle,
) -> Result<bool, TableError>
pub fn delete_multimap_table( &self, definition: impl MultimapTableHandle, ) -> Result<bool, TableError>
Delete the given table
Returns a bool indicating whether the table existed
sourcepub fn list_tables(
&self,
) -> Result<impl Iterator<Item = UntypedTableHandle> + '_>
pub fn list_tables( &self, ) -> Result<impl Iterator<Item = UntypedTableHandle> + '_>
List all the tables
sourcepub fn list_multimap_tables(
&self,
) -> Result<impl Iterator<Item = UntypedMultimapTableHandle> + '_>
pub fn list_multimap_tables( &self, ) -> Result<impl Iterator<Item = UntypedMultimapTableHandle> + '_>
List all the multimap tables
sourcepub fn commit(self) -> Result<(), CommitError>
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
sourcepub fn abort(self) -> Result
pub fn abort(self) -> Result
Abort the transaction
All writes performed in this transaction will be rolled back
sourcepub fn stats(&self) -> Result<DatabaseStats>
pub fn stats(&self) -> Result<DatabaseStats>
Retrieves information about storage usage in the database