Skip to main content

activecube_rs/sql/
dialect.rs

1use crate::compiler::ir::{CompileResult, QueryIR};
2
3/// Trait for SQL dialect implementations.
4/// Each database backend (e.g. ClickHouse) implements this
5/// to compile a QueryIR into its native SQL syntax.
6pub trait SqlDialect: Send + Sync {
7    /// Compile a QueryIR into a parameterized SQL string, binding values,
8    /// and an alias remapping table for columns aliased in SELECT for HAVING support.
9    fn compile(&self, ir: &QueryIR) -> CompileResult;
10
11    /// Quote a column or table identifier for this dialect (e.g. backticks for ClickHouse).
12    fn quote_identifier(&self, name: &str) -> String;
13
14    /// Whether the dialect supports `COUNT(DISTINCT col)`.
15    fn supports_count_distinct(&self) -> bool {
16        true
17    }
18
19    /// The placeholder character for parameterized queries (e.g. `?` for ClickHouse, `$1` for PostgreSQL).
20    fn placeholder(&self) -> &str {
21        "?"
22    }
23
24    /// Dialect name for logging/debugging.
25    fn name(&self) -> &str;
26}