1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::{err::Error, SimpleTransaction};
use std::{pin::Pin, sync::Arc};

#[derive(Debug, Clone)]
pub enum StorageVariant {
	RelationalStore,
	KeyValueStore,
}

#[derive(Debug, Clone)]
pub enum StorageAdapterName {
	RocksDB,
	CassandraDB,
}

#[derive(Debug, Clone)]
pub struct StorageAdapter<T> {
	pub name: StorageAdapterName,
	pub path: String,
	pub db_instance: Pin<Arc<T>>,
	pub variant: StorageVariant,
}

impl<T> StorageAdapter<T> {
	pub fn new(
		name: StorageAdapterName,
		path: String,
		db_instance: T,
		variant: StorageVariant,
	) -> Result<Self, Error> {
		Ok(StorageAdapter {
			name,
			path,
			db_instance: Arc::pin(db_instance),
			variant,
		})
	}
}

pub trait DatastoreAdapter {
	type Transaction: SimpleTransaction;
	// # Create new database transaction
	// Set `rw` default to false means readable but not readable
	fn transaction(&self, rw: bool) -> Result<Self::Transaction, Error>;

	fn default() -> Self;

	fn spawn(&self) -> Self;
}