#[cfg(feature = "mysql")]
mod mysql;
#[cfg(feature = "mysql")]
pub use self::mysql::MySql;
#[cfg(feature = "pg")]
mod pg;
#[cfg(feature = "pg")]
pub use self::pg::Pg;
#[cfg(feature = "sqlite3")]
mod sqlite3;
#[cfg(feature = "sqlite3")]
pub use self::sqlite3::Sqlite;
#[cfg(feature = "mssql")]
mod mssql;
#[cfg(feature = "mssql")]
pub use self::mssql::MsSql;
#[allow(unused_imports)]
use crate::{types::Type, Migration};
#[derive(Copy, Clone, Debug)]
pub enum SqlVariant {
#[cfg(feature = "sqlite3")]
Sqlite,
#[cfg(feature = "pg")]
Pg,
#[cfg(feature = "mysql")]
Mysql,
#[cfg(feature = "mssql")]
Mssql,
#[doc(hidden)]
__Empty,
}
impl SqlVariant {
pub(crate) fn run_for(self, _migr: &Migration) -> String {
match self {
#[cfg(feature = "sqlite3")]
SqlVariant::Sqlite => _migr.make::<Sqlite>(),
#[cfg(feature = "pg")]
SqlVariant::Pg => _migr.make::<Pg>(),
#[cfg(feature = "mysql")]
SqlVariant::Mysql => _migr.make::<MySql>(),
#[cfg(feature = "mssql")]
SqlVariant::Mssql => _migr.make::<MsSql>(),
_ => panic!("You need to select an Sql variant!"),
}
}
}
pub trait SqlGenerator {
fn create_table(name: &str, schema: Option<&str>) -> String;
fn create_table_if_not_exists(name: &str, schema: Option<&str>) -> String;
fn drop_table(name: &str, schema: Option<&str>) -> String;
fn drop_table_if_exists(name: &str, schema: Option<&str>) -> String;
fn rename_table(old: &str, new: &str, schema: Option<&str>) -> String;
fn alter_table(name: &str, schema: Option<&str>) -> String;
fn add_column(ex: bool, schema: Option<&str>, name: &str, _type: &Type) -> String;
fn drop_column(name: &str) -> String;
fn rename_column(old: &str, new: &str) -> String;
fn create_index(table: &str, schema: Option<&str>, name: &str, _type: &Type) -> String;
fn create_constraint(name: &str, _type: &Type, schema: Option<&str>) -> String;
fn create_partial_index(
table: &str,
schema: Option<&str>,
name: &str,
_type: &Type,
conditions: &str,
) -> String {
format!(
"{} WHERE {}",
Self::create_index(table, schema, name, _type),
conditions
)
}
fn drop_index(name: &str) -> String;
fn add_foreign_key(
columns: &[String],
table: &str,
relation_columns: &[String],
schema: Option<&str>,
) -> String;
fn add_primary_key(columns: &[String]) -> String;
}