1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
pub enum Combinator {
  Except,
  Intersect,
  Union,
}

/// Builder to contruct a delete command
#[derive(Default, Clone)]
pub struct DeleteBuilder<'a> {
  pub(crate) _delete_from: &'a str,
  pub(crate) _raw_after: Vec<(DeleteClause, String)>,
  pub(crate) _raw_before: Vec<(DeleteClause, String)>,
  pub(crate) _raw: Vec<String>,
  pub(crate) _where: Vec<String>,

  #[cfg(feature = "postgresql")]
  pub(crate) _returning: Vec<String>,
  #[cfg(feature = "postgresql")]
  pub(crate) _with: Vec<(&'a str, std::sync::Arc<dyn crate::behavior::Query>)>,
}

/// All available clauses to be used in `raw_before` and `raw_after` methods of the DeleteBuilder
#[derive(PartialEq, Clone)]
pub enum DeleteClause {
  DeleteFrom,
  Where,

  #[cfg(feature = "postgresql")]
  Returning,
  #[cfg(feature = "postgresql")]
  With,
}

/// Builder to contruct a insert command
#[derive(Default, Clone)]
pub struct InsertBuilder<'a> {
  pub(crate) _insert_into: &'a str,
  pub(crate) _on: Vec<String>,
  pub(crate) _overriding: &'a str,
  pub(crate) _raw_after: Vec<(InsertClause, String)>,
  pub(crate) _raw_before: Vec<(InsertClause, String)>,
  pub(crate) _raw: Vec<String>,
  pub(crate) _select: Option<SelectBuilder<'a>>,
  pub(crate) _values: Vec<String>,

  #[cfg(feature = "postgresql")]
  pub(crate) _returning: Vec<String>,
  #[cfg(feature = "postgresql")]
  pub(crate) _with: Vec<(&'a str, std::sync::Arc<dyn crate::behavior::Query>)>,
}

/// All available clauses to be used in `raw_before` and `raw_after` methods of the InsertBuilder
#[derive(PartialEq, Clone)]
pub enum InsertClause {
  InsertInto,
  Overriding,
  Select,
  Values,

  #[cfg(feature = "postgresql")]
  Returning,
  #[cfg(feature = "postgresql")]
  With,
}

/// Builder to contruct a select command
#[derive(Default, Clone)]
pub struct SelectBuilder<'a> {
  pub(crate) _except: Vec<Self>,
  pub(crate) _from: Vec<String>,
  pub(crate) _group_by: Vec<String>,
  pub(crate) _having: Vec<String>,
  pub(crate) _intersect: Vec<Self>,
  pub(crate) _join: Vec<String>,
  pub(crate) _limit: &'a str,
  pub(crate) _offset: &'a str,
  pub(crate) _order_by: Vec<String>,
  pub(crate) _raw_after: Vec<(SelectClause, String)>,
  pub(crate) _raw_before: Vec<(SelectClause, String)>,
  pub(crate) _raw: Vec<String>,
  pub(crate) _select: Vec<String>,
  pub(crate) _union: Vec<Self>,
  pub(crate) _where: Vec<String>,

  #[cfg(feature = "postgresql")]
  pub(crate) _with: Vec<(&'a str, std::sync::Arc<dyn crate::behavior::Query>)>,
}

/// All available clauses to be used in `raw_before` and `raw_after` methods of the SelectBuilder
#[derive(Clone, PartialEq)]
pub enum SelectClause {
  Except,
  From,
  GroupBy,
  Having,
  Intersect,
  Join,
  Limit,
  Offset,
  OrderBy,
  Select,
  Union,
  Where,

  #[cfg(feature = "postgresql")]
  With,
}

/// Builder to contruct a update command
#[derive(Default, Clone)]
pub struct UpdateBuilder<'a> {
  pub(crate) _raw_after: Vec<(UpdateClause, String)>,
  pub(crate) _raw_before: Vec<(UpdateClause, String)>,
  pub(crate) _raw: Vec<String>,
  pub(crate) _set: Vec<String>,
  pub(crate) _update: &'a str,
  pub(crate) _where: Vec<String>,

  #[cfg(feature = "postgresql")]
  pub(crate) _returning: Vec<String>,
  #[cfg(feature = "postgresql")]
  pub(crate) _with: Vec<(&'a str, std::sync::Arc<dyn crate::behavior::Query>)>,
}

/// All available clauses to be used in `raw_before` and `raw_after` methods of the UpdateBuilder
#[derive(PartialEq, Clone)]
pub enum UpdateClause {
  Set,
  Update,
  Where,

  #[cfg(feature = "postgresql")]
  Returning,
  #[cfg(feature = "postgresql")]
  With,
}