mod base;
mod clickhouse;
pub mod column;
mod enums;
pub mod feature;
mod index;
mod mongodb;
mod mysql;
mod names;
mod postgresql;
mod sqlite;
pub mod table;
pub use clickhouse::ClickHouse;
pub use column::{Column, ColumnDefinition};
pub use enums::{
ColumnType, Engine, ForeignKeyAction, IndexAlgorithm, IndexType, Order, ParameterDirection, PartitionType,
TriggerEvent, TriggerTiming,
};
pub use feature::ViewBody;
pub use index::{CheckConstraint, Index, IndexOptions, RenameColumn};
pub use mongodb::MongoDb;
pub use mysql::MySql;
pub use postgresql::PostgreSql;
pub use sqlite::Sqlite;
pub use table::{ForeignKey, Table, TableDefinition};
use crate::builder::{Executor, Statement};
use crate::error::Result;
pub trait Schema: Clone + Send + Sync + Sized + 'static {
fn executor(&self) -> Option<&Executor>;
fn set_executor(&mut self, executor: Executor) -> &mut Self;
fn quote(&self, identifier: &str) -> Result<String>;
fn quote_literal(&self, identifier: &str) -> Result<String>;
fn compile_column_type(&self, column: &Column<Self>) -> Result<String>;
fn compile_auto_increment(&self) -> &'static str;
fn table(&self, name: impl Into<String>) -> Table<Self> {
Table::with_schema(self.clone(), name)
}
fn compile_create(&self, table: &Table<Self>, if_not_exists: bool) -> Result<Statement> {
base::create(self, table, if_not_exists)
}
fn compile_alter(&self, table: &Table<Self>) -> Result<Statement> {
base::alter(self, table)
}
fn compile_drop(&self, name: &str, if_exists: bool) -> Result<Statement> {
base::plain(self, format!("DROP TABLE {}{}", if if_exists { "IF EXISTS " } else { "" }, self.quote(name)?))
}
fn compile_rename(&self, from: &str, to: &str) -> Result<Statement> {
base::plain(self, format!("RENAME TABLE {} TO {}", self.quote(from)?, self.quote(to)?))
}
fn compile_truncate(&self, name: &str) -> Result<Statement> {
base::plain(self, format!("TRUNCATE TABLE {}", self.quote(name)?))
}
fn create_index(&self, table: &str, name: &str, columns: &[&str], options: &IndexOptions) -> Result<Statement> {
base::create_index(self, table, name, columns, options)
}
fn drop_index(&self, table: &str, name: &str) -> Result<Statement> {
base::plain(self, format!("DROP INDEX {} ON {}", self.quote(name)?, self.quote(table)?))
}
fn compile_column_definition(&self, column: &Column<Self>) -> Result<String> {
base::column_definition(self, column)
}
fn compile_generated_clause(&self, column: &Column<Self>) -> String {
base::generated_clause(column)
}
fn compile_create_suffix(&self, _table: &Table<Self>) -> String {
String::new()
}
fn quote_collation(&self, collation: &str) -> Result<String> {
Ok(collation.to_owned())
}
fn literal(&self) -> crate::StringLiteral {
crate::StringLiteral::Backslash
}
fn compile_unsigned(&self) -> &'static str {
"UNSIGNED"
}
fn compile_index_columns(&self, index: &Index) -> Result<String> {
base::index_columns(self, index)
}
}