polyglot_sql/dialects/
druid.rs1use super::{DialectImpl, DialectType};
13use crate::error::Result;
14use crate::expressions::{Expression, Function};
15use crate::generator::GeneratorConfig;
16use crate::tokens::TokenizerConfig;
17
18pub struct DruidDialect;
20
21impl DialectImpl for DruidDialect {
22 fn dialect_type(&self) -> DialectType {
23 DialectType::Druid
24 }
25
26 fn tokenizer_config(&self) -> TokenizerConfig {
27 let mut config = TokenizerConfig::default();
28 config.identifiers.insert('"', '"');
30 config
31 }
32
33 fn generator_config(&self) -> GeneratorConfig {
34 use crate::generator::IdentifierQuoteStyle;
35 GeneratorConfig {
36 identifier_quote: '"',
37 identifier_quote_style: IdentifierQuoteStyle::DOUBLE_QUOTE,
38 dialect: Some(DialectType::Druid),
39 ..Default::default()
40 }
41 }
42
43 fn transform_expr(&self, expr: Expression) -> Result<Expression> {
44 match expr {
45 Expression::CurrentTimestamp(_) => Ok(Expression::CurrentTimestamp(
47 crate::expressions::CurrentTimestamp {
48 precision: None,
49 sysdate: false,
50 },
51 )),
52
53 Expression::Mod(op) => Ok(Expression::Function(Box::new(Function::new(
55 "MOD".to_string(),
56 vec![op.left, op.right],
57 )))),
58
59 Expression::Function(f) => self.transform_function(*f),
61
62 _ => Ok(expr),
64 }
65 }
66}
67
68impl DruidDialect {
69 fn transform_function(&self, f: Function) -> Result<Expression> {
70 let name_upper = f.name.to_uppercase();
71 match name_upper.as_str() {
72 "CURRENT_TIMESTAMP" => Ok(Expression::CurrentTimestamp(
74 crate::expressions::CurrentTimestamp {
75 precision: None,
76 sysdate: false,
77 },
78 )),
79
80 _ => Ok(Expression::Function(Box::new(f))),
82 }
83 }
84}