Skip to main content

qail_core/transpiler/sql/
sqlite.rs

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