Struct Database

Source
pub struct Database<K: Key> { /* private fields */ }
Expand description

The main database object.

leveldb databases are based on ordered keys. By default, leveldb orders by the binary value of the key. Additionally, a custom Comparator can be passed when opening the database. This library ships with an Comparator implementation for keys that are Ord.

When re-CString a database, you must use the same key type K and comparator type C.

Multiple Database objects can be kept around, as leveldb synchronises internally.

Implementations§

Source§

impl<K: Key> Database<K>

Source

pub fn open(name: &Path, options: Options) -> Result<Database<K>, Error>

Open a new database

If the database is missing, the behaviour depends on options.create_if_missing. The database will be created using the settings given in options.

Source

pub fn open_with_comparator<C: Comparator<K = K>>( name: &Path, options: Options, comparator: C, ) -> Result<Database<K>, Error>

Open a new database with a custom comparator

If the database is missing, the behaviour depends on options.create_if_missing. The database will be created using the settings given in options.

The comparator must implement a total ordering over the keyspace.

For keys that implement Ord, consider the OrdComparator.

Trait Implementations§

Source§

impl<K: Key> Batch<K> for Database<K>

Source§

fn write( &self, options: WriteOptions, batch: &Writebatch<K>, ) -> Result<(), Error>

Write a batch to the database, ensuring success for all items or an error
Source§

impl<'a, K: Key + 'a> Compaction<'a, K> for Database<K>

Source§

fn compact(&self, start: &'a K, limit: &'a K)

Source§

impl<'a, K: Key + 'a> Iterable<'a, K> for Database<K>

Source§

fn iter(&'a self, options: ReadOptions<'a, K>) -> Iterator<'_, K>

Return an Iterator iterating over (Key,Value) pairs
Source§

fn keys_iter(&'a self, options: ReadOptions<'a, K>) -> KeyIterator<'_, K>

Returns an Iterator iterating over Keys only.
Source§

fn value_iter(&'a self, options: ReadOptions<'a, K>) -> ValueIterator<'_, K>

Returns an Iterator iterating over Values only.
Source§

impl<K: Key> KV<K> for Database<K>

Source§

fn put<BK: Borrow<K>>( &self, options: WriteOptions, key: BK, value: &[u8], ) -> Result<(), Error>

put a binary value into the database.

If the key is already present in the database, it will be overwritten.

The passed key will be compared using the comparator.

The database will be synced to disc if options.sync == true. This is NOT the default.

Source§

fn delete<BK: Borrow<K>>( &self, options: WriteOptions, key: BK, ) -> Result<(), Error>

delete a value from the database.

The passed key will be compared using the comparator.

The database will be synced to disc if options.sync == true. This is NOT the default.

Source§

fn get_bytes<'a, BK: Borrow<K>>( &self, options: ReadOptions<'a, K>, key: BK, ) -> Result<Option<Bytes>, Error>

get a value from the database. Read more
Source§

fn get<'a, BK: Borrow<K>>( &self, options: ReadOptions<'a, K>, key: BK, ) -> Result<Option<Vec<u8>>, Error>

get a value from the database. Read more
Source§

impl<K: Key> Snapshots<K> for Database<K>

Source§

fn snapshot<'a>(&'a self) -> Snapshot<'a, K>

Creates a snapshot and returns a struct representing it.
Source§

impl<K: Key> Send for Database<K>

Source§

impl<K: Key> Sync for Database<K>

Auto Trait Implementations§

§

impl<K> Freeze for Database<K>

§

impl<K> RefUnwindSafe for Database<K>
where K: RefUnwindSafe,

§

impl<K> Unpin for Database<K>
where K: Unpin,

§

impl<K> UnwindSafe for Database<K>
where K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.