Skip to main content

CustomDialectBuilder

Struct CustomDialectBuilder 

Source
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

Source

pub fn new(name: impl Into<String>) -> Self

Create a new builder with the given name. Defaults to Generic as the base dialect.

Source

pub fn based_on(self, dialect: DialectType) -> Self

Set the base built-in dialect to inherit configuration from.

Source

pub fn tokenizer_config_modifier<F>(self, f: F) -> Self
where F: FnOnce(&mut TokenizerConfig) + 'static,

Provide a closure that modifies the tokenizer configuration inherited from the base dialect.

Source

pub fn generator_config_modifier<F>(self, f: F) -> Self
where F: FnOnce(&mut GeneratorConfig) + 'static,

Provide a closure that modifies the generator configuration inherited from the base dialect.

Source

pub fn transform_fn<F>(self, f: F) -> Self
where F: Fn(Expression) -> Result<Expression> + Send + Sync + 'static,

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.

Source

pub fn preprocess_fn<F>(self, f: F) -> Self
where F: Fn(Expression) -> Result<Expression> + Send + Sync + 'static,

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.

Source

pub fn register(self) -> Result<()>

Build the custom dialect configuration and register it in the global registry.

Returns an error if:

  • The name collides with a built-in dialect name
  • A custom dialect with the same name is already registered

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.