Trait Database
pub trait Database:
Send
+ Sync
+ Debug {
type TX: DbTx + Sync + 'static;
type TXMut: DbTx + TableImporter + Sync + 'static;
// Required methods
fn tx(&self) -> Result<Self::TX, DatabaseError>;
fn tx_mut(&self) -> Result<Self::TXMut, DatabaseError>;
fn path(&self) -> PathBuf;
fn oldest_reader_txnid(&self) -> Option<u64>;
fn last_txnid(&self) -> Option<u64>;
// Provided methods
fn reader_check(&self) -> Result<(), DatabaseError> { ... }
fn view<T, F>(&self, f: F) -> Result<T, DatabaseError>
where F: FnOnce(&mut 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§
type TXMut: DbTx + TableImporter + Sync + 'static
type TXMut: DbTx + TableImporter + Sync + 'static
Read-Write database transaction
Required Methods§
fn tx(&self) -> Result<Self::TX, DatabaseError>
fn tx(&self) -> Result<Self::TX, DatabaseError>
Create read only transaction.
fn tx_mut(&self) -> Result<Self::TXMut, DatabaseError>
fn tx_mut(&self) -> Result<Self::TXMut, DatabaseError>
Create read write transaction only possible if database is open with write access.
fn oldest_reader_txnid(&self) -> Option<u64>
fn oldest_reader_txnid(&self) -> Option<u64>
Returns the transaction ID of the oldest active reader, if available.
This is the committed txnid of the snapshot the reader is pinned to, not a unique per-reader identifier, so multiple readers can report the same txnid.
Used to check whether stale readers from a previous write transaction have completed.
Returns None if no readers are active or the backend does not support this query.
fn last_txnid(&self) -> Option<u64>
fn last_txnid(&self) -> Option<u64>
Returns the ID of the most recently committed transaction, if available.
Provided Methods§
fn reader_check(&self) -> Result<(), DatabaseError>
fn reader_check(&self) -> Result<(), DatabaseError>
Clears reader slots left behind by processes that no longer exist, so they stop counting
towards Self::oldest_reader_txnid.
MDBX skips slots carrying this process’s own PID, so a stale slot left by a dead process whose PID was reused by this one is not cleared.
Does nothing by default, for backends without such slots.
fn view<T, F>(&self, f: F) -> Result<T, DatabaseError>
fn view<T, F>(&self, f: F) -> Result<T, DatabaseError>
Takes a function and passes a read-only transaction into it, making sure it’s closed in the end of the execution.
fn update<T, F>(&self, f: F) -> Result<T, DatabaseError>
fn update<T, F>(&self, f: F) -> Result<T, DatabaseError>
Takes a function and passes a write-read transaction into it, making sure it’s committed in the end of the execution.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
§impl<DB> Database for &DBwhere
DB: Database,
impl<DB> Database for &DBwhere
DB: Database,
type TX = <DB as Database>::TX
type TXMut = <DB as Database>::TXMut
fn tx(&self) -> Result<<&DB as Database>::TX, DatabaseError>
fn tx_mut(&self) -> Result<<&DB as Database>::TXMut, DatabaseError>
fn path(&self) -> PathBuf
fn oldest_reader_txnid(&self) -> Option<u64>
fn last_txnid(&self) -> Option<u64>
fn reader_check(&self) -> Result<(), DatabaseError>
§impl<DB> Database for Arc<DB>where
DB: Database,
impl<DB> Database for Arc<DB>where
DB: Database,
type TX = <DB as Database>::TX
type TXMut = <DB as Database>::TXMut
fn tx(&self) -> Result<<Arc<DB> as Database>::TX, DatabaseError>
fn tx_mut(&self) -> Result<<Arc<DB> as Database>::TXMut, DatabaseError>
fn path(&self) -> PathBuf
fn oldest_reader_txnid(&self) -> Option<u64>
fn last_txnid(&self) -> Option<u64>
fn reader_check(&self) -> Result<(), DatabaseError>
Implementors§
Source§impl Database for DatabaseEnv
Available on crate feature mdbx only.
impl Database for DatabaseEnv
mdbx only.