elif_orm/query/
builder.rs1use std::marker::PhantomData;
4use serde_json::Value;
5
6use super::types::*;
7
8#[derive(Debug)]
10pub struct QueryBuilder<M = ()> {
11 pub(crate) query_type: QueryType,
12 pub(crate) select_fields: Vec<String>,
13 pub(crate) from_tables: Vec<String>,
14 pub(crate) insert_table: Option<String>,
15 pub(crate) update_table: Option<String>,
16 pub(crate) delete_table: Option<String>,
17 pub(crate) set_clauses: Vec<SetClause>,
18 pub(crate) where_conditions: Vec<WhereCondition>,
19 pub(crate) joins: Vec<JoinClause>,
20 pub(crate) order_by: Vec<(String, OrderDirection)>,
21 pub(crate) group_by: Vec<String>,
22 pub(crate) having_conditions: Vec<WhereCondition>,
23 pub(crate) limit_count: Option<i64>,
24 pub(crate) offset_value: Option<i64>,
25 pub(crate) distinct: bool,
26 _phantom: PhantomData<M>,
27}
28
29impl<M> Clone for QueryBuilder<M> {
30 fn clone(&self) -> Self {
31 Self {
32 query_type: self.query_type.clone(),
33 select_fields: self.select_fields.clone(),
34 from_tables: self.from_tables.clone(),
35 insert_table: self.insert_table.clone(),
36 update_table: self.update_table.clone(),
37 delete_table: self.delete_table.clone(),
38 set_clauses: self.set_clauses.clone(),
39 where_conditions: self.where_conditions.clone(),
40 joins: self.joins.clone(),
41 order_by: self.order_by.clone(),
42 group_by: self.group_by.clone(),
43 having_conditions: self.having_conditions.clone(),
44 limit_count: self.limit_count,
45 offset_value: self.offset_value,
46 distinct: self.distinct,
47 _phantom: PhantomData,
48 }
49 }
50}
51
52impl<M> Default for QueryBuilder<M> {
53 fn default() -> Self {
54 Self::new()
55 }
56}
57
58impl<M> QueryBuilder<M> {
59 pub fn new() -> Self {
61 Self {
62 query_type: QueryType::Select,
63 select_fields: Vec::new(),
64 from_tables: Vec::new(),
65 insert_table: None,
66 update_table: None,
67 delete_table: None,
68 set_clauses: Vec::new(),
69 where_conditions: Vec::new(),
70 joins: Vec::new(),
71 order_by: Vec::new(),
72 group_by: Vec::new(),
73 having_conditions: Vec::new(),
74 limit_count: None,
75 offset_value: None,
76 distinct: false,
77 _phantom: PhantomData,
78 }
79 }
80}