Struct Database

Source
pub struct Database { /* private fields */ }
Expand description

GrebeDB database interface.

Implementations§

Source§

impl Database

Source

pub fn open( vfs: Box<dyn Vfs + Sync + Send>, options: Options, ) -> Result<Self, Error>

Open a database using the given virtual file system and options.

Source

pub fn open_memory(options: Options) -> Result<Self, Error>

Open a database in temporary memory.

Source

pub fn open_path<P>(root_path: P, options: Options) -> Result<Self, Error>
where P: Into<PathBuf>,

Open a database to a path on the disk.

The path must be a directory.

Source

pub fn metadata(&self) -> Metadata<'_>

Return database metadata information.

Source

pub fn contains_key<K>(&mut self, key: K) -> Result<bool, Error>
where K: AsRef<[u8]>,

Return whether the key exists.

Source

pub fn get<K>(&mut self, key: K) -> Result<Option<Vec<u8>>, Error>
where K: AsRef<[u8]>,

Retrieve a stored value, by its key, as a vector.

Source

pub fn get_buf<K>( &mut self, key: K, value_destination: &mut Vec<u8>, ) -> Result<bool, Error>
where K: AsRef<[u8]>,

Retrieve a stored value, by its key, into the given buffer.

Returns true if the key-value pair was found. The vector will be cleared and resized.

Source

pub fn put<K, V>(&mut self, key: K, value: V) -> Result<(), Error>
where K: Into<Vec<u8>>, V: Into<Vec<u8>>,

Store a key-value pair.

Source

pub fn remove<K>(&mut self, key: K) -> Result<(), Error>
where K: AsRef<[u8]>,

Remove a key-value pair by its key.

No error occurs if the key does not exist.

Source

pub fn cursor(&mut self) -> Result<Cursor<'_>, Error>

Return a cursor for iterating all the key-value pairs.

Source

pub fn cursor_range<K, R>(&mut self, range: R) -> Result<Cursor<'_>, Error>
where K: AsRef<[u8]>, R: RangeBounds<K>,

Return a cursor for iterating all the key-value pairs within the given range.

This method is equivalent of obtaining a cursor and calling Cursor::seek() and Cursor::set_range()

Source

pub fn flush(&mut self) -> Result<(), Error>

Persist all modifications to the file system.

Calling this function ensures that all changes pending, whether cached in memory or in files, are atomically saved on the file system before this function returns. If the database is not flushed when dropped or the program exits, changes since the last successful flush will be discarded. This function effectively emulates a transaction.

For details about automatic flushing, see Options.

Source

pub fn verify<P>(&mut self, progress_callback: P) -> Result<(), Error>
where P: FnMut(usize, usize),

Check the database for internal consistency and data integrity.

The provided callback function is called with the number of items processed and the estimated number of items.

The function returns an error on the first verification failure or other error.

Source

pub fn debug_print_tree(&mut self) -> Result<(), Error>

Print the tree for debugging purposes.

Trait Implementations§

Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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, 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.