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