use rustc_hash::FxHashMap;
use crate::core::{IsolationLevel, Result, Row, 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 view_exists(&self, view_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<Schema>;
fn update_table_schema(&self, table_name: &str, schema: Schema) -> Result<()>;
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 record_create_index(
&self,
table_name: &str,
index_name: &str,
column_names: &[String],
is_unique: bool,
index_type: crate::core::IndexType,
) {
let _ = (table_name, index_name, column_names, is_unique, index_type);
}
fn record_drop_index(&self, table_name: &str, index_name: &str) {
let _ = (table_name, index_name);
}
fn record_alter_table_add_column(
&self,
table_name: &str,
column_name: &str,
data_type: crate::core::DataType,
nullable: bool,
default_expr: Option<&str>,
) {
let _ = (table_name, column_name, data_type, nullable, default_expr);
}
fn record_alter_table_drop_column(&self, table_name: &str, column_name: &str) {
let _ = (table_name, column_name);
}
fn record_alter_table_rename_column(
&self,
table_name: &str,
old_column_name: &str,
new_column_name: &str,
) {
let _ = (table_name, old_column_name, new_column_name);
}
fn record_alter_table_modify_column(
&self,
table_name: &str,
column_name: &str,
data_type: crate::core::DataType,
nullable: bool,
auto_increment: Option<bool>,
check_expr: Option<Option<String>>,
) {
let _ = (
table_name,
column_name,
data_type,
nullable,
auto_increment,
check_expr,
);
}
fn record_alter_table_rename(&self, old_table_name: &str, new_table_name: &str) {
let _ = (old_table_name, new_table_name);
}
fn sequence_exists(&self, schema_name: &str, sequence_name: &str) -> Result<bool>;
fn create_sequence(
&self,
schema_name: &str,
sequence_name: &str,
options: crate::core::SequenceOptions,
) -> Result<()>;
fn alter_sequence(
&self,
schema_name: &str,
sequence_name: &str,
options: crate::core::SequenceOptions,
) -> Result<()>;
fn drop_sequence(&self, schema_name: &str, sequence_name: &str) -> Result<()>;
fn nextval(&self, schema_name: &str, sequence_name: &str) -> Result<i64>;
fn setval(
&self,
schema_name: &str,
sequence_name: &str,
value: i64,
is_called: bool,
) -> Result<i64>;
fn list_sequences(&self) -> Result<Vec<(String, String, crate::core::SequenceOptions, i64)>>;
fn fetch_rows_by_ids(&self, table_name: &str, row_ids: &[i64]) -> Result<Vec<(i64, Row)>> {
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]) -> Vec<(i64, Row)> + Send + Sync>> {
let _ = table_name;
Err(crate::core::Error::internal(
"get_row_fetcher not supported by this engine",
))
}
}
#[cfg(test)]
mod tests {
use super::*;
fn _assert_object_safe(_: &dyn Engine) {}
}