pub trait DialectPlugin: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn quote_style(&self) -> Option<QuoteStyle> { ... }
fn supports_ilike(&self) -> Option<bool> { ... }
fn map_function_name(&self, name: &str) -> Option<String> { ... }
fn map_data_type(&self, data_type: &DataType) -> Option<DataType> { ... }
fn transform_expr(&self, expr: &Expr) -> Option<Expr> { ... }
fn transform_statement(&self, statement: &Statement) -> Option<Statement> { ... }
}Expand description
Trait that external code can implement to define a custom SQL dialect.
All methods have default implementations that return None, meaning
“no custom behaviour — fall through to the built-in logic”. Implementors
only need to override the methods they care about.
§Thread Safety
Implementations must be Send + Sync because the global registry is
shared across threads.
§Example
use sqlglot_rust::dialects::plugin::{DialectPlugin, DialectRegistry};
use sqlglot_rust::ast::{DataType, Expr, QuoteStyle, Statement};
struct MyDialect;
impl DialectPlugin for MyDialect {
fn name(&self) -> &str { "mydialect" }
fn map_function_name(&self, name: &str) -> Option<String> {
match name.to_uppercase().as_str() {
"MY_FUNC" => Some("BUILTIN_FUNC".to_string()),
_ => None,
}
}
fn quote_style(&self) -> Option<QuoteStyle> {
Some(QuoteStyle::Backtick)
}
}
// Register once, then use via DialectRef::Custom("mydialect")
DialectRegistry::global().register(MyDialect);Required Methods§
Provided Methods§
Sourcefn quote_style(&self) -> Option<QuoteStyle>
fn quote_style(&self) -> Option<QuoteStyle>
Preferred quoting style for identifiers.
Sourcefn supports_ilike(&self) -> Option<bool>
fn supports_ilike(&self) -> Option<bool>
Whether this dialect natively supports ILIKE.
Sourcefn map_function_name(&self, name: &str) -> Option<String>
fn map_function_name(&self, name: &str) -> Option<String>
Map a function name for this dialect.
Return Some(new_name) to override, or None to keep the original.
Sourcefn map_data_type(&self, data_type: &DataType) -> Option<DataType>
fn map_data_type(&self, data_type: &DataType) -> Option<DataType>
Map a data type for this dialect.
Return Some(new_type) to override, or None to keep the original.
Sourcefn transform_expr(&self, expr: &Expr) -> Option<Expr>
fn transform_expr(&self, expr: &Expr) -> Option<Expr>
Transform an entire expression for this dialect.
Return Some(new_expr) to replace the expression, or None to
fall through to the default transformation logic.
Sourcefn transform_statement(&self, statement: &Statement) -> Option<Statement>
fn transform_statement(&self, statement: &Statement) -> Option<Statement>
Transform a complete statement for this dialect.
Return Some(new_stmt) to replace the statement, or None to
fall through to the default transformation logic.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".