Struct sled_overlay::SledDbOverlay
source · pub struct SledDbOverlay { /* private fields */ }Expand description
An overlay on top of an entire sled::Db which can span multiple trees
Implementations§
source§impl SledDbOverlay
impl SledDbOverlay
sourcepub fn new(db: &Db) -> Self
pub fn new(db: &Db) -> Self
Instantiate a new SledDbOverlay on top of a given sled::Db.
sourcepub fn open_tree(&mut self, tree_name: &[u8]) -> Result<(), Error>
pub fn open_tree(&mut self, tree_name: &[u8]) -> Result<(), Error>
Create a new SledTreeOverlay on top of a given tree_name.
This function will also open a new tree inside db regardless of if it has
existed before, so for convenience, we also provide SledDbOverlay::purge_new_trees
in case we decide we don’t want to write the batches, and drop the new trees.
sourcepub fn purge_new_trees(&self) -> Result<(), Error>
pub fn purge_new_trees(&self) -> Result<(), Error>
Drop newly created trees from the sled database. This is a convenience function that should be used when we decide that we don’t want to apply any cache changes, and we want to revert back to the initial state.
sourcepub fn contains_key(&self, tree_key: &[u8], key: &[u8]) -> Result<bool, Error>
pub fn contains_key(&self, tree_key: &[u8], key: &[u8]) -> Result<bool, Error>
Returns true if the overlay contains a value for a specified key in the specified
tree cache.
sourcepub fn get(&self, tree_key: &[u8], key: &[u8]) -> Result<Option<IVec>, Error>
pub fn get(&self, tree_key: &[u8], key: &[u8]) -> Result<Option<IVec>, Error>
Retrieve a value from the overlay if it exists in the specified tree cache.
sourcepub fn insert(
&mut self,
tree_key: &[u8],
key: &[u8],
value: &[u8]
) -> Result<Option<IVec>, Error>
pub fn insert( &mut self, tree_key: &[u8], key: &[u8], value: &[u8] ) -> Result<Option<IVec>, Error>
Insert a key to a new value in the specified tree cache, returning the last value if it was set.
sourcepub fn remove(
&mut self,
tree_key: &[u8],
key: &[u8]
) -> Result<Option<IVec>, Error>
pub fn remove( &mut self, tree_key: &[u8], key: &[u8] ) -> Result<Option<IVec>, Error>
Delete a value in the specified tree cache, returning the old value if it existed.
sourcepub fn aggregate(&self) -> Result<(Vec<Tree>, Vec<Batch>), Error>
pub fn aggregate(&self) -> Result<(Vec<Tree>, Vec<Batch>), Error>
Aggregate all the current overlay changes into sled::Batch instances and
return vectors of sled::Tree and their respective sled::Batch that can
be used for further operations. If there are no changes, both vectors will be empty.