#[cfg(feature = "mysql")]
mod mysql;
#[cfg(feature = "postgres")]
mod postgres;
#[cfg(feature = "sqlite")]
mod sqlite;
#[cfg(feature = "mysql")]
use mysql::MySqlDialect;
#[cfg(feature = "postgres")]
use postgres::PostgresDialect;
#[cfg(feature = "sqlite")]
use sqlite::SqliteDialect;
use crate::{
filter::FilterType,
helpers::{ColumnBindingKind, SqlBindQuery},
schema::ColumnInfo,
};
pub trait SqlDialect {
fn quote_identifier(&self, identifier: &str) -> String;
fn placeholder(&self, index: usize) -> String;
fn adapt_sql(&self, sql: String) -> String;
fn returning_sql(&self, sql: String, returning: &Vec<&'static str>) -> String;
fn build_filter_expr_fallback(
&self,
col1: &(String, String),
filter: &FilterType,
idx: usize,
) -> String;
fn bind_null<'q>(&self, query: SqlBindQuery<'q>, kind: ColumnBindingKind) -> SqlBindQuery<'q>;
fn insert_sql(&self, sql: String, columns: &Vec<ColumnInfo>) -> String;
}
pub fn get_dialect() -> Box<dyn SqlDialect> {
#[cfg(feature = "mysql")]
{
return Box::new(MySqlDialect);
}
#[cfg(all(not(feature = "mysql"), feature = "postgres"))]
{
return Box::new(PostgresDialect);
}
#[cfg(all(not(feature = "mysql"), not(feature = "postgres"), feature = "sqlite"))]
return Box::new(SqliteDialect);
#[cfg(all(
not(feature = "mysql"),
not(feature = "postgres"),
not(feature = "sqlite")
))]
compile_error!(
"At least one database backend feature (mysql, postgres, sqlite) must be enabled"
);
}