pub struct Database { /* private fields */ }Expand description
The main database structure This struct can be accessed concurrently and you should never instantiate it more than once for the same on-disk files
Implementations§
Source§impl Database
impl Database
Sourcepub async fn new(mode: StartMode) -> Result<Self, Error>
pub async fn new(mode: StartMode) -> Result<Self, Error>
Create a new database instance with default parameters
Sourcepub async fn new_with_params(
mode: StartMode,
params: Params,
) -> Result<Self, Error>
pub async fn new_with_params( mode: StartMode, params: Params, ) -> Result<Self, Error>
Create a new database instance with specific parameters
Sourcepub async fn get(&self, key: &[u8]) -> Result<Option<EntryRef>, Error>
pub async fn get(&self, key: &[u8]) -> Result<Option<EntryRef>, Error>
Will deserialize V from the raw data (avoids an additional data copy)
Sourcepub async fn delete(&self, key: Key) -> Result<(), Error>
pub async fn delete(&self, key: Key) -> Result<(), Error>
Delete an existing entry For efficiency, the datastore does not check whether the key actually existed Instead, it will just mark the most recent version (which could be the first one) as deleted
Sourcepub async fn synchronize(&self) -> Result<(), Error>
pub async fn synchronize(&self) -> Result<(), Error>
Ensure all data is written to disk Only has an effect if there were previous writes with sync=false
Sourcepub async fn delete_opts(
&self,
key: Key,
opts: &WriteOptions,
) -> Result<(), Error>
pub async fn delete_opts( &self, key: Key, opts: &WriteOptions, ) -> Result<(), Error>
Delete an existing entry (with additional options)
Sourcepub async fn put(&self, key: Key, value: Value) -> Result<(), Error>
pub async fn put(&self, key: Key, value: Value) -> Result<(), Error>
Insert or update a single entry
Sourcepub async fn put_opts(
&self,
key: Key,
value: Value,
opts: &WriteOptions,
) -> Result<(), Error>
pub async fn put_opts( &self, key: Key, value: Value, opts: &WriteOptions, ) -> Result<(), Error>
Insert or update a single entry (with additional options)
Sourcepub async fn iter(&self) -> DbIterator
pub async fn iter(&self) -> DbIterator
Iterate over all entries in the database
Sourcepub async fn range_iter(&self, min_key: &[u8], max_key: &[u8]) -> DbIterator
pub async fn range_iter(&self, min_key: &[u8], max_key: &[u8]) -> DbIterator
Like iter(), but will only include entries with keys in [min_key;max_key)
Sourcepub async fn reverse_range_iter(
&self,
max_key: &[u8],
min_key: &[u8],
) -> DbIterator
pub async fn reverse_range_iter( &self, max_key: &[u8], min_key: &[u8], ) -> DbIterator
Like range_iter(), but in reverse. It will only include entries with keys in (min_key;max_key]
Sourcepub async fn write(&self, write_batch: WriteBatch) -> Result<(), Error>
pub async fn write(&self, write_batch: WriteBatch) -> Result<(), Error>
Write a batch of updates to the database
If you only want to write to a single key, use Database::put instead
Sourcepub async fn write_opts(
&self,
write_batch: WriteBatch,
opts: &WriteOptions,
) -> Result<(), Error>
pub async fn write_opts( &self, write_batch: WriteBatch, opts: &WriteOptions, ) -> Result<(), Error>
Write a batch of updates to the database This version of write allows you to specify options such as “synchronous”