[][src]Struct megadex_rkv::MegadexDb

pub struct MegadexDb<T> { /* fields omitted */ }

A specialized database table that is persisted to the provided directory. This will store structs which implement Serialize and DeserializeOwned. It will also index those structs by any additional fields that you specify.

This is a sparse and rather specialized API as it is intended to be used with the megadex_derive crate.

Methods

impl<T> MegadexDb<T> where
    T: Serialize + DeserializeOwned
[src]

pub fn new(db: Db, fields: &[&str]) -> Result<Self, MegadexDbError>
[src]

pub fn get_env(&self) -> Arc<RwLock<Rkv>>
[src]

Fetch a handle to the underlying LMDB environment

pub fn get<K: Serialize>(&self, id: &K) -> Result<Option<T>, MegadexDbError>
[src]

Retrieve T from the database at the given id. Returns None if there is no value present for the id

pub fn get_by_field<K: Serialize>(
    &self,
    name: &str,
    key: &K
) -> Result<Vec<T>, MegadexDbError>
[src]

Retrieve all objects that are indexed by the provided field TODO This is ugly.. find a good way to refactor the handling of iterators of results of options of values

pub fn get_ids_by_field<'s, K, I, Txn>(
    &self,
    reader: &Txn,
    name: &str,
    key: &'s K
) -> Result<Vec<I>, MegadexDbError> where
    K: Serialize,
    I: DeserializeOwned,
    Txn: Transaction
[src]

Retrieve the exact type of ids that are indexed by the provided field XXX Note that this will basically swallow deserialization and mismatchd type errors by simpling excluding the result from the vector if it fails

pub fn get_ids_by_field_raw<'s, Txn: Transaction>(
    &self,
    reader: &'s Txn,
    name: &str,
    key: &'s [u8]
) -> Result<Option<MdIter<'s>>, MegadexDbError>
[src]

Retrieve an iterator for the raw bytes of ids that are indexed by the provided field

pub fn put<K: Serialize>(
    &mut self,
    id: &K,
    obj: &T,
    fields: &[(&str, &K)]
) -> Result<(), MegadexDbError>
[src]

Store an object of type T indexed by id

pub fn del<K: Serialize>(
    &mut self,
    id: &K,
    fields: &[(&str, &K)]
) -> Result<(), MegadexDbError>
[src]

Delete an object and all of its indexed fields. Note that the obj, T must be in the exact state in which it was put into the DB for it to be successfully deleted.

Auto Trait Implementations

impl<T> Send for MegadexDb<T> where
    T: Send

impl<T> Sync for MegadexDb<T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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