pub struct Hyperbee { /* private fields */ }Expand description
An append only B-Tree built on Hypercore. It provides a key-value
store API, with methods for inserting, getting, and
deleting key-value pair. As well as creating sorted
iterators, and “sub” B-Trees for grouping related data.
Implementations§
Source§impl Hyperbee
impl Hyperbee
Sourcepub async fn version(&self) -> u64
pub async fn version(&self) -> u64
The number of blocks in the hypercore.
The first block is always the header block so:
version would be the seq of the next block
version - 1 is most recent block
Sourcepub async fn create_header(
&self,
metadata: Option<Metadata>,
) -> Result<AppendOutcome, HyperbeeError>
pub async fn create_header( &self, metadata: Option<Metadata>, ) -> Result<AppendOutcome, HyperbeeError>
Create the header for the Hyperbee. This must be done before writing anything else to the tree.
Sourcepub async fn get(
&self,
key: &[u8],
) -> Result<Option<(u64, Option<Vec<u8>>)>, HyperbeeError>
pub async fn get( &self, key: &[u8], ) -> Result<Option<(u64, Option<Vec<u8>>)>, HyperbeeError>
Get the value corresponding to the provided key from the Hyperbee
§Errors
When Hyperbee.get_root fails
Sourcepub async fn put(
&self,
key: &[u8],
value: Option<&[u8]>,
) -> Result<(Option<u64>, u64), HyperbeeError>
pub async fn put( &self, key: &[u8], value: Option<&[u8]>, ) -> Result<(Option<u64>, u64), HyperbeeError>
Insert the given key and value into the tree
Returs the seq of the new key, and Option<u64> which contains the seq of the old key
if it was replaced.
Sourcepub async fn put_compare_and_swap(
&self,
key: &[u8],
value: Option<&[u8]>,
cas: impl FnOnce(Option<&KeyValueData>, &KeyValueData) -> bool,
) -> Result<(Option<u64>, Option<u64>), HyperbeeError>
pub async fn put_compare_and_swap( &self, key: &[u8], value: Option<&[u8]>, cas: impl FnOnce(Option<&KeyValueData>, &KeyValueData) -> bool, ) -> Result<(Option<u64>, Option<u64>), HyperbeeError>
Like Hyperbee::put but takes a compare_and_swap function.
The compared_and_swap function is called with the old key (if present), and the new key.
The new key is only inserted if compare_and_swap returns true.
Returs two Option<u64>s. The first is the old key, the second is the new key.
Sourcepub async fn del(&self, key: &[u8]) -> Result<Option<u64>, HyperbeeError>
pub async fn del(&self, key: &[u8]) -> Result<Option<u64>, HyperbeeError>
Delete the given key from the tree.
Returns the seq from the key if it was deleted.
Sourcepub async fn del_compare_and_swap(
&self,
key: &[u8],
cas: impl FnOnce(&KeyValueData) -> bool,
) -> Result<Option<(bool, u64)>, HyperbeeError>
pub async fn del_compare_and_swap( &self, key: &[u8], cas: impl FnOnce(&KeyValueData) -> bool, ) -> Result<Option<(bool, u64)>, HyperbeeError>
Like Hyperbee::del but takes a compare_and_swap function.
Before deleting the function is called with existing key’s KeyValueData.
The key is only deleted if compare_and_swap returs true.
Returns the bool representing the result of compare_and_swap, and the seq for the
key.
Sourcepub fn sub(&self, prefix: &[u8], config: PrefixedConfig) -> Prefixed
pub fn sub(&self, prefix: &[u8], config: PrefixedConfig) -> Prefixed
Create a new tree with all it’s operation’s prefixed by the provided prefix.
Sourcepub async fn traverse<'a>(
&self,
conf: TraverseConfig,
) -> Result<impl Stream<Item = KeyDataResult> + 'a, HyperbeeError>
pub async fn traverse<'a>( &self, conf: TraverseConfig, ) -> Result<impl Stream<Item = KeyDataResult> + 'a, HyperbeeError>
Traverse the tree based on the given TraverseConfig