Struct Database

Source
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

Source

pub async fn new(mode: StartMode) -> Result<Self, Error>

Create a new database instance with default parameters

Source

pub async fn new_with_params( mode: StartMode, params: Params, ) -> Result<Self, Error>

Create a new database instance with specific parameters

Source

pub async fn get(&self, key: &[u8]) -> Result<Option<EntryRef>, Error>

Will deserialize V from the raw data (avoids an additional data copy)

Source

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

Source

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

Source

pub async fn delete_opts( &self, key: Key, opts: &WriteOptions, ) -> Result<(), Error>

Delete an existing entry (with additional options)

Source

pub async fn put(&self, key: Key, value: Value) -> Result<(), Error>

Insert or update a single entry

Source

pub async fn put_opts( &self, key: Key, value: Value, opts: &WriteOptions, ) -> Result<(), Error>

Insert or update a single entry (with additional options)

Source

pub async fn iter(&self) -> DbIterator

Iterate over all entries in the database

Source

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)

Source

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]

Source

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

Source

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”

Source

pub async fn stop(&self) -> Result<(), Error>

Stop all background tasks gracefully

Trait Implementations§

Source§

impl Drop for Database

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more