pub struct CustomDialectBuilder { /* private fields */ }Expand description
Fluent builder for creating and registering custom SQL dialects.
A custom dialect is based on an existing built-in dialect and allows selective overrides of tokenizer configuration, generator configuration, and expression transforms.
§Example
use polyglot_sql::dialects::{CustomDialectBuilder, DialectType, Dialect};
use polyglot_sql::generator::NormalizeFunctions;
CustomDialectBuilder::new("my_postgres")
.based_on(DialectType::PostgreSQL)
.generator_config_modifier(|gc| {
gc.normalize_functions = NormalizeFunctions::Lower;
})
.register()
.unwrap();
let d = Dialect::get_by_name("my_postgres").unwrap();
let exprs = d.parse("SELECT COUNT(*)").unwrap();
let sql = d.generate(&exprs[0]).unwrap();
assert_eq!(sql, "select count(*)");
polyglot_sql::unregister_custom_dialect("my_postgres");Implementations§
Source§impl CustomDialectBuilder
impl CustomDialectBuilder
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new builder with the given name. Defaults to Generic as the base dialect.
Sourcepub fn based_on(self, dialect: DialectType) -> Self
pub fn based_on(self, dialect: DialectType) -> Self
Set the base built-in dialect to inherit configuration from.
Sourcepub fn tokenizer_config_modifier<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut TokenizerConfig) + 'static,
pub fn tokenizer_config_modifier<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut TokenizerConfig) + 'static,
Provide a closure that modifies the tokenizer configuration inherited from the base dialect.
Sourcepub fn generator_config_modifier<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut GeneratorConfig) + 'static,
pub fn generator_config_modifier<F>(self, f: F) -> Selfwhere
F: FnOnce(&mut GeneratorConfig) + 'static,
Provide a closure that modifies the generator configuration inherited from the base dialect.
Sourcepub fn transform_fn<F>(self, f: F) -> Self
pub fn transform_fn<F>(self, f: F) -> Self
Set a custom per-node expression transform function.
This replaces the base dialect’s transform. It is called on every expression node during the recursive transform pass.
Sourcepub fn preprocess_fn<F>(self, f: F) -> Self
pub fn preprocess_fn<F>(self, f: F) -> Self
Set a custom whole-tree preprocessing function.
This replaces the base dialect’s built-in preprocessing. It is called once on the entire expression tree before the recursive per-node transform.