pub struct Database { /* private fields */ }
Expand description
GrebeDB database interface.
Implementations§
Source§impl Database
impl Database
Sourcepub fn open(
vfs: Box<dyn Vfs + Sync + Send>,
options: Options,
) -> Result<Self, Error>
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.
Sourcepub fn open_memory(options: Options) -> Result<Self, Error>
pub fn open_memory(options: Options) -> Result<Self, Error>
Open a database in temporary memory.
Sourcepub fn open_path<P>(root_path: P, options: Options) -> Result<Self, Error>
pub fn open_path<P>(root_path: P, options: Options) -> Result<Self, Error>
Open a database to a path on the disk.
The path must be a directory.
Sourcepub fn contains_key<K>(&mut self, key: K) -> Result<bool, Error>
pub fn contains_key<K>(&mut self, key: K) -> Result<bool, Error>
Return whether the key exists.
Sourcepub fn get<K>(&mut self, key: K) -> Result<Option<Vec<u8>>, Error>
pub fn get<K>(&mut self, key: K) -> Result<Option<Vec<u8>>, Error>
Retrieve a stored value, by its key, as a vector.
Sourcepub fn get_buf<K>(
&mut self,
key: K,
value_destination: &mut Vec<u8>,
) -> Result<bool, Error>
pub fn get_buf<K>( &mut self, key: K, value_destination: &mut Vec<u8>, ) -> Result<bool, Error>
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.
Sourcepub fn remove<K>(&mut self, key: K) -> Result<(), Error>
pub fn remove<K>(&mut self, key: K) -> Result<(), Error>
Remove a key-value pair by its key.
No error occurs if the key does not exist.
Sourcepub fn cursor(&mut self) -> Result<Cursor<'_>, Error>
pub fn cursor(&mut self) -> Result<Cursor<'_>, Error>
Return a cursor for iterating all the key-value pairs.
Sourcepub fn cursor_range<K, R>(&mut self, range: R) -> Result<Cursor<'_>, Error>
pub fn cursor_range<K, R>(&mut self, range: R) -> Result<Cursor<'_>, Error>
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()
Sourcepub fn flush(&mut self) -> Result<(), Error>
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
.
Sourcepub fn verify<P>(&mut self, progress_callback: P) -> Result<(), Error>
pub fn verify<P>(&mut self, progress_callback: P) -> Result<(), Error>
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.
Sourcepub fn debug_print_tree(&mut self) -> Result<(), Error>
pub fn debug_print_tree(&mut self) -> Result<(), Error>
Print the tree for debugging purposes.