Struct libmdbx::Transaction

source ·
pub struct Transaction<'db, K, E>{ /* private fields */ }
Expand description

An MDBX transaction.

All table operations require a transaction.

Implementations§

source§

impl<'db, K, E> Transaction<'db, K, E>

source

pub fn txn(&self) -> TxnPtr

source

pub fn db(&self) -> &Database<E>

Returns a raw pointer to the MDBX database.

source

pub fn id(&self) -> u64

Returns the transaction id.

source

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.

source

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

Commits the transaction.

Any pending operations will be saved.

source

pub fn prime_for_permaopen(&self, table: Table<'_>)

source

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.

source

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.

source

pub fn table_flags<'txn>(&'txn self, table: &Table<'txn>) -> Result<TableFlags>

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

source

pub fn table_stat<'txn>(&'txn self, table: &Table<'txn>) -> Result<Stat>

Retrieves table statistics.

source

pub fn cursor<'txn>(&'txn self, table: &Table<'txn>) -> Result<Cursor<'txn, K>>

Open a new cursor on the given table.

source§

impl<'db, E> Transaction<'db, RW, E>
where E: DatabaseKind,

source

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.

source

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).

source

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.

source

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.

source

pub fn clear_table<'txn>(&'txn self, table: &Table<'txn>) -> Result<()>

Empties the given table. All items will be removed.

source

pub unsafe fn drop_table<'txn>(&'txn self, table: Table<'txn>) -> Result<()>

Drops the table from the database.

§Safety

Caller must close ALL other Table and Cursor instances pointing to the same dbi BEFORE calling this function.

source§

impl<'db, E> Transaction<'db, RO, E>
where E: DatabaseKind,

source

pub unsafe fn close_table(&self, table: Table<'_>) -> Result<()>

Closes the table handle.

§Safety

Caller must close ALL other Table and Cursor instances pointing to the same dbi BEFORE calling this function.

source§

impl<'db> Transaction<'db, RW, NoWriteMap>

source

pub fn begin_nested_txn(&mut self) -> Result<Transaction<'_, RW, NoWriteMap>>

Begins a new nested transaction inside of this transaction.

Trait Implementations§

source§

impl<'db, K, E> Debug for Transaction<'db, K, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'db, K, E> Drop for Transaction<'db, K, E>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'db, K, E> !Freeze for Transaction<'db, K, E>

§

impl<'db, K, E> !RefUnwindSafe for Transaction<'db, K, E>

§

impl<'db, K, E> Send for Transaction<'db, K, E>
where E: Sync,

§

impl<'db, K, E> Sync for Transaction<'db, K, E>
where E: Sync,

§

impl<'db, K, E> Unpin for Transaction<'db, K, E>

§

impl<'db, K, E> !UnwindSafe for Transaction<'db, K, E>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.