[][src]Struct tari_storage::lmdb_store::LMDBDatabase

pub struct LMDBDatabase { /* fields omitted */ }

Implementations

impl LMDBDatabase[src]

pub fn insert<K: ?Sized, V>(&self, key: &K, value: &V) -> Result<(), LMDBError> where
    K: AsLmdbBytes,
    V: Serialize
[src]

Inserts a record into the database. This is an atomic operation. Internally, insert creates a new write transaction, writes the value, and then commits the transaction.

pub fn get<K: ?Sized, V>(&self, key: &K) -> Result<Option<V>, LMDBError> where
    K: AsLmdbBytes,
    V: DeserializeOwned
[src]

Get a value from the database. This is an atomic operation. A read transaction is created, the value extracted, copied and converted to V before closing the transaction. A copy is unavoidable because the extracted byte string is released when the transaction is closed. If you are doing many gets, it is more efficient to use with_read_transaction

pub fn get_stats(&self) -> Result<Stat, LMDBError>[src]

Return statistics about the database, See Stat for more details.

pub fn log_info(&self)[src]

Log some pretty printed stats.See Stat for more details.

pub fn is_empty(&self) -> Result<bool, LMDBError>[src]

Returns if the database is empty.

pub fn len(&self) -> Result<usize, LMDBError>[src]

Returns the total number of entries in this database.

pub fn for_each<K, V, F>(&self, mut f: F) -> Result<(), LMDBError> where
    K: DeserializeOwned,
    V: DeserializeOwned,
    F: FnMut(Result<(K, V), KeyValStoreError>) -> IterationResult
[src]

Execute function f for each value in the database.

The underlying LMDB library does not permit database cursors to be returned from functions to preserve Rust memory guarantees, so this is the closest thing to an iterator that you're going to get :/

f is a closure of form |pair: Result<(K,V), LMDBError>| -> IterationResult. If IterationResult::Break is returned the closure will not be called again and for_each will return. You will usually need to include type inference to let Rust know which type to deserialise to:

   let res = db.for_each::<Key, User, _>(|pair| {
       let (key, user) = pair.unwrap();
       //.. do stuff with key and user..
   });

pub fn contains_key<K: ?Sized>(&self, key: &K) -> Result<bool, LMDBError> where
    K: AsLmdbBytes
[src]

Checks whether a key exists in this database

pub fn remove<K: ?Sized>(&self, key: &K) -> Result<(), LMDBError> where
    K: AsLmdbBytes
[src]

Delete a record associated with key from the database. If the key is not found,

pub fn with_read_transaction<F, V>(
    &self,
    f: F
) -> Result<Option<Vec<V>>, LMDBError> where
    V: DeserializeOwned,
    F: FnOnce(LMDBReadTransaction<'_, '_>) -> Result<Option<Vec<V>>, LMDBError>, 
[src]

Create a read-only transaction on the current database and execute the instructions given in the closure. The transaction is automatically committed when the closure goes out of scope. You may provide the results of the transaction to the calling scope by populating a Vec<V> with the results of txn.get(k). Otherwise, if the results are not needed, or you did not call get, just return Ok(None).

pub fn with_write_transaction<F>(&self, f: F) -> Result<(), LMDBError> where
    F: FnOnce(LMDBWriteTransaction<'_, '_>) -> Result<(), LMDBError>, 
[src]

Create a transaction with write access on the current table.

pub fn db(&self) -> Arc<Database<'static>>[src]

Returns an owned atomic reference to the database

Trait Implementations

impl Clone for LMDBDatabase[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<'a, T> DefaultFeatures<'a> for T where
    T: 'a + Clone + Send + Sync

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<'a, T> NonSyncFeatures<'a> for T where
    T: 'a + Clone

impl<T> SafeBorrow<T> for T where
    T: ?Sized

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,