Struct leveldb::database::Database [-] [+] [src]

pub struct Database<K: Key> {
    // some fields omitted
}

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-opening 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.

Methods

impl<K: Key> Database<K>

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.

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

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

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

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

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

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

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

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

fn put(&self, options: WriteOptions, key: K, 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.

fn delete(&self, options: WriteOptions, key: K) -> 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.

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

get a value from the database.

The passed key will be compared using the comparator.

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

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