reifydb_store_single/
lib.rs1#![cfg_attr(not(debug_assertions), deny(clippy::disallowed_methods))]
4#![cfg_attr(debug_assertions, warn(clippy::disallowed_methods))]
5#![cfg_attr(not(debug_assertions), deny(warnings))]
6#![allow(clippy::tabs_in_doc_comments)]
7
8use reifydb_core::{
9 event::EventBus,
10 interface::version::{ComponentType, HasVersion, SystemVersion},
11};
12use reifydb_type::Result;
13
14pub mod config;
15pub mod hot;
16pub mod store;
17pub mod tier;
18
19use config::{HotConfig, SingleStoreConfig};
20use reifydb_core::{
21 delta::Delta,
22 encoded::key::{EncodedKey, EncodedKeyRange},
23 interface::store::{
24 SingleVersionBatch, SingleVersionCommit, SingleVersionContains, SingleVersionGet, SingleVersionRange,
25 SingleVersionRangeRev, SingleVersionRemove, SingleVersionRow, SingleVersionSet, SingleVersionStore,
26 },
27};
28use reifydb_type::util::cowvec::CowVec;
29use store::StandardSingleStore;
30
31pub struct SingleStoreVersion;
32
33impl HasVersion for SingleStoreVersion {
34 fn version(&self) -> SystemVersion {
35 SystemVersion {
36 name: env!("CARGO_PKG_NAME")
37 .strip_prefix("reifydb-")
38 .unwrap_or(env!("CARGO_PKG_NAME"))
39 .to_string(),
40 version: env!("CARGO_PKG_VERSION").to_string(),
41 description: "Single-version storage for OLTP operations without version history".to_string(),
42 r#type: ComponentType::Module,
43 }
44 }
45}
46
47#[repr(u8)]
48#[derive(Clone)]
49pub enum SingleStore {
50 Standard(StandardSingleStore) = 0,
51 }
53
54impl SingleStore {
55 pub fn standard(config: SingleStoreConfig) -> Self {
56 Self::Standard(StandardSingleStore::new(config).unwrap())
57 }
58}
59
60impl SingleStore {
61 pub fn testing_memory() -> Self {
62 SingleStore::Standard(StandardSingleStore::testing_memory())
63 }
64
65 pub fn testing_memory_with_eventbus(event_bus: EventBus) -> Self {
66 SingleStore::Standard(StandardSingleStore::testing_memory_with_eventbus(event_bus))
67 }
68
69 pub fn hot(&self) -> Option<&hot::tier::HotTier> {
73 match self {
74 SingleStore::Standard(store) => store.hot(),
75 }
76 }
77}
78
79impl SingleVersionGet for SingleStore {
82 #[inline]
83 fn get(&self, key: &EncodedKey) -> Result<Option<SingleVersionRow>> {
84 match self {
85 SingleStore::Standard(store) => SingleVersionGet::get(store, key),
86 }
87 }
88}
89
90impl SingleVersionContains for SingleStore {
91 #[inline]
92 fn contains(&self, key: &EncodedKey) -> Result<bool> {
93 match self {
94 SingleStore::Standard(store) => SingleVersionContains::contains(store, key),
95 }
96 }
97}
98
99impl SingleVersionSet for SingleStore {}
100
101impl SingleVersionRemove for SingleStore {}
102
103impl SingleVersionCommit for SingleStore {
104 #[inline]
105 fn commit(&mut self, deltas: CowVec<Delta>) -> Result<()> {
106 match self {
107 SingleStore::Standard(store) => SingleVersionCommit::commit(store, deltas),
108 }
109 }
110}
111
112impl SingleVersionRange for SingleStore {
113 #[inline]
114 fn range_batch(&self, range: EncodedKeyRange, batch_size: u64) -> Result<SingleVersionBatch> {
115 match self {
116 SingleStore::Standard(store) => SingleVersionRange::range_batch(store, range, batch_size),
117 }
118 }
119}
120
121impl SingleVersionRangeRev for SingleStore {
122 #[inline]
123 fn range_rev_batch(&self, range: EncodedKeyRange, batch_size: u64) -> Result<SingleVersionBatch> {
124 match self {
125 SingleStore::Standard(store) => {
126 SingleVersionRangeRev::range_rev_batch(store, range, batch_size)
127 }
128 }
129 }
130}
131
132impl SingleVersionStore for SingleStore {}