Skip to main content

nodedb_lite/storage/pagedb_storage/engine/
native.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! `StorageEngine` implementation for native targets.
4
5use async_trait::async_trait;
6use pagedb::vfs::Vfs;
7
8use nodedb_types::Namespace;
9
10use crate::error::LiteError;
11use crate::storage::engine::{CompactionOutcome, KvPair, PrefixScan, StorageEngine, WriteOp};
12use crate::storage::pagedb_storage::types::PagedbStorage;
13
14#[async_trait]
15impl<V: Vfs + Clone + Send + Sync + 'static> StorageEngine for PagedbStorage<V>
16where
17    <V as Vfs>::LockHandle: Sync,
18    <V as Vfs>::File: Sync,
19{
20    async fn get(&self, ns: Namespace, key: &[u8]) -> Result<Option<Vec<u8>>, LiteError> {
21        self.get_rows(ns, key).await
22    }
23
24    async fn put(&self, ns: Namespace, key: &[u8], value: &[u8]) -> Result<(), LiteError> {
25        self.put_rows(ns, key, value).await
26    }
27
28    async fn delete(&self, ns: Namespace, key: &[u8]) -> Result<(), LiteError> {
29        self.delete_rows(ns, key).await
30    }
31
32    async fn scan_prefix(&self, ns: Namespace, prefix: &[u8]) -> Result<Vec<KvPair>, LiteError> {
33        self.scan_prefix_rows(ns, prefix).await
34    }
35
36    async fn scan_prefix_bounded(
37        &self,
38        ns: Namespace,
39        prefix: &[u8],
40        limit: usize,
41    ) -> Result<Vec<KvPair>, LiteError> {
42        self.scan_prefix_bounded_rows(ns, prefix, limit).await
43    }
44
45    async fn scan_prefix_budgeted(
46        &self,
47        ns: Namespace,
48        prefix: &[u8],
49        max_records: usize,
50        max_bytes: usize,
51    ) -> Result<PrefixScan, LiteError> {
52        self.scan_budgeted(ns, prefix, None, max_records, max_bytes, false)
53            .await
54    }
55
56    async fn scan_prefix_from_budgeted(
57        &self,
58        ns: Namespace,
59        prefix: &[u8],
60        after_key: Option<&[u8]>,
61        max_records: usize,
62        max_bytes: usize,
63    ) -> Result<PrefixScan, LiteError> {
64        self.scan_budgeted(ns, prefix, after_key, max_records, max_bytes, true)
65            .await
66    }
67
68    async fn batch_write(&self, ops: &[WriteOp]) -> Result<(), LiteError> {
69        self.batch_write_rows(ops).await
70    }
71
72    async fn count(&self, ns: Namespace) -> Result<u64, LiteError> {
73        self.count_rows(ns).await
74    }
75
76    async fn scan_range(
77        &self,
78        ns: Namespace,
79        start: &[u8],
80        limit: usize,
81    ) -> Result<Vec<KvPair>, LiteError> {
82        self.scan_range_rows(ns, start, limit).await
83    }
84
85    async fn scan_range_bounded(
86        &self,
87        ns: Namespace,
88        start: Option<&[u8]>,
89        end: Option<&[u8]>,
90        limit: Option<usize>,
91    ) -> Result<Vec<KvPair>, LiteError> {
92        self.scan_range_bounded_rows(ns, start, end, limit).await
93    }
94
95    async fn compact(&self) -> Result<CompactionOutcome, LiteError> {
96        self.compact_rows().await
97    }
98
99    fn as_vector_segment_ext(
100        &self,
101    ) -> Option<&dyn crate::storage::vector_segment_ext::VectorSegmentExt> {
102        Some(self)
103    }
104
105    fn as_array_segment_ext(
106        &self,
107    ) -> Option<&dyn crate::storage::array_segment_ext::ArraySegmentExt> {
108        Some(self)
109    }
110
111    fn as_fts_segment_ext(&self) -> Option<&dyn crate::storage::fts_segment_ext::FtsSegmentExt> {
112        Some(self)
113    }
114
115    fn as_columnar_segment_ext(
116        &self,
117    ) -> Option<&dyn crate::storage::columnar_segment_ext::ColumnarSegmentExt> {
118        Some(self)
119    }
120
121    fn as_graph_segment_ext(
122        &self,
123    ) -> Option<&dyn crate::storage::graph_segment_ext::GraphSegmentExt> {
124        Some(self)
125    }
126
127    fn as_spatial_segment_ext(
128        &self,
129    ) -> Option<&dyn crate::storage::spatial_segment_ext::SpatialSegmentExt> {
130        Some(self)
131    }
132}