1use crate::error::DbxResult;
7
8pub trait DatabaseCore {
14 fn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>;
16
17 fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>;
19
20 fn delete(&self, table: &str, key: &[u8]) -> DbxResult<()>;
22
23 fn scan(&self, table: &str) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>;
25
26 fn flush(&self) -> DbxResult<()>;
28
29 fn insert_batch(&self, table: &str, entries: Vec<(Vec<u8>, Vec<u8>)>) -> DbxResult<()>;
31
32 fn insert_if_not_exists(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<bool>;
34
35 fn compare_and_swap(
37 &self,
38 table: &str,
39 key: &[u8],
40 expected: &[u8],
41 new_value: &[u8],
42 ) -> DbxResult<bool>;
43
44 fn update_if_exists(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<bool>;
46
47 fn delete_if_equals(&self, table: &str, key: &[u8], expected: &[u8]) -> DbxResult<bool>;
49}
50
51pub trait DatabaseSql {
57 fn execute_sql(&self, sql: &str) -> DbxResult<Vec<arrow::record_batch::RecordBatch>>;
59
60 fn register_table(&self, name: &str, batches: Vec<arrow::record_batch::RecordBatch>);
62
63 fn append_batch(&self, table: &str, batch: arrow::record_batch::RecordBatch) -> DbxResult<()>;
65}
66
67pub trait DatabaseQuery {
74 }
76
77pub trait DatabaseTransaction {
83 fn begin(
85 &self,
86 ) -> DbxResult<crate::transaction::api::Transaction<'_, crate::transaction::api::Active>>;
87}
88
89pub trait DatabaseSnapshot {
95 fn save_to_file(&self, path: &str) -> DbxResult<()>;
97
98 fn load_from_file(path: &str) -> DbxResult<Self>
100 where
101 Self: Sized;
102}
103
104pub trait DatabaseSerde {
110 fn insert_struct<T: serde::Serialize>(
112 &self,
113 table: &str,
114 key: &[u8],
115 data: &T,
116 ) -> DbxResult<()>;
117
118 fn get_struct<T: serde::de::DeserializeOwned>(
120 &self,
121 table: &str,
122 key: &[u8],
123 ) -> DbxResult<Option<T>>;
124}