Struct mmtkvdb::TxnRw

source ·
pub struct TxnRw<'a> { /* private fields */ }
Expand description

Read-write transaction

A read-write transaction can be started with EnvRw::txn_rw.

The methods for read-only access to the database are accessible through the Txn trait (which is implemented by TxnRo and TxnRw). Methods for write access, however, are available directly on the TxnRw struct.

Read-write transactions are aborted when dropped. To make changes permanent, TxnRw::commit must be called.

Read-write transactions are neither Send nor Sync.

Implementations§

source§

impl<'a> TxnRw<'a>

source

pub fn on_commit<F>(&mut self, commit_handler: F)where F: FnOnce(&mut Self) -> Result<()> + 'a,

Add commit handler to be executed on TxnRw::commit before the transaction is actually committed

source

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

Commit transaction

Previously added commit handlers (see TxnRw::on_commit) are executed in the same order as they have been added. If one commit handler reports an error, the transaction is aborted.

source

pub fn abort(self)

Abort transaction (same as drop)

source

pub fn nested(&mut self) -> Result<TxnRw<'_>>

Start nested transaction

Panics if environment does not support nested transactions (which is the case when the EnvBuilder::writemap flag has been set).

source

pub fn put<'kr, 'vr, K, V, C, KRef, VRef>( &mut self, db: &Db<K, V, C>, key: KRef, value: VRef ) -> Result<()>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + 'vr, C: Constraint, KRef: StorableRef<'kr, K>, VRef: StorableRef<'vr, V>,

Put value into database

This will overwrite an existing value if the database does not use the DbBuilder::keys_duplicate option.

source

pub fn put_unless_key_exists<'kr, 'vr, K, V, C, KRef, VRef>( &mut self, db: &Db<K, V, C>, key: KRef, value: VRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + 'vr, C: Constraint, KRef: StorableRef<'kr, K>, VRef: StorableRef<'vr, V>,

Put value into database unless key exists

Returns Ok(false) if key exists.

source

pub fn put_unless_pair_exists<'kr, 'vr, K, V, KRef, VRef>( &mut self, db: &Db<K, V, KeysDuplicate>, key: KRef, value: VRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + 'vr, KRef: StorableRef<'kr, K>, VRef: StorableRef<'vr, V>,

Put value into database unless key-value pair exists

Returns Ok(false) if key-value pair exists.

source

pub fn delete_key<'kr, K, V, C, KRef>( &mut self, db: &Db<K, V, C>, key: KRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable, C: Constraint, KRef: StorableRef<'kr, K>,

Delete all values from database that match a given key

source

pub fn delete_pair<'kr, 'vr, K, V, KRef, VRef>( &mut self, db: &Db<K, V, KeysDuplicate>, key: KRef, value: VRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + 'vr, KRef: StorableRef<'kr, K>, VRef: StorableRef<'vr, V>,

Delete key-value pair from database

source

pub fn delete_all<K, V, C>(&mut self, db: &Db<K, V, C>) -> Result<()>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Delete all entries in a database

Use EnvRw::drop_db to completely drop the database.

source

pub fn cursor_delete_current<K, V, C>( &mut self, cursor: &Cursor<K, V, C> ) -> Result<()>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Delete key-value pair at current cursor position

source

pub fn cursor_delete_current_key<K, V>( &mut self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<()>where K: ?Sized + Storable, V: ?Sized + Storable,

Delete all values with same key at current cursor position

Trait Implementations§

source§

impl<'a> Debug for TxnRw<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Txn for TxnRw<'a>

source§

fn get<'kr, K, V, C, KRef>( &self, db: &Db<K, V, C>, key: KRef ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable, C: Constraint, KRef: StorableRef<'kr, K>,

Get reference to value in database
source§

fn new_cursor<K, V, C>(&self, db: &Db<K, V, C>) -> Result<Cursor<K, V, C>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Create a new cursor
source§

fn cursor_get_current_value_count<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<usize>where K: ?Sized + Storable, V: ?Sized + Storable,

Get number of values for current cursor position
source§

fn cursor_set_first<K, V, C>(&self, cursor: &Cursor<K, V, C>) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Set cursor to first entry in database Read more
source§

fn cursor_set_first_get_pair<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Set cursor to first entry in database and get pair
source§

fn cursor_set_last<K, V, C>(&self, cursor: &Cursor<K, V, C>) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Set cursor to last entry in database Read more
source§

fn cursor_set_last_get_pair<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Set cursor to last entry in database and get pair
source§

fn cursor_get_current_key<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<K::AlignedRef<'_>>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Get key at current cursor position
source§

fn cursor_get_current_value<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Get value at current cursor position
source§

fn cursor_get_current_pair<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Get key-value pair at current cursor position
source§

fn cursor_set_key<'kr, K, V, C, KRef>( &self, cursor: &Cursor<K, V, C>, key: KRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable, C: Constraint, KRef: StorableRef<'kr, K>,

Set cursor to key Read more
source§

fn cursor_set_key_get_value<'kr, K, V, C, KRef>( &self, cursor: &Cursor<K, V, C>, key: KRef ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable, C: Constraint, KRef: StorableRef<'kr, K>,

Set cursor to key and get value
source§

fn cursor_search_key<'kr, K, V, C, KRef>( &self, cursor: &Cursor<K, V, C>, key: KRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable, C: Constraint, KRef: StorableRef<'kr, K>,

Set cursor to key or next greater key if not existent Read more
source§

fn cursor_search_key_get_key<'kr, K, V, C, KRef>( &self, cursor: &Cursor<K, V, C>, key: KRef ) -> Result<Option<K::AlignedRef<'_>>>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable, C: Constraint, KRef: StorableRef<'kr, K>,

👎Deprecated since 0.14.0: use <code>cursor_search_key</code> (with subsequent <code>cursor_get_current_key</code>) or <code>cursor_search_key_get_pair</code>
Set cursor to key or next greater key if not existent and get key
source§

fn cursor_search_key_get_pair<'kr, K, V, C, KRef>( &self, cursor: &Cursor<K, V, C>, key: KRef ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable, C: Constraint, KRef: StorableRef<'kr, K>,

Set cursor to key or next greater key if not existent and get pair
source§

fn cursor_set_next<K, V, C>(&self, cursor: &Cursor<K, V, C>) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to next entry in database Read more
source§

fn cursor_set_next_get_pair<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to next entry in database and get pair
source§

fn cursor_set_prev<K, V, C>(&self, cursor: &Cursor<K, V, C>) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to previous entry in database Read more
source§

fn cursor_set_prev_get_pair<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to previous entry in database and get pair
source§

fn cursor_set_next_key<K, V, C>(&self, cursor: &Cursor<K, V, C>) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to first value of next key Read more
source§

fn cursor_set_next_key_get_pair<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to first value of next key and get pair
source§

fn cursor_set_prev_key<K, V, C>(&self, cursor: &Cursor<K, V, C>) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to last value of previous key Read more
source§

fn cursor_set_prev_key_get_pair<K, V, C>( &self, cursor: &Cursor<K, V, C> ) -> Result<Option<(K::AlignedRef<'_>, V::AlignedRef<'_>)>>where K: ?Sized + Storable, V: ?Sized + Storable, C: Constraint,

Move cursor to last value of previous key and get pair
source§

fn cursor_set_first_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to first value of current key Read more
source§

fn cursor_set_first_value_get_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to first value of current key and get value
source§

fn cursor_set_last_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to last value of current key Read more
source§

fn cursor_set_last_value_get_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to last value of current key and get value
source§

fn cursor_set_pair<'kr, 'vr, K, V, KRef, VRef>( &self, cursor: &Cursor<K, V, KeysDuplicate>, key: KRef, value: VRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + 'vr, KRef: StorableRef<'kr, K>, VRef: StorableRef<'vr, V>,

Set cursor to key-value pair Read more
source§

fn cursor_set_key_search_value<'kr, 'vr, K, V, KRef, VRef>( &self, cursor: &Cursor<K, V, KeysDuplicate>, key: KRef, value: VRef ) -> Result<bool>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + 'vr, KRef: StorableRef<'kr, K>, VRef: StorableRef<'vr, V>,

Set cursor to key and value or next greater value if not existent Read more
source§

fn cursor_set_key_search_value_get_value<'kr, 'vr, K, V, KRef, VRef>( &self, cursor: &Cursor<K, V, KeysDuplicate>, key: KRef, value: VRef ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + 'vr, KRef: StorableRef<'kr, K>, VRef: StorableRef<'vr, V>,

Set cursor to key and value or next greater value if not existent and get value
source§

fn cursor_set_next_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to next value of current key Read more
source§

fn cursor_set_next_value_get_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to next value of current key and get value
source§

fn cursor_set_prev_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<bool>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to next value of current key Read more
source§

fn cursor_set_prev_value_get_value<K, V>( &self, cursor: &Cursor<K, V, KeysDuplicate> ) -> Result<Option<V::AlignedRef<'_>>>where K: ?Sized + Storable, V: ?Sized + Storable,

Move cursor to next value of current key and get value
source§

fn get_owned<'a, 'kr, K, V, C, KRef>( &'a self, db: &Db<K, V, C>, key: KRef ) -> Result<Option<<V as ToOwned>::Owned>>where K: ?Sized + Storable + 'kr, V: ?Sized + Storable + ToOwned, C: Constraint, KRef: StorableRef<'kr, K>,

Get owned value from database

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for TxnRw<'a>

§

impl<'a> !Send for TxnRw<'a>

§

impl<'a> !Sync for TxnRw<'a>

§

impl<'a> Unpin for TxnRw<'a>

§

impl<'a> !UnwindSafe for TxnRw<'a>

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.