Trait lmdb::Transaction
source · pub trait Transaction: Sized {
fn txn(&self) -> *mut MDB_txn;
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> { ... }
}
Expand description
An LMDB transaction.
All database operations require a transaction.
Required Methods§
Provided Methods§
sourceunsafe fn open_db(&self, name: Option<&str>) -> Result<Database>
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.
sourcefn get<'txn, K>(&'txn self, database: Database, key: &K) -> Result<&'txn [u8]>where
K: AsRef<[u8]>,
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.
sourcefn open_ro_cursor<'txn>(&'txn self, db: Database) -> Result<RoCursor<'txn>>
fn open_ro_cursor<'txn>(&'txn self, db: Database) -> Result<RoCursor<'txn>>
Open a new read-only cursor on the given database.
sourcefn db_flags(&self, db: Database) -> Result<DatabaseFlags>
fn db_flags(&self, db: Database) -> Result<DatabaseFlags>
Gets the option flags for the given database in the transaction.