pub mod writer;
#[cfg(feature = "sqlite")]
pub mod sqlite;
#[cfg(feature = "sqlite")]
pub use sqlite::SqliteDialect;
pub mod postgres;
pub use postgres::PostgresDialect;
pub mod mysql;
pub use mysql::MySqlDialect;
pub use writer::{
QueryWriter, predicate_sql, quote_string_literal, render_count, render_delete, render_exists,
render_expr, render_insert, render_select, render_union, render_update,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DialectKind {
Sqlite,
Postgres,
Mysql,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SqlType {
Boolean,
Integer,
BigInt,
Real,
Text,
Varchar(u32),
Timestamp,
Blob,
Json,
Uuid,
Array(&'static SqlType),
Enum {
name: &'static str,
variants: &'static [&'static str],
},
}
pub trait Dialect: Send + Sync + 'static {
fn name(&self) -> &'static str;
fn kind(&self) -> DialectKind;
fn quote_identifier(&self, identifier: &str, out: &mut String);
fn placeholder(&self, index: usize, out: &mut String);
fn supports_returning(&self) -> bool;
fn max_bind_params(&self) -> usize {
999
}
fn map_sql_type(&self, ty: SqlType, out: &mut String);
fn quoted(&self, identifier: &str) -> String {
let mut out = String::with_capacity(identifier.len() + 2);
self.quote_identifier(identifier, &mut out);
out
}
fn begin_sql(&self) -> &'static str {
"BEGIN"
}
fn isolation_setup_sql(&self, _level: crate::transaction::IsolationLevel) -> Option<String> {
None
}
fn begin_with_sql(&self, _level: crate::transaction::IsolationLevel) -> String {
"BEGIN".to_string()
}
fn commit_sql(&self) -> &'static str {
"COMMIT"
}
fn rollback_sql(&self) -> &'static str {
"ROLLBACK"
}
fn savepoint_sql(&self, name: &str) -> String {
format!("SAVEPOINT {name}")
}
fn release_sql(&self, name: &str) -> String {
format!("RELEASE {name}")
}
fn rollback_to_sql(&self, name: &str) -> String {
format!("ROLLBACK TO {name}")
}
fn bool_literal(&self, value: bool) -> &'static str {
if value {
"1"
} else {
"0"
}
}
fn escape_string_literal(&self, value: &str, out: &mut String) {
writer::quote_string_literal(value, out);
}
fn acquire_migration_lock_sql(&self, _key: i64) -> Option<String> {
None
}
fn release_migration_lock_sql(&self, _key: i64) -> Option<String> {
None
}
fn supports_index_method(&self) -> bool {
false
}
fn supports_index_include(&self) -> bool {
false
}
fn supports_index_opclass(&self) -> bool {
false
}
fn supports_filter_clause(&self) -> bool {
true
}
fn supports_full_join(&self) -> bool {
true
}
fn supports_distinct_on(&self) -> bool {
false
}
fn supports_lock_modifiers(&self) -> bool {
false
}
}