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>
impl<K: Key> Database<K>
Sourcepub fn open(name: &Path, options: Options) -> Result<Database<K>, Error>
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
.
Sourcepub fn open_with_comparator<C: Comparator<K = K>>(
name: &Path,
options: Options,
comparator: C,
) -> Result<Database<K>, Error>
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>
impl<K: Key> Batch<K> for Database<K>
Source§fn write(
&self,
options: WriteOptions,
batch: &Writebatch<K>,
) -> Result<(), Error>
fn write( &self, options: WriteOptions, batch: &Writebatch<K>, ) -> Result<(), Error>
Source§impl<'a, K: Key + 'a> Compaction<'a, K> for Database<K>
impl<'a, K: Key + 'a> Compaction<'a, K> for Database<K>
Source§impl<'a, K: Key + 'a> Iterable<'a, K> for Database<K>
impl<'a, K: Key + 'a> Iterable<'a, K> for Database<K>
Source§fn iter(&'a self, options: ReadOptions<'a, K>) -> Iterator<'_, K> ⓘ
fn iter(&'a self, options: ReadOptions<'a, K>) -> Iterator<'_, K> ⓘ
Source§fn keys_iter(&'a self, options: ReadOptions<'a, K>) -> KeyIterator<'_, K> ⓘ
fn keys_iter(&'a self, options: ReadOptions<'a, K>) -> KeyIterator<'_, K> ⓘ
Source§fn value_iter(&'a self, options: ReadOptions<'a, K>) -> ValueIterator<'_, K> ⓘ
fn value_iter(&'a self, options: ReadOptions<'a, K>) -> ValueIterator<'_, K> ⓘ
Source§impl<K: Key> KV<K> for Database<K>
impl<K: Key> KV<K> for Database<K>
Source§fn put<BK: Borrow<K>>(
&self,
options: WriteOptions,
key: BK,
value: &[u8],
) -> Result<(), Error>
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>
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.