Skip to main content

DbTx

Trait DbTx 

pub trait DbTx: Debug + Send {
    type Cursor<T: Table>: DbCursorRO<T> + Send;
    type DupCursor<T: DupSort>: DbDupCursorRO<T> + DbCursorRO<T> + Send;

    // Required methods
    fn get<T>(
        &self,
        key: <T as Table>::Key,
    ) -> Result<Option<<T as Table>::Value>, DatabaseError>
       where T: Table;
    fn get_by_encoded_key<T>(
        &self,
        key: &<<T as Table>::Key as Encode>::Encoded,
    ) -> Result<Option<<T as Table>::Value>, DatabaseError>
       where T: Table;
    fn commit(self) -> Result<(), DatabaseError>;
    fn abort(self);
    fn cursor_read<T>(&self) -> Result<Self::Cursor<T>, DatabaseError>
       where T: Table;
    fn cursor_dup_read<T>(&self) -> Result<Self::DupCursor<T>, DatabaseError>
       where T: DupSort;
    fn entries<T>(&self) -> Result<usize, DatabaseError>
       where T: Table;
    fn disable_long_read_transaction_safety(&mut self);

    // Provided methods
    fn commit_durable(self) -> Result<(), DatabaseError>
       where Self: Sized { ... }
    fn prefetch(&self, _enabled: bool) -> &Self { ... }
}
Expand description

Read only transaction

Required Associated Types§

type Cursor<T: Table>: DbCursorRO<T> + Send

Cursor type for this read-only transaction

type DupCursor<T: DupSort>: DbDupCursorRO<T> + DbCursorRO<T> + Send

DupCursor type for this read-only transaction

Required Methods§

fn get<T>( &self, key: <T as Table>::Key, ) -> Result<Option<<T as Table>::Value>, DatabaseError>
where T: Table,

Get value by an owned key

fn get_by_encoded_key<T>( &self, key: &<<T as Table>::Key as Encode>::Encoded, ) -> Result<Option<<T as Table>::Value>, DatabaseError>
where T: Table,

Get value by a reference to the encoded key, especially useful for “raw” keys that encode to themselves like Address and B256. Doesn’t need to clone a reference key like get.

fn commit(self) -> Result<(), DatabaseError>

Commit for read only transaction will consume and free transaction and allows freeing of memory pages

fn abort(self)

Aborts transaction

fn cursor_read<T>(&self) -> Result<Self::Cursor<T>, DatabaseError>
where T: Table,

Iterate over read only values in table.

fn cursor_dup_read<T>(&self) -> Result<Self::DupCursor<T>, DatabaseError>
where T: DupSort,

Iterate over read only values in dup sorted table.

fn entries<T>(&self) -> Result<usize, DatabaseError>
where T: Table,

Returns number of entries in the table.

fn disable_long_read_transaction_safety(&mut self)

Disables long-lived read transaction safety guarantees.

Provided Methods§

fn commit_durable(self) -> Result<(), DatabaseError>
where Self: Sized,

Commits the transaction and returns once the commit is durable on disk.

The default calls DbTx::commit; backends with weak commits must override it. An error after a successful commit means the commit may be visible but not durable.

fn prefetch(&self, _enabled: bool) -> &Self

Enables or disables best-effort read-ahead for this transaction.

Defaults to disabled and persists across operations until explicitly changed. Applies to gets in every table. New read and write cursors inherit the setting; existing cursors keep their own setting, configurable with DbCursorRO::prefetch. Returns the transaction for chaining. Backends without support ignore the setting.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl DbTx for TxMock

Source§

impl<K: TransactionKind> DbTx for Tx<K>

Available on crate feature mdbx only.
Source§

type Cursor<T: Table> = Cursor<K, T>

Source§

type DupCursor<T: DupSort> = Cursor<K, T>