sea_query/backend/sqlite/
query.rs1use super::*;
2use crate::extension::sqlite::SqliteBinOper;
3
4impl QueryBuilder for SqliteQueryBuilder {
5 fn prepare_select_lock(&self, _select_lock: &LockClause, _sql: &mut dyn SqlWriter) {
6 }
8
9 fn prepare_sub_query_oper(&self, oper: &SubQueryOper, sql: &mut dyn SqlWriter) {
10 sql.write_str(match oper {
11 SubQueryOper::Exists => "EXISTS",
12 SubQueryOper::Any => panic!("Operator 'ANY' doesnot support"),
13 SubQueryOper::Some => panic!("Operator 'SOME' doesnot support"),
14 SubQueryOper::All => panic!("Operator 'ALL' doesnot support"),
15 })
16 .unwrap();
17 }
18
19 fn prepare_bin_oper(&self, bin_oper: &BinOper, sql: &mut dyn SqlWriter) {
20 match bin_oper {
21 BinOper::SqliteOperator(bin_oper) => sql
22 .write_str(match bin_oper {
23 SqliteBinOper::Glob => "GLOB",
24 SqliteBinOper::Match => "MATCH",
25 SqliteBinOper::GetJsonField => "->",
26 SqliteBinOper::CastJsonField => "->>",
27 })
28 .unwrap(),
29 _ => self.prepare_bin_oper_common(bin_oper, sql),
30 }
31 }
32
33 fn prepare_union_statement(
34 &self,
35 union_type: UnionType,
36 select_statement: &SelectStatement,
37 sql: &mut dyn SqlWriter,
38 ) {
39 match union_type {
40 UnionType::Intersect => sql.write_str(" INTERSECT ").unwrap(),
41 UnionType::Distinct => sql.write_str(" UNION ").unwrap(),
42 UnionType::Except => sql.write_str(" EXCEPT ").unwrap(),
43 UnionType::All => sql.write_str(" UNION ALL ").unwrap(),
44 }
45 self.prepare_select_statement(select_statement, sql);
46 }
47
48 fn prepare_query_statement(&self, query: &SubQueryStatement, sql: &mut dyn SqlWriter) {
49 query.prepare_statement(self, sql);
50 }
51
52 fn prepare_with_clause_recursive_options(&self, _: &WithClause, _: &mut dyn SqlWriter) {
53 }
55
56 fn prepare_order_expr(&self, order_expr: &OrderExpr, sql: &mut dyn SqlWriter) {
57 if !matches!(order_expr.order, Order::Field(_)) {
58 self.prepare_simple_expr(&order_expr.expr, sql);
59 }
60 self.prepare_order(order_expr, sql);
61 match order_expr.nulls {
62 None => (),
63 Some(NullOrdering::Last) => sql.write_str(" NULLS LAST").unwrap(),
64 Some(NullOrdering::First) => sql.write_str(" NULLS FIRST").unwrap(),
65 }
66 }
67
68 fn prepare_value(&self, value: Value, sql: &mut dyn SqlWriter) {
69 sql.push_param(value, self as _);
70 }
71
72 fn greatest_function(&self) -> &str {
73 "MAX"
74 }
75
76 fn least_function(&self) -> &str {
77 "MIN"
78 }
79
80 fn char_length_function(&self) -> &str {
81 "LENGTH"
82 }
83
84 fn insert_default_values(&self, _: u32, sql: &mut dyn SqlWriter) {
85 sql.write_str("DEFAULT VALUES").unwrap()
87 }
88}