activecube_rs/sql/dialect.rs
1use crate::compiler::ir::{QueryIR, SqlValue};
2
3/// Trait for SQL dialect implementations.
4/// Each database backend (StarRocks, ClickHouse, etc.) 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 and binding values.
8 fn compile(&self, ir: &QueryIR) -> (String, Vec<SqlValue>);
9
10 /// Quote a column or table identifier for this dialect (e.g. backticks for MySQL/StarRocks).
11 fn quote_identifier(&self, name: &str) -> String;
12
13 /// Whether the dialect supports `COUNT(DISTINCT col)`.
14 fn supports_count_distinct(&self) -> bool {
15 true
16 }
17
18 /// The placeholder character for parameterized queries (e.g. `?` for MySQL, `$1` for PostgreSQL).
19 fn placeholder(&self) -> &str {
20 "?"
21 }
22
23 /// Dialect name for logging/debugging.
24 fn name(&self) -> &str;
25}