qail_core/transpiler/sql/
sqlite.rs1use super::super::traits::SqlGenerator;
2
3pub struct SqliteGenerator;
5
6impl SqlGenerator for SqliteGenerator {
7 fn quote_identifier(&self, id: &str) -> String {
8 id.split('.')
9 .map(|part| format!("\"{}\"", part.replace('\0', "").replace('"', "\"\"")))
10 .collect::<Vec<_>>()
11 .join(".")
12 }
13
14 fn placeholder(&self, _index: usize) -> String {
15 "?".to_string()
16 }
17
18 fn fuzzy_operator(&self) -> &str {
19 "LIKE"
20 }
21
22 fn bool_literal(&self, val: bool) -> String {
23 if val {
24 "1".to_string()
25 } else {
26 "0".to_string()
27 }
28 }
29
30 fn string_concat(&self, parts: &[&str]) -> String {
31 parts.join(" || ")
32 }
33
34 fn limit_offset(&self, limit: Option<usize>, offset: Option<usize>) -> String {
35 let mut sql = String::new();
36 if let Some(n) = limit {
37 sql.push_str(&format!(" LIMIT {}", n));
38 }
39 if let Some(n) = offset {
40 sql.push_str(&format!(" OFFSET {}", n));
41 }
42 sql
43 }
44}