1pub mod ffi;
5
6use std::ops::Bound;
7
8use ffi::{raw_store_contains_key, raw_store_get, raw_store_prefix, raw_store_range};
9use reifydb_core::encoded::{key::EncodedKey, row::EncodedRow};
10use tracing::{Span, instrument};
11
12use crate::{error::Result, operator::context::OperatorContext};
13
14pub struct Store<'a> {
15 ctx: &'a mut OperatorContext,
16}
17
18impl<'a> Store<'a> {
19 pub(crate) fn new(ctx: &'a mut OperatorContext) -> Self {
20 Self {
21 ctx,
22 }
23 }
24
25 #[instrument(name = "flow::operator::store::get", level = "trace", skip(self), fields(
26 key_len = key.as_bytes().len(),
27 found
28 ))]
29 pub fn get(&self, key: &EncodedKey) -> Result<Option<EncodedRow>> {
30 let result = raw_store_get(self.ctx, key)?;
31 Span::current().record("found", result.is_some());
32 Ok(result)
33 }
34
35 #[instrument(name = "flow::operator::store::contains", level = "trace", skip(self), fields(
36 key_len = key.as_bytes().len()
37 ))]
38 pub fn contains(&self, key: &EncodedKey) -> Result<bool> {
39 raw_store_contains_key(self.ctx, key)
40 }
41
42 #[instrument(name = "flow::operator::store::prefix", level = "trace", skip(self), fields(
43 prefix_len = prefix.as_bytes().len(),
44 result_count
45 ))]
46 pub fn prefix(&self, prefix: &EncodedKey) -> Result<Vec<(EncodedKey, EncodedRow)>> {
47 let results = raw_store_prefix(self.ctx, prefix)?;
48 Span::current().record("result_count", results.len());
49 Ok(results)
50 }
51
52 #[instrument(
53 name = "flow::operator::store::range",
54 level = "trace",
55 skip(self, start, end),
56 fields(result_count)
57 )]
58 pub fn range(
59 &self,
60 start: Bound<&EncodedKey>,
61 end: Bound<&EncodedKey>,
62 ) -> Result<Vec<(EncodedKey, EncodedRow)>> {
63 let results = raw_store_range(self.ctx, start, end)?;
64 Span::current().record("result_count", results.len());
65 Ok(results)
66 }
67}