Struct lmdb_zero::ReadTransaction
[−]
[src]
pub struct ReadTransaction<'env>(_);
A read-only LMDB transaction.
In addition to all operations valid on ConstTransaction
, a
ReadTransaction
can additionally operate on cursors with a lifetime
scoped to the environment instead of the transaction.
Lifetime
All notes for ConstTransaction
apply.
Methods
impl<'env> ReadTransaction<'env>
[src]
fn new(env: &'env Environment) -> Result<Self>
Opens a new, read-only transaction within 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
transaction at a time. If NOTLS
is in use, this does not apply to
read-only transactions. Attempting to open a read-only transaction
while the current thread holds a read-write transaction will deadlock.
fn dissoc_cursor<'txn, 'db>(&self,
cursor: Cursor<'txn, 'db>)
-> Result<StaleCursor<'db>> where 'env: 'db
cursor: Cursor<'txn, 'db>)
-> Result<StaleCursor<'db>> where 'env: 'db
Dissociates the given cursor from this transaction and its database,
returning a StaleCursor
which can be reused later.
This only fails if cursor
does not belong to this transaction.
Example
let mut saved_cursor; { let txn = lmdb::ReadTransaction::new(&env).unwrap(); let cursor = txn.cursor(&db).unwrap(); // Do some stuff with `txn` and `cursor` // We don't want to realloc `cursor` next time, so save it away saved_cursor = txn.dissoc_cursor(cursor).unwrap(); } // Read transaction goes away, but our saved cursor remains { let txn = lmdb::ReadTransaction::new(&env).unwrap(); // Rebind the old cursor. It continues operating on `db`. let cursor = txn.assoc_cursor(saved_cursor).unwrap(); // Do stuff with txn, cursor // We can save the cursor away again saved_cursor = txn.dissoc_cursor(cursor).unwrap(); }
fn assoc_cursor<'txn, 'db>(&'txn self,
cursor: StaleCursor<'db>)
-> Result<Cursor<'txn, 'db>>
cursor: StaleCursor<'db>)
-> Result<Cursor<'txn, 'db>>
Associates a saved read-only with this transaction.
The cursor will be rebound to this transaction, but will continue using the same database that it was previously.
fn reset(self) -> ResetTransaction<'env>
Resets this transaction, releasing most of its resources but allowing it to be quickly renewed if desired.
Example
let mut saved_txn; { let txn = lmdb::ReadTransaction::new(&env).unwrap(); { let access = txn.access(); // Do stuff with `txn`, `access` } // Save our transaction so we don't have to reallocate it next time, // but we also don't keep locks around and will later move to the // latest version of the environment. saved_txn = txn.reset(); } { // Instead of creating a brand new transaction, renew the one we // saved. let txn = saved_txn.renew().unwrap(); { let access = txn.access(); // Do stuff with `txn`, `access` } // We can save the transaction away again saved_txn = txn.reset(); }
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 ReadTransaction<'env>
[src]
impl<'env> Deref for ReadTransaction<'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 ReadTransaction<'env>
[src]
fn deref_mut(&mut self) -> &mut ConstTransaction<'env>
The method called to mutably dereference a value