qail_core/transpiler/sql/
sqlserver.rs1use super::super::traits::SqlGenerator;
2
3pub struct SqlServerGenerator;
4
5impl SqlGenerator for SqlServerGenerator {
6 fn quote_identifier(&self, id: &str) -> String {
7 format!("[{}]", id)
8 }
9
10 fn placeholder(&self, index: usize) -> String {
11 format!("@p{}", index)
12 }
13
14 fn fuzzy_operator(&self) -> &str {
15 "LIKE"
16 }
17
18 fn bool_literal(&self, val: bool) -> String {
19 if val { "1".to_string() } else { "0".to_string() }
20 }
21
22 fn string_concat(&self, parts: &[&str]) -> String {
23 parts.join(" + ")
24 }
25
26 fn limit_offset(&self, limit: Option<usize>, offset: Option<usize>) -> String {
27 let mut sql = String::new();
34 let off = offset.unwrap_or(0);
35
36 if limit.is_some() || offset.is_some() {
38 sql.push_str(&format!(" OFFSET {} ROWS", off));
39
40 if let Some(lim) = limit {
41 sql.push_str(&format!(" FETCH NEXT {} ROWS ONLY", lim));
42 }
43 }
44
45 sql
46 }
47}