Trait reth_db::Database

source ·
pub trait Database: Send + Sync {
    type TX: DbTx + Send + Sync + Debug + 'static;
    type TXMut: DbTxMut + DbTx + TableImporter + Send + Sync + Debug + 'static;

    // Required methods
    fn tx(&self) -> Result<Self::TX, DatabaseError>;
    fn tx_mut(&self) -> Result<Self::TXMut, DatabaseError>;

    // Provided methods
    fn view<T, F>(&self, f: F) -> Result<T, DatabaseError>
       where F: FnOnce(&Self::TX) -> T { ... }
    fn update<T, F>(&self, f: F) -> Result<T, DatabaseError>
       where F: FnOnce(&Self::TXMut) -> T { ... }
}
Expand description

Main Database trait that can open read-only and read-write transactions.

Sealed trait which cannot be implemented by 3rd parties, exposed only for consumption.

Required Associated Types§

source

type TX: DbTx + Send + Sync + Debug + 'static

Read-Only database transaction

source

type TXMut: DbTxMut + DbTx + TableImporter + Send + Sync + Debug + 'static

Read-Write database transaction

Required Methods§

source

fn tx(&self) -> Result<Self::TX, DatabaseError>

Create read only transaction.

source

fn tx_mut(&self) -> Result<Self::TXMut, DatabaseError>

Create read write transaction only possible if database is open with write access.

Provided Methods§

source

fn view<T, F>(&self, f: F) -> Result<T, DatabaseError>
where F: FnOnce(&Self::TX) -> T,

Takes a function and passes a read-only transaction into it, making sure it’s closed in the end of the execution.

source

fn update<T, F>(&self, f: F) -> Result<T, DatabaseError>
where F: FnOnce(&Self::TXMut) -> T,

Takes a function and passes a write-read transaction into it, making sure it’s committed in the end of the execution.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<DB> Database for &DB
where DB: Database,

§

type TX = <DB as Database>::TX

§

type TXMut = <DB as Database>::TXMut

source§

fn tx(&self) -> Result<<&DB as Database>::TX, DatabaseError>

source§

fn tx_mut(&self) -> Result<<&DB as Database>::TXMut, DatabaseError>

source§

impl<DB> Database for Arc<DB>
where DB: Database,

§

type TX = <DB as Database>::TX

§

type TXMut = <DB as Database>::TXMut

source§

fn tx(&self) -> Result<<Arc<DB> as Database>::TX, DatabaseError>

source§

fn tx_mut(&self) -> Result<<Arc<DB> as Database>::TXMut, DatabaseError>

Implementors§

source§

impl Database for DatabaseEnv

Available on crate feature mdbx only.
§

type TX = Tx<RO>

§

type TXMut = Tx<RW>

source§

impl Database for DatabaseMock

§

type TX = TxMock

§

type TXMut = TxMock

source§

impl<DB: Database> Database for TempDatabase<DB>

Available on crate feature test-utils only.
§

type TX = <DB as Database>::TX

§

type TXMut = <DB as Database>::TXMut