use crate::error::DbxResult;
pub trait DatabaseCore {
fn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>;
fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>;
fn delete(&self, table: &str, key: &[u8]) -> DbxResult<()>;
fn scan(&self, table: &str) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>;
fn flush(&self) -> DbxResult<()>;
fn insert_batch(&self, table: &str, entries: Vec<(Vec<u8>, Vec<u8>)>) -> DbxResult<()>;
fn insert_if_not_exists(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<bool>;
fn compare_and_swap(
&self,
table: &str,
key: &[u8],
expected: &[u8],
new_value: &[u8],
) -> DbxResult<bool>;
fn update_if_exists(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<bool>;
fn delete_if_equals(&self, table: &str, key: &[u8], expected: &[u8]) -> DbxResult<bool>;
}
pub trait DatabaseSql {
fn execute_sql(&self, sql: &str) -> DbxResult<Vec<arrow::record_batch::RecordBatch>>;
fn register_table(&self, name: &str, batches: Vec<arrow::record_batch::RecordBatch>);
fn append_batch(&self, table: &str, batch: arrow::record_batch::RecordBatch) -> DbxResult<()>;
}
pub trait DatabaseQuery {
}
pub trait DatabaseTransaction {
fn begin(
&self,
) -> DbxResult<crate::transaction::api::Transaction<'_, crate::transaction::api::Active>>;
}
pub trait DatabaseSnapshot {
fn save_to_file(&self, path: &str) -> DbxResult<()>;
fn load_from_file(path: &str) -> DbxResult<Self>
where
Self: Sized;
}
pub trait DatabaseSerde {
fn insert_struct<T: serde::Serialize>(
&self,
table: &str,
key: &[u8],
data: &T,
) -> DbxResult<()>;
fn get_struct<T: serde::de::DeserializeOwned>(
&self,
table: &str,
key: &[u8],
) -> DbxResult<Option<T>>;
}