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.
Implementations§
source§impl<'a> TxnRw<'a>
impl<'a> TxnRw<'a>
sourcepub fn on_commit<F>(&mut self, commit_handler: F)where
F: FnOnce(&mut Self) -> Result<()> + 'a,
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
sourcepub fn commit(self) -> Result<()>
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.
sourcepub fn nested(&mut self) -> Result<TxnRw<'_>>
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).
sourcepub 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>,
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.
sourcepub 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>,
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.
sourcepub 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>,
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.
sourcepub 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>,
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
sourcepub 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>,
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
sourcepub fn delete_all<K, V, C>(&mut self, db: &Db<K, V, C>) -> Result<()>where
K: ?Sized + Storable,
V: ?Sized + Storable,
C: Constraint,
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.
sourcepub fn cursor_delete_current<K, V, C>(
&mut self,
cursor: &Cursor<K, V, C>
) -> Result<()>where
K: ?Sized + Storable,
V: ?Sized + Storable,
C: Constraint,
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
sourcepub fn cursor_delete_current_key<K, V>(
&mut self,
cursor: &Cursor<K, V, KeysDuplicate>
) -> Result<()>where
K: ?Sized + Storable,
V: ?Sized + Storable,
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