db/model/
adapter.rs

1use crate::{err::Error, SimpleTransaction};
2use std::{pin::Pin, sync::Arc};
3
4#[derive(Debug, Clone)]
5pub enum StorageVariant {
6	RelationalStore,
7	KeyValueStore,
8}
9
10#[derive(Debug, Clone)]
11pub enum StorageAdapterName {
12	RocksDB,
13	CassandraDB,
14}
15
16#[derive(Debug, Clone)]
17pub struct StorageAdapter<T> {
18	pub name: StorageAdapterName,
19	pub path: String,
20	pub db_instance: Pin<Arc<T>>,
21	pub variant: StorageVariant,
22}
23
24impl<T> StorageAdapter<T> {
25	pub fn new(
26		name: StorageAdapterName,
27		path: String,
28		db_instance: T,
29		variant: StorageVariant,
30	) -> Result<Self, Error> {
31		Ok(StorageAdapter {
32			name,
33			path,
34			db_instance: Arc::pin(db_instance),
35			variant,
36		})
37	}
38}
39
40pub trait DatastoreAdapter {
41	type Transaction: SimpleTransaction;
42	// # Create new database transaction
43	// Set `rw` default to false means readable but not readable
44	fn transaction(&self, rw: bool) -> Result<Self::Transaction, Error>;
45
46	fn default() -> Self;
47
48	fn spawn(&self) -> Self;
49}