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 DropIndex,
30 Alter,
32 AlterDrop,
34 TxnStart,
36 TxnCommit,
37 TxnRollback,
38 Put,
39 DropCol,
40 RenameCol,
41 JsonTable,
44 Export,
46}
47
48impl std::fmt::Display for Action {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 match self {
51 Action::Get => write!(f, "GET"),
52 Action::Set => write!(f, "SET"),
53 Action::Del => write!(f, "DEL"),
54 Action::Add => write!(f, "ADD"),
55 Action::Gen => write!(f, "GEN"),
56 Action::Make => write!(f, "MAKE"),
57 Action::Drop => write!(f, "DROP"),
58 Action::Mod => write!(f, "MOD"),
59 Action::Over => write!(f, "OVER"),
60 Action::With => write!(f, "WITH"),
61 Action::Index => write!(f, "INDEX"),
62 Action::DropIndex => write!(f, "DROP_INDEX"),
63 Action::Alter => write!(f, "ALTER"),
64 Action::AlterDrop => write!(f, "ALTER_DROP"),
65 Action::TxnStart => write!(f, "TXN_START"),
66 Action::TxnCommit => write!(f, "TXN_COMMIT"),
67 Action::TxnRollback => write!(f, "TXN_ROLLBACK"),
68 Action::Put => write!(f, "PUT"),
69 Action::DropCol => write!(f, "DROP_COL"),
70 Action::RenameCol => write!(f, "RENAME_COL"),
71 Action::JsonTable => write!(f, "JSON_TABLE"),
72 Action::Export => write!(f, "EXPORT"),
73 }
74 }
75}
76
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
79pub enum LogicalOp {
80 #[default]
81 And,
82 Or,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
87pub enum SortOrder {
88 Asc,
89 Desc,
90 AscNullsFirst,
92 AscNullsLast,
94 DescNullsFirst,
96 DescNullsLast,
98}
99
100#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
102pub enum Operator {
103 Eq,
105 Ne,
107 Gt,
109 Gte,
111 Lt,
113 Lte,
115 Fuzzy,
117 In,
119 NotIn,
121 IsNull,
123 IsNotNull,
125 Contains,
127 KeyExists,
129 JsonExists,
131 JsonQuery,
133 JsonValue,
135 Like,
137 NotLike,
139 ILike,
141 NotILike,
143 Between,
145 NotBetween,
147 Exists,
149 NotExists,
151}
152
153impl Operator {
154 pub fn sql_symbol(&self) -> &'static str {
158 match self {
159 Operator::Eq => "=",
160 Operator::Ne => "!=",
161 Operator::Gt => ">",
162 Operator::Gte => ">=",
163 Operator::Lt => "<",
164 Operator::Lte => "<=",
165 Operator::Fuzzy => "ILIKE",
166 Operator::In => "IN",
167 Operator::NotIn => "NOT IN",
168 Operator::IsNull => "IS NULL",
169 Operator::IsNotNull => "IS NOT NULL",
170 Operator::Contains => "@>",
171 Operator::KeyExists => "?",
172 Operator::JsonExists => "JSON_EXISTS",
173 Operator::JsonQuery => "JSON_QUERY",
174 Operator::JsonValue => "JSON_VALUE",
175 Operator::Like => "LIKE",
176 Operator::NotLike => "NOT LIKE",
177 Operator::ILike => "ILIKE",
178 Operator::NotILike => "NOT ILIKE",
179 Operator::Between => "BETWEEN",
180 Operator::NotBetween => "NOT BETWEEN",
181 Operator::Exists => "EXISTS",
182 Operator::NotExists => "NOT EXISTS",
183 }
184 }
185
186 pub fn needs_value(&self) -> bool {
189 !matches!(self,
190 Operator::IsNull |
191 Operator::IsNotNull |
192 Operator::Exists |
193 Operator::NotExists
194 )
195 }
196
197 pub fn is_simple_binary(&self) -> bool {
199 matches!(self,
200 Operator::Eq | Operator::Ne | Operator::Gt | Operator::Gte |
201 Operator::Lt | Operator::Lte | Operator::Like | Operator::NotLike |
202 Operator::ILike | Operator::NotILike
203 )
204 }
205}
206
207#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
209pub enum AggregateFunc {
210 Count,
211 Sum,
212 Avg,
213 Min,
214 Max,
215}
216
217impl std::fmt::Display for AggregateFunc {
218 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
219 match self {
220 AggregateFunc::Count => write!(f, "COUNT"),
221 AggregateFunc::Sum => write!(f, "SUM"),
222 AggregateFunc::Avg => write!(f, "AVG"),
223 AggregateFunc::Min => write!(f, "MIN"),
224 AggregateFunc::Max => write!(f, "MAX"),
225 }
226 }
227}
228
229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
231pub enum JoinKind {
232 Inner,
233 Left,
234 Right,
235 Lateral,
237 Full,
239 Cross,
241}
242
243#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
245pub enum SetOp {
246 Union,
248 UnionAll,
250 Intersect,
252 Except,
254}
255
256#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
258pub enum ModKind {
259 Add,
260 Drop,
261}
262
263#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
265pub enum GroupByMode {
266 #[default]
268 Simple,
269 Rollup,
271 Cube,
273}