pub struct SphereDb<S>where
S: Storage,{ /* private fields */ }Expand description
A SphereDb is a high-level storage primitive for Noosphere’s APIs. It takes a Storage and implements BlockStore and KeyValueStore, orchestrating writes so that as blocks are stored, links are also extracted and tracked separately, and also hosting metadata information such as sphere version records and other purely local configuration
Implementations§
Source§impl<S> SphereDb<S>where
S: Storage,
impl<S> SphereDb<S>where
S: Storage,
pub async fn new(storage: &S) -> Result<SphereDb<S>>
Sourcepub async fn persist(&mut self, memory_store: &MemoryStore) -> Result<()>
pub async fn persist(&mut self, memory_store: &MemoryStore) -> Result<()>
Given a MemoryStore, store copies of all the blocks found within in the storage that backs this SphereDb.
Sourcepub async fn set_version(&mut self, identity: &str, version: &Cid) -> Result<()>
pub async fn set_version(&mut self, identity: &str, version: &Cid) -> Result<()>
Record the tip of a local sphere lineage as a Cid
Sourcepub async fn get_version(&self, identity: &str) -> Result<Option<Cid>>
pub async fn get_version(&self, identity: &str) -> Result<Option<Cid>>
Get the most recently recorded tip of a local sphere lineage
Sourcepub async fn flush(&self) -> Result<()>
pub async fn flush(&self) -> Result<()>
Manually flush all pending writes to the underlying Storage
Sourcepub async fn require_version(&self, identity: &str) -> Result<Cid>
pub async fn require_version(&self, identity: &str) -> Result<Cid>
Get the most recently recorded tip of a local sphere lineage, returning an error if no version has ever been recorded
Sourcepub async fn get_block_links(&self, cid: &Cid) -> Result<Option<Vec<Cid>>>
pub async fn get_block_links(&self, cid: &Cid) -> Result<Option<Vec<Cid>>>
Get all links referenced by a block given its Cid
Sourcepub fn query_links<'a, F, P>(
&'a self,
cid: &'a Cid,
predicate: P,
) -> impl Stream<Item = Result<Cid>> + 'a
pub fn query_links<'a, F, P>( &'a self, cid: &'a Cid, predicate: P, ) -> impl Stream<Item = Result<Cid>> + 'a
Given a Cid root and a predicate function, stream all links that are referenced by the root or its descendants (recursively). The predicate function is called with each Cid before it is yielded by the stream. If the predicate returns true, the Cid is yielded and its referenced links are queued to be yielded later by the stream. If the predicate returns false, the Cid is skipped and by extension so are its referenced links.
Sourcepub fn stream_links<'a>(
&'a self,
cid: &'a Cid,
) -> impl Stream<Item = Result<Cid>> + 'a
pub fn stream_links<'a>( &'a self, cid: &'a Cid, ) -> impl Stream<Item = Result<Cid>> + 'a
Stream all links that are referenced from the given root Cid or its DAG descendants (recursively).
Sourcepub fn stream_blocks<'a>(
&'a self,
cid: &'a Cid,
) -> impl Stream<Item = Result<(Cid, Vec<u8>)>> + 'a
pub fn stream_blocks<'a>( &'a self, cid: &'a Cid, ) -> impl Stream<Item = Result<(Cid, Vec<u8>)>> + 'a
Stream all the blocks in the DAG starting at the given root Cid.
Sourcepub fn to_block_store(&self) -> S::BlockStore
pub fn to_block_store(&self) -> S::BlockStore
Get an owned copy of the underlying primitive BlockStore for this SphereDb