1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5pub enum Action {
6 Get,
8 Set,
10 Del,
12 Add,
14 Gen,
16 Make,
18 Drop,
20 Mod,
22 Over,
24 With,
26 Index,
28 TxnStart,
30 TxnCommit,
31 TxnRollback,
32 Put,
33 DropCol,
34 RenameCol,
35 JsonTable,
38}
39
40impl std::fmt::Display for Action {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 match self {
43 Action::Get => write!(f, "GET"),
44 Action::Set => write!(f, "SET"),
45 Action::Del => write!(f, "DEL"),
46 Action::Add => write!(f, "ADD"),
47 Action::Gen => write!(f, "GEN"),
48 Action::Make => write!(f, "MAKE"),
49 Action::Drop => write!(f, "DROP"),
50 Action::Mod => write!(f, "MOD"),
51 Action::Over => write!(f, "OVER"),
52 Action::With => write!(f, "WITH"),
53 Action::Index => write!(f, "INDEX"),
54 Action::TxnStart => write!(f, "TXN_START"),
55 Action::TxnCommit => write!(f, "TXN_COMMIT"),
56 Action::TxnRollback => write!(f, "TXN_ROLLBACK"),
57 Action::Put => write!(f, "PUT"),
58 Action::DropCol => write!(f, "DROP_COL"),
59 Action::RenameCol => write!(f, "RENAME_COL"),
60 Action::JsonTable => write!(f, "JSON_TABLE"),
61 }
62 }
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
67pub enum LogicalOp {
68 #[default]
69 And,
70 Or,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
75pub enum SortOrder {
76 Asc,
77 Desc,
78 AscNullsFirst,
80 AscNullsLast,
82 DescNullsFirst,
84 DescNullsLast,
86}
87
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
90pub enum Operator {
91 Eq,
93 Ne,
95 Gt,
97 Gte,
99 Lt,
101 Lte,
103 Fuzzy,
105 In,
107 NotIn,
109 IsNull,
111 IsNotNull,
113 Contains,
115 KeyExists,
117 JsonExists,
119 JsonQuery,
121 JsonValue,
123 Like,
125 NotLike,
127 ILike,
129 NotILike,
131 Between,
133 NotBetween,
135 Exists,
137 NotExists,
139}
140
141impl Operator {
142 pub fn sql_symbol(&self) -> &'static str {
146 match self {
147 Operator::Eq => "=",
148 Operator::Ne => "!=",
149 Operator::Gt => ">",
150 Operator::Gte => ">=",
151 Operator::Lt => "<",
152 Operator::Lte => "<=",
153 Operator::Fuzzy => "ILIKE",
154 Operator::In => "IN",
155 Operator::NotIn => "NOT IN",
156 Operator::IsNull => "IS NULL",
157 Operator::IsNotNull => "IS NOT NULL",
158 Operator::Contains => "@>",
159 Operator::KeyExists => "?",
160 Operator::JsonExists => "JSON_EXISTS",
161 Operator::JsonQuery => "JSON_QUERY",
162 Operator::JsonValue => "JSON_VALUE",
163 Operator::Like => "LIKE",
164 Operator::NotLike => "NOT LIKE",
165 Operator::ILike => "ILIKE",
166 Operator::NotILike => "NOT ILIKE",
167 Operator::Between => "BETWEEN",
168 Operator::NotBetween => "NOT BETWEEN",
169 Operator::Exists => "EXISTS",
170 Operator::NotExists => "NOT EXISTS",
171 }
172 }
173
174 pub fn needs_value(&self) -> bool {
177 !matches!(self,
178 Operator::IsNull |
179 Operator::IsNotNull |
180 Operator::Exists |
181 Operator::NotExists
182 )
183 }
184
185 pub fn is_simple_binary(&self) -> bool {
187 matches!(self,
188 Operator::Eq | Operator::Ne | Operator::Gt | Operator::Gte |
189 Operator::Lt | Operator::Lte | Operator::Like | Operator::NotLike |
190 Operator::ILike | Operator::NotILike
191 )
192 }
193}
194
195#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
197pub enum AggregateFunc {
198 Count,
199 Sum,
200 Avg,
201 Min,
202 Max,
203}
204
205impl std::fmt::Display for AggregateFunc {
206 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
207 match self {
208 AggregateFunc::Count => write!(f, "COUNT"),
209 AggregateFunc::Sum => write!(f, "SUM"),
210 AggregateFunc::Avg => write!(f, "AVG"),
211 AggregateFunc::Min => write!(f, "MIN"),
212 AggregateFunc::Max => write!(f, "MAX"),
213 }
214 }
215}
216
217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
219pub enum JoinKind {
220 Inner,
221 Left,
222 Right,
223 Lateral,
225 Full,
227 Cross,
229}
230
231#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
233pub enum SetOp {
234 Union,
236 UnionAll,
238 Intersect,
240 Except,
242}
243
244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
246pub enum ModKind {
247 Add,
248 Drop,
249}
250
251#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
253pub enum GroupByMode {
254 #[default]
256 Simple,
257 Rollup,
259 Cube,
261}