Struct libmdbx::Transaction
source · [−]pub struct Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind, { /* private fields */ }Expand description
An MDBX transaction.
All database operations require a transaction.
Implementations
sourceimpl<'env, K, E> Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
impl<'env, K, E> Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
pub fn txn(&self) -> *mut MDBX_txn
sourcepub fn env(&self) -> &Environment<E>
pub fn env(&self) -> &Environment<E>
Returns a raw pointer to the MDBX environment.
sourcepub fn get<'txn, Key>(
&'txn self,
db: &Database<'txn>,
key: &[u8]
) -> Result<Option<Key>> where
Key: TableObject<'txn>,
pub fn get<'txn, Key>(
&'txn self,
db: &Database<'txn>,
key: &[u8]
) -> Result<Option<Key>> where
Key: TableObject<'txn>,
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 Cursor. If the item is not in the database, then None will be returned.
sourcepub fn commit(self) -> Result<bool>
pub fn commit(self) -> Result<bool>
Commits the transaction.
Any pending operations will be saved.
pub fn prime_for_permaopen(&self, db: Database<'_>)
sourcepub fn commit_and_rebind_open_dbs(self) -> Result<(bool, Vec<Database<'env>>)>
pub fn commit_and_rebind_open_dbs(self) -> Result<(bool, Vec<Database<'env>>)>
Commits the transaction and returns table handles permanently open for the lifetime of Environment.
sourcepub fn open_db<'txn>(&'txn self, name: Option<&str>) -> Result<Database<'txn>>
pub fn open_db<'txn>(&'txn self, name: Option<&str>) -> Result<Database<'txn>>
Opens a handle to an MDBX database.
If name is None, then the returned handle will be for the default database.
If name is not None, then the returned handle will be for a named database. In this
case the environment must be configured to allow named databases through
EnvironmentBuilder::set_max_dbs().
The returned database handle may be shared among any transaction in the environment.
The database name may not contain the null character.
sourcepub fn db_flags<'txn>(&'txn self, db: &Database<'txn>) -> Result<DatabaseFlags>
pub fn db_flags<'txn>(&'txn self, db: &Database<'txn>) -> Result<DatabaseFlags>
Gets the option flags for the given database in the transaction.
sourceimpl<'env, E> Transaction<'env, RW, E> where
E: EnvironmentKind,
impl<'env, E> Transaction<'env, RW, E> where
E: EnvironmentKind,
sourcepub fn create_db<'txn>(
&'txn self,
name: Option<&str>,
flags: DatabaseFlags
) -> Result<Database<'txn>>
pub fn create_db<'txn>(
&'txn self,
name: Option<&str>,
flags: DatabaseFlags
) -> Result<Database<'txn>>
Opens a handle to an MDBX database, creating the database if necessary.
If the database is already created, the given option flags will be added to it.
If name is None, then the returned handle will be for the default database.
If name is not None, then the returned handle will be for a named database. In this
case the environment must be configured to allow named databases through
EnvironmentBuilder::set_max_dbs().
This function will fail with Error::BadRslot if called by a thread with an open transaction.
sourcepub fn put<'txn>(
&'txn self,
db: &Database<'txn>,
key: impl AsRef<[u8]>,
data: impl AsRef<[u8]>,
flags: WriteFlags
) -> Result<()>
pub fn put<'txn>(
&'txn self,
db: &Database<'txn>,
key: impl AsRef<[u8]>,
data: impl AsRef<[u8]>,
flags: WriteFlags
) -> Result<()>
Stores an item into a database.
This function stores key/data pairs in the database. The default behavior is to enter the new key/data pair, replacing any previously existing key if duplicates are disallowed, or adding a duplicate data item if duplicates are allowed (DatabaseFlags::DUP_SORT).
sourcepub fn reserve<'txn>(
&'txn self,
db: &Database<'txn>,
key: impl AsRef<[u8]>,
len: usize,
flags: WriteFlags
) -> Result<&'txn mut [u8]>
pub fn reserve<'txn>(
&'txn self,
db: &Database<'txn>,
key: impl AsRef<[u8]>,
len: usize,
flags: WriteFlags
) -> Result<&'txn mut [u8]>
Returns a buffer which can be used to write a value into the item at the given key and with the given length. The buffer must be completely filled by the caller.
sourcepub fn del<'txn>(
&'txn self,
db: &Database<'txn>,
key: impl AsRef<[u8]>,
data: Option<&[u8]>
) -> Result<bool>
pub fn del<'txn>(
&'txn self,
db: &Database<'txn>,
key: impl AsRef<[u8]>,
data: Option<&[u8]>
) -> Result<bool>
Delete items from a database. This function removes key/data pairs from the database.
The data parameter is NOT ignored regardless the database does support sorted duplicate data items or not. If the data parameter is Some only the matching data item will be deleted. Otherwise, if data parameter is None, any/all value(s) for specified key will be deleted.
Returns true if the key/value pair was present.
sourceimpl<'env, E> Transaction<'env, RO, E> where
E: EnvironmentKind,
impl<'env, E> Transaction<'env, RO, E> where
E: EnvironmentKind,
sourceimpl<'env> Transaction<'env, RW, NoWriteMap>
impl<'env> Transaction<'env, RW, NoWriteMap>
sourcepub fn begin_nested_txn(&mut self) -> Result<Transaction<'_, RW, NoWriteMap>>
pub fn begin_nested_txn(&mut self) -> Result<Transaction<'_, RW, NoWriteMap>>
Begins a new nested transaction inside of this transaction.
Trait Implementations
sourceimpl<'env, K, E> Debug for Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
impl<'env, K, E> Debug for Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
sourceimpl<'env, K, E> Drop for Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
impl<'env, K, E> Drop for Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
impl<'env, K, E> Send for Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
impl<'env, K, E> Sync for Transaction<'env, K, E> where
K: TransactionKind,
E: EnvironmentKind,
Auto Trait Implementations
impl<'env, K, E> !RefUnwindSafe for Transaction<'env, K, E>
impl<'env, K, E> Unpin for Transaction<'env, K, E>
impl<'env, K, E> !UnwindSafe for Transaction<'env, K, E>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more