Struct lmdb_zero::WriteTransaction
[−]
[src]
pub struct WriteTransaction<'env>(_);
A read-write LMDB transaction.
In addition to all operations valid on ConstTransaction
, it is also
possible to perform writes to the underlying databases.
Lifetime
All notes for ConstTransaction
apply.
Methods
impl<'env> WriteTransaction<'env>
[src]
fn new(env: &'env Environment) -> Result<Self>
Creates a new, read-write transaction in the given environment.
Note
A transaction and its cursors must only be used by a single thread
(enforced by the rust compiler), and a thread may only have a single
read-write transaction at a time (even if NOTLS
is in use --- trying
to start two top-level read-write transactions on the same thread will
deadlock).
fn child_tx<'a>(&'a mut self) -> Result<WriteTransaction<'a>> where 'env: 'a
Opens a new, read-write transaction as a child transaction of the given parent. While the new transaction exists, no operations may be performed on the parent or any of its cursors. (These bindings are actually stricter, and do not permit cursors or other references into the parent to coexist with the child transaction.)
After this call, whether or not it succeeds, it is possible to call
access()
on the original transaction again one more time, since the
Rust borrow rules guarantee the old accessor was destroyed by the
caller already.
Note
A transaction and its cursors must only be used by a single thread (enforced by the rust compiler).
Example
let db = lmdb::Database::open( &env, None, &lmdb::DatabaseOptions::defaults()).unwrap(); let mut txn = lmdb::WriteTransaction::new(&env).unwrap(); let f = lmdb::put::Flags::empty(); { let mut access = txn.access(); access.put(&db, "Germany", "Berlin", f).unwrap(); access.put(&db, "Latvia", "Rīga", f).unwrap(); access.put(&db, "France", "Paris", f).unwrap(); } { // Open a child transaction and do some more reading and writing. let subtx = txn.child_tx().unwrap(); let mut access = subtx.access(); assert_eq!("Berlin", access.get::<str,str>(&db, "Germany").unwrap()); access.put(&db, "Germany", "Frankfurt", f).unwrap(); assert_eq!("Frankfurt", access.get::<str,str>(&db, "Germany").unwrap()); // Don't commit --- let the child transaction abort (roll back) } { let mut access = txn.access(); // Now we can do some more reading and writing on the original // transaction. // The effect of the aborted child transaction are not visible. access.put(&db, "United Kingdom", "London", f).unwrap(); assert_eq!("Berlin", access.get::<str,str>(&db, "Germany").unwrap()); } { // Another child. let subtx = txn.child_tx().unwrap(); { let mut access = subtx.access(); access.put(&db, "Spain", "Madrid", f).unwrap(); } // Commit this one this time. subtx.commit().unwrap(); } { // Now the changes from the child are visible to this transaction, // but still not outside it. let mut access = txn.access(); assert_eq!("Madrid", access.get::<str,str>(&db, "Spain").unwrap()); } txn.commit().unwrap();
fn commit(self) -> Result<()>
Commits this write transaction.
fn access(&self) -> WriteAccessor
Returns a read/write accessor on this transaction.
Panics
Panics if called more than once on the same transaction.
Methods from Deref<Target=ConstTransaction<'env>>
fn access(&self) -> ConstAccessor
Returns an accessor used to manipulate data in this transaction.
Panics
Panics if this function has already been called on this transaction.
Example
let txn = lmdb::ReadTransaction::new(&env).unwrap(); // Get access the first time let access = txn.access(); // You can't get the accessor again, since this would create two // references to the same logical memory and allow creating aliased // mutable references and so forth. let access2 = txn.access(); // PANIC!
fn cursor<'txn, 'db>(&'txn self, db: &'db Database) -> Result<Cursor<'txn, 'db>>
Creates a new cursor scoped to this transaction, bound to the given database.
fn id(&self) -> usize
Returns the internal id of this transaction.
fn db_stat(&self, db: &Database) -> Result<Stat>
Retrieves statistics for a database.
fn db_flags(&self, db: &Database) -> Result<Flags>
Retrieve the DB flags for a database handle.
Trait Implementations
impl<'env> Debug for WriteTransaction<'env>
[src]
impl<'env> Deref for WriteTransaction<'env>
[src]
type Target = ConstTransaction<'env>
The resulting type after dereferencing
fn deref(&self) -> &ConstTransaction<'env>
The method called to dereference a value
impl<'env> DerefMut for WriteTransaction<'env>
[src]
fn deref_mut(&mut self) -> &mut ConstTransaction<'env>
The method called to mutably dereference a value