Skip to main content

reifydb_store_single/
lib.rs

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