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§
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]>
fn get<'txn, K>(&'txn self, database: Database, key: &K) -> Result<&'txn [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.
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.