Struct libmdbx::Transaction
source · pub struct Transaction<'db, K, E>where
K: TransactionKind,
E: DatabaseKind,{ /* private fields */ }Expand description
An MDBX transaction.
All table operations require a transaction.
Implementations§
source§impl<'db, K, E> Transaction<'db, K, E>where
K: TransactionKind,
E: DatabaseKind,
impl<'db, K, E> Transaction<'db, K, E>where
K: TransactionKind,
E: DatabaseKind,
pub fn txn(&self) -> TxnPtr
sourcepub fn get<'txn, Key>(
&'txn self,
table: &Table<'txn>,
key: &[u8]
) -> Result<Option<Key>>where
Key: Decodable<'txn>,
pub fn get<'txn, Key>(
&'txn self,
table: &Table<'txn>,
key: &[u8]
) -> Result<Option<Key>>where
Key: Decodable<'txn>,
Gets an item from a table.
This function retrieves the data associated with the given key in the table. If the table supports duplicate keys (TableFlags::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 table, 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, table: Table<'_>)
sourcepub fn commit_and_rebind_open_dbs(self) -> Result<(bool, Vec<Table<'db>>)>
pub fn commit_and_rebind_open_dbs(self) -> Result<(bool, Vec<Table<'db>>)>
Commits the transaction and returns table handles permanently open for the lifetime of Database.
sourcepub fn open_table<'txn>(&'txn self, name: Option<&str>) -> Result<Table<'txn>>
pub fn open_table<'txn>(&'txn self, name: Option<&str>) -> Result<Table<'txn>>
Opens a handle to an MDBX table.
If name is None, then the returned handle will be for the default table.
If name is not None, then the returned handle will be for a named table. In this
case the database must be configured to allow named tables through
DatabaseBuilder::set_max_tables().
The returned table handle may be shared among any transaction in the database.
The table name may not contain the null character.
sourcepub fn table_flags<'txn>(&'txn self, table: &Table<'txn>) -> Result<TableFlags>
pub fn table_flags<'txn>(&'txn self, table: &Table<'txn>) -> Result<TableFlags>
Gets the option flags for the given table in the transaction.
sourcepub fn table_stat<'txn>(&'txn self, table: &Table<'txn>) -> Result<Stat>
pub fn table_stat<'txn>(&'txn self, table: &Table<'txn>) -> Result<Stat>
Retrieves table statistics.
source§impl<'db, E> Transaction<'db, RW, E>where
E: DatabaseKind,
impl<'db, E> Transaction<'db, RW, E>where
E: DatabaseKind,
sourcepub fn create_table<'txn>(
&'txn self,
name: Option<&str>,
flags: TableFlags
) -> Result<Table<'txn>>
pub fn create_table<'txn>( &'txn self, name: Option<&str>, flags: TableFlags ) -> Result<Table<'txn>>
Opens a handle to an MDBX table, creating the table if necessary.
If the table 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 table.
If name is not None, then the returned handle will be for a named table. In this
case the database must be configured to allow named tables through
DatabaseBuilder::set_max_tables().
This function will fail with Error::BadRslot if called by a thread with an open transaction.
sourcepub fn put<'txn>(
&'txn self,
table: &Table<'txn>,
key: impl AsRef<[u8]>,
data: impl AsRef<[u8]>,
flags: WriteFlags
) -> Result<()>
pub fn put<'txn>( &'txn self, table: &Table<'txn>, key: impl AsRef<[u8]>, data: impl AsRef<[u8]>, flags: WriteFlags ) -> Result<()>
Stores an item into a table.
This function stores key/data pairs in the table. 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 (TableFlags::DUP_SORT).
sourcepub fn reserve<'txn>(
&'txn self,
table: &Table<'txn>,
key: impl AsRef<[u8]>,
len: usize,
flags: WriteFlags
) -> Result<&'txn mut [u8]>
pub fn reserve<'txn>( &'txn self, table: &Table<'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,
table: &Table<'txn>,
key: impl AsRef<[u8]>,
data: Option<&[u8]>
) -> Result<bool>
pub fn del<'txn>( &'txn self, table: &Table<'txn>, key: impl AsRef<[u8]>, data: Option<&[u8]> ) -> Result<bool>
Delete items from a table. This function removes key/data pairs from the table.
The data parameter is NOT ignored regardless the table 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.
sourcepub fn clear_table<'txn>(&'txn self, table: &Table<'txn>) -> Result<()>
pub fn clear_table<'txn>(&'txn self, table: &Table<'txn>) -> Result<()>
Empties the given table. All items will be removed.
source§impl<'db, E> Transaction<'db, RO, E>where
E: DatabaseKind,
impl<'db, E> Transaction<'db, RO, E>where
E: DatabaseKind,
source§impl<'db> Transaction<'db, RW, NoWriteMap>
impl<'db> Transaction<'db, 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.