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]

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.

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();
}

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.

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>>

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!

Creates a new cursor scoped to this transaction, bound to the given database.

Returns the internal id of this transaction.

Retrieves statistics for a database.

Retrieve the DB flags for a database handle.

Trait Implementations

impl<'env> Debug for ReadTransaction<'env>
[src]

Formats the value using the given formatter.

impl<'env> Deref for ReadTransaction<'env>
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<'env> DerefMut for ReadTransaction<'env>
[src]

The method called to mutably dereference a value