use rustc_hash::FxHashMap;
use crate::common::CompactArc;
use crate::core::{IsolationLevel, Result, RowVec, Schema};
use crate::storage::config::Config;
use crate::storage::traits::{Index, Transaction};
pub trait Engine: Send + Sync {
fn open(&mut self) -> Result<()>;
fn close(&mut self) -> Result<()>;
fn begin_transaction(&self) -> Result<Box<dyn Transaction>>;
fn begin_transaction_with_level(&self, level: IsolationLevel) -> Result<Box<dyn Transaction>>;
fn path(&self) -> Option<&str>;
fn table_exists(&self, table_name: &str) -> Result<bool>;
fn index_exists(&self, index_name: &str, table_name: &str) -> Result<bool>;
fn get_index(&self, table_name: &str, index_name: &str) -> Result<Box<dyn Index>>;
fn get_table_schema(&self, table_name: &str) -> Result<CompactArc<Schema>>;
fn schema_epoch(&self) -> u64;
fn list_table_indexes(&self, table_name: &str) -> Result<FxHashMap<String, String>>;
fn get_all_indexes(&self, table_name: &str) -> Result<Vec<std::sync::Arc<dyn Index>>>;
fn get_isolation_level(&self) -> IsolationLevel;
fn set_isolation_level(&mut self, level: IsolationLevel) -> Result<()>;
fn get_config(&self) -> Config;
fn update_config(&mut self, config: Config) -> Result<()>;
fn create_snapshot(&self) -> Result<()>;
fn restore_snapshot(&self, _timestamp: Option<&str>) -> Result<String> {
Err(crate::core::Error::internal(
"restore_snapshot not supported by this engine",
))
}
fn checkpoint_cycle(&self) -> Result<()>;
fn force_checkpoint_cycle(&self) -> Result<()>;
fn dedup_segments(&self) -> usize {
0
}
#[allow(clippy::too_many_arguments)]
fn record_create_index(
&self,
table_name: &str,
index_name: &str,
column_names: &[String],
is_unique: bool,
index_type: crate::core::IndexType,
hnsw_m: Option<u16>,
hnsw_ef_construction: Option<u16>,
hnsw_ef_search: Option<u16>,
hnsw_distance_metric: Option<u8>,
) -> Result<()> {
let _ = (
table_name,
index_name,
column_names,
is_unique,
index_type,
hnsw_m,
hnsw_ef_construction,
hnsw_ef_search,
hnsw_distance_metric,
);
Ok(())
}
fn record_drop_index(&self, table_name: &str, index_name: &str) -> Result<()> {
let _ = (table_name, index_name);
Ok(())
}
fn record_alter_table_add_column(
&self,
table_name: &str,
column_name: &str,
data_type: crate::core::DataType,
nullable: bool,
default_expr: Option<&str>,
vector_dimensions: u16,
) -> Result<()> {
let _ = (
table_name,
column_name,
data_type,
nullable,
default_expr,
vector_dimensions,
);
Ok(())
}
fn record_alter_table_drop_column(&self, table_name: &str, column_name: &str) -> Result<()> {
let _ = (table_name, column_name);
Ok(())
}
fn record_alter_table_rename_column(
&self,
table_name: &str,
old_column_name: &str,
new_column_name: &str,
) -> Result<()> {
let _ = (table_name, old_column_name, new_column_name);
Ok(())
}
fn record_alter_table_modify_column(
&self,
table_name: &str,
column_name: &str,
data_type: crate::core::DataType,
nullable: bool,
vector_dimensions: u16,
) -> Result<()> {
let _ = (
table_name,
column_name,
data_type,
nullable,
vector_dimensions,
);
Ok(())
}
fn record_alter_table_rename(&self, old_table_name: &str, new_table_name: &str) -> Result<()> {
let _ = (old_table_name, new_table_name);
Ok(())
}
fn record_truncate_table(&self, table_name: &str) -> Result<()> {
let _ = table_name;
Ok(())
}
fn fetch_rows_by_ids(&self, table_name: &str, row_ids: &[i64]) -> Result<RowVec> {
let _ = (table_name, row_ids);
Err(crate::core::Error::internal(
"fetch_rows_by_ids not supported by this engine",
))
}
#[allow(clippy::type_complexity)]
fn get_row_fetcher(
&self,
table_name: &str,
) -> Result<Box<dyn Fn(&[i64]) -> RowVec + Send + Sync>> {
let _ = table_name;
Err(crate::core::Error::internal(
"get_row_fetcher not supported by this engine",
))
}
#[allow(clippy::type_complexity)]
fn get_row_counter(
&self,
table_name: &str,
) -> Result<Box<dyn Fn(&[i64]) -> usize + Send + Sync>> {
let _ = table_name;
Err(crate::core::Error::internal(
"get_row_counter not supported by this engine",
))
}
}
#[cfg(test)]
mod tests {
use super::*;
fn _assert_object_safe(_: &dyn Engine) {}
}