lmdb

Trait Transaction

Source
pub trait Transaction: Sized {
    // Required method
    fn txn(&self) -> *mut MDB_txn;

    // Provided methods
    fn commit(self) -> Result<()> { ... }
    fn abort(self) { ... }
    unsafe fn open_db(&self, name: Option<&str>) -> Result<Database> { ... }
    fn get<'txn, K>(
        &'txn self,
        database: Database,
        key: &K,
    ) -> Result<&'txn [u8]>
       where K: AsRef<[u8]> { ... }
    fn open_ro_cursor<'txn>(&'txn self, db: Database) -> Result<RoCursor<'txn>> { ... }
    fn db_flags(&self, db: Database) -> Result<DatabaseFlags> { ... }
    fn stat(&self, db: Database) -> Result<Stat> { ... }
}
Expand description

An LMDB transaction.

All database operations require a transaction.

Required Methods§

Source

fn txn(&self) -> *mut MDB_txn

Returns a raw pointer to the underlying LMDB transaction.

The caller must ensure that the pointer is not used after the lifetime of the transaction.

Provided Methods§

Source

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

Commits the transaction.

Any pending operations will be saved.

Source

fn abort(self)

Aborts the transaction.

Any pending operations will not be saved.

Source

unsafe fn open_db(&self, name: Option<&str>) -> Result<Database>

Opens a database in the transaction.

If name is None, then the default database will be opened, otherwise a named database will be opened. The database handle will be private to the transaction until the transaction is successfully committed. If the transaction is aborted the returned database handle should no longer be used.

Prefer using Environment::open_db.

§Safety

This function (as well as Environment::open_db, Environment::create_db, and Database::create) must not be called from multiple concurrent transactions in the same environment. A transaction which uses this function must finish (either commit or abort) before any other transaction may use this function.

Source

fn get<'txn, K>(&'txn self, database: Database, key: &K) -> Result<&'txn [u8]>
where K: AsRef<[u8]>,

Gets an item from a database.

This function retrieves the data associated with the given key in the database. If the database supports duplicate keys (DatabaseFlags::DUP_SORT) then the first data item for the key will be returned. Retrieval of other items requires the use of Transaction::cursor_get. If the item is not in the database, then Error::NotFound will be returned.

Source

fn open_ro_cursor<'txn>(&'txn self, db: Database) -> Result<RoCursor<'txn>>

Open a new read-only cursor on the given database.

Source

fn db_flags(&self, db: Database) -> Result<DatabaseFlags>

Gets the option flags for the given database in the transaction.

Source

fn stat(&self, db: Database) -> Result<Stat>

Retrieves database statistics.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'env> Transaction for RoTransaction<'env>

Source§

impl<'env> Transaction for RwTransaction<'env>