krabka_client_streams/store/
backend.rs1use crate::store::byte::{ByteKeyValueStore, InMemoryBytes};
7
8#[derive(Clone, Debug, Default)]
9pub enum StoreBackend {
10 #[default]
11 InMemory,
12 #[cfg(not(target_family = "wasm"))]
13 Turso { state_dir: std::path::PathBuf },
14}
15
16impl StoreBackend {
17 #[tracing::instrument(
20 name = "streams.store.backend_open",
21 level = "info",
22 skip_all,
23 fields(app_id = %app_id, store = %store),
24 )]
25 pub(crate) async fn open(&self, app_id: &str, store: &str) -> Box<dyn ByteKeyValueStore> {
26 match self {
27 Self::InMemory => Box::new(InMemoryBytes::default()),
28 #[cfg(not(target_family = "wasm"))]
29 Self::Turso { state_dir } => {
30 let dir = state_dir.join(app_id);
31 std::fs::create_dir_all(&dir).expect("create state dir");
32 let path = dir.join(format!("{store}.db"));
33 Box::new(
34 crate::store::turso::TursoBytes::open(path.to_str().expect("utf8 path")).await,
35 )
36 }
37 }
38 }
39}