Skip to main content

shodh_redb/composite/
provider.rs

1//! Backend-agnostic trait for blob queries used by `CompositeQuery`.
2//!
3//! `BlobQueryProvider` abstracts the blob-related query operations that
4//! `CompositeQuery` needs, enabling composite queries to work with any
5//! storage backend that implements this trait.
6
7use alloc::vec::Vec;
8
9use crate::blob_store::types::{BlobId, BlobMeta, CausalEdge, TemporalKey};
10
11/// Provides blob query operations needed by `CompositeQuery`.
12///
13/// This trait decouples the composite query engine from the storage backend.
14pub trait BlobQueryProvider {
15    /// Error type returned by blob operations.
16    type Error: Into<crate::StorageError>;
17
18    /// Get blob metadata by ID.
19    fn get_blob_meta(&self, blob_id: &BlobId) -> Result<Option<BlobMeta>, Self::Error>;
20
21    /// Look up a blob by its sequence number.
22    ///
23    /// Returns the `(BlobId, BlobMeta)` pair for the blob with the given sequence,
24    /// or `None` if no blob matches.
25    fn blob_by_sequence(&self, seq: u64) -> Result<Option<(BlobId, BlobMeta)>, Self::Error>;
26
27    /// Query blobs in a temporal range `[start_ns, end_ns]`.
28    fn blobs_in_time_range(
29        &self,
30        start_ns: u64,
31        end_ns: u64,
32    ) -> Result<Vec<(TemporalKey, BlobMeta)>, Self::Error>;
33
34    /// Query blobs in a namespace, returning `(BlobId, BlobMeta)` pairs.
35    fn blobs_in_namespace(&self, namespace: &str) -> Result<Vec<(BlobId, BlobMeta)>, Self::Error>;
36
37    /// Query blobs that have the given tag.
38    fn blobs_by_tag(&self, tag: &str) -> Result<Vec<BlobId>, Self::Error>;
39
40    /// Get the causal children of a parent blob.
41    fn causal_children(&self, blob_id: &BlobId) -> Result<Vec<CausalEdge>, Self::Error>;
42}
43
44// ---------------------------------------------------------------------------
45// Legacy ReadTransaction implementation
46// ---------------------------------------------------------------------------
47
48impl BlobQueryProvider for crate::transactions::ReadTransaction {
49    type Error = crate::StorageError;
50
51    fn get_blob_meta(&self, blob_id: &BlobId) -> Result<Option<BlobMeta>, Self::Error> {
52        self.get_blob_meta(blob_id)
53    }
54
55    fn blob_by_sequence(&self, seq: u64) -> Result<Option<(BlobId, BlobMeta)>, Self::Error> {
56        self.blob_by_sequence(seq)
57    }
58
59    fn blobs_in_time_range(
60        &self,
61        start_ns: u64,
62        end_ns: u64,
63    ) -> Result<Vec<(TemporalKey, BlobMeta)>, Self::Error> {
64        self.blobs_in_time_range(start_ns, end_ns)
65    }
66
67    fn blobs_in_namespace(&self, namespace: &str) -> Result<Vec<(BlobId, BlobMeta)>, Self::Error> {
68        self.blobs_in_namespace(namespace)
69    }
70
71    fn blobs_by_tag(&self, tag: &str) -> Result<Vec<BlobId>, Self::Error> {
72        self.blobs_by_tag(tag)
73    }
74
75    fn causal_children(&self, blob_id: &BlobId) -> Result<Vec<CausalEdge>, Self::Error> {
76        self.causal_children(blob_id)
77    }
78}