use crate::core::{
AggregateQuery, BulkInsertQuery, BulkUpdateQuery, CountQuery, DeleteQuery, FieldType,
InsertQuery, SelectQuery, UpdateQuery,
};
use super::{CompiledStatement, SqlError};
pub trait Dialect {
fn name(&self) -> &'static str;
fn quote_ident(&self, name: &str) -> String {
let escaped = name.replace('"', "\"\"");
format!("\"{escaped}\"")
}
fn placeholder(&self, n: usize) -> String {
let _ = n;
"?".to_owned()
}
fn serial_type(&self, field_type: FieldType) -> &'static str {
match field_type {
FieldType::I32 => "INTEGER",
_ => "BIGINT",
}
}
fn bool_literal(&self, b: bool) -> &'static str {
if b {
"TRUE"
} else {
"FALSE"
}
}
fn supports_concurrent_index(&self) -> bool {
false
}
fn supports_returning(&self) -> bool {
false
}
fn acquire_session_lock_sql(&self) -> Option<String> {
None
}
fn release_session_lock_sql(&self) -> Option<String> {
None
}
fn acquire_xact_lock_sql(&self) -> Option<String> {
None
}
fn compile_select(&self, query: &SelectQuery) -> Result<CompiledStatement, SqlError>;
fn compile_insert(&self, query: &InsertQuery) -> Result<CompiledStatement, SqlError>;
fn compile_bulk_insert(
&self,
query: &BulkInsertQuery,
) -> Result<CompiledStatement, SqlError>;
fn compile_update(&self, query: &UpdateQuery) -> Result<CompiledStatement, SqlError>;
fn compile_delete(&self, query: &DeleteQuery) -> Result<CompiledStatement, SqlError>;
fn compile_count(&self, query: &CountQuery) -> Result<CompiledStatement, SqlError>;
fn compile_aggregate(&self, query: &AggregateQuery) -> Result<CompiledStatement, SqlError>;
fn compile_bulk_update(&self, query: &BulkUpdateQuery) -> Result<CompiledStatement, SqlError>;
}