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 AlterType,
36 TxnStart,
38 TxnCommit,
39 TxnRollback,
40 Put,
41 DropCol,
42 RenameCol,
43 JsonTable,
46 Export,
48 Truncate,
50 Explain,
52 ExplainAnalyze,
54 Lock,
56 CreateMaterializedView,
58 RefreshMaterializedView,
60 DropMaterializedView,
62 Listen,
65 Notify,
67 Unlisten,
69 Savepoint,
72 ReleaseSavepoint,
74 RollbackToSavepoint,
76}
77
78impl std::fmt::Display for Action {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 match self {
81 Action::Get => write!(f, "GET"),
82 Action::Set => write!(f, "SET"),
83 Action::Del => write!(f, "DEL"),
84 Action::Add => write!(f, "ADD"),
85 Action::Gen => write!(f, "GEN"),
86 Action::Make => write!(f, "MAKE"),
87 Action::Drop => write!(f, "DROP"),
88 Action::Mod => write!(f, "MOD"),
89 Action::Over => write!(f, "OVER"),
90 Action::With => write!(f, "WITH"),
91 Action::Index => write!(f, "INDEX"),
92 Action::DropIndex => write!(f, "DROP_INDEX"),
93 Action::Alter => write!(f, "ALTER"),
94 Action::AlterDrop => write!(f, "ALTER_DROP"),
95 Action::AlterType => write!(f, "ALTER_TYPE"),
96 Action::TxnStart => write!(f, "TXN_START"),
97 Action::TxnCommit => write!(f, "TXN_COMMIT"),
98 Action::TxnRollback => write!(f, "TXN_ROLLBACK"),
99 Action::Put => write!(f, "PUT"),
100 Action::DropCol => write!(f, "DROP_COL"),
101 Action::RenameCol => write!(f, "RENAME_COL"),
102 Action::JsonTable => write!(f, "JSON_TABLE"),
103 Action::Export => write!(f, "EXPORT"),
104 Action::Truncate => write!(f, "TRUNCATE"),
105 Action::Explain => write!(f, "EXPLAIN"),
106 Action::ExplainAnalyze => write!(f, "EXPLAIN_ANALYZE"),
107 Action::Lock => write!(f, "LOCK"),
108 Action::CreateMaterializedView => write!(f, "CREATE_MATERIALIZED_VIEW"),
109 Action::RefreshMaterializedView => write!(f, "REFRESH_MATERIALIZED_VIEW"),
110 Action::DropMaterializedView => write!(f, "DROP_MATERIALIZED_VIEW"),
111 Action::Listen => write!(f, "LISTEN"),
112 Action::Notify => write!(f, "NOTIFY"),
113 Action::Unlisten => write!(f, "UNLISTEN"),
114 Action::Savepoint => write!(f, "SAVEPOINT"),
115 Action::ReleaseSavepoint => write!(f, "RELEASE_SAVEPOINT"),
116 Action::RollbackToSavepoint => write!(f, "ROLLBACK_TO_SAVEPOINT"),
117 }
118 }
119}
120
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
123pub enum LogicalOp {
124 #[default]
125 And,
126 Or,
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
131pub enum SortOrder {
132 Asc,
133 Desc,
134 AscNullsFirst,
136 AscNullsLast,
138 DescNullsFirst,
140 DescNullsLast,
142}
143
144#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
146pub enum Operator {
147 Eq,
149 Ne,
151 Gt,
153 Gte,
155 Lt,
157 Lte,
159 Fuzzy,
161 In,
163 NotIn,
165 IsNull,
167 IsNotNull,
169 Contains,
171 KeyExists,
173 JsonExists,
175 JsonQuery,
177 JsonValue,
179 Like,
181 NotLike,
183 ILike,
185 NotILike,
187 Between,
189 NotBetween,
191 Exists,
193 NotExists,
195 Regex,
197 RegexI,
199 SimilarTo,
201 ContainedBy,
203 Overlaps,
205}
206
207impl Operator {
208 pub fn sql_symbol(&self) -> &'static str {
212 match self {
213 Operator::Eq => "=",
214 Operator::Ne => "!=",
215 Operator::Gt => ">",
216 Operator::Gte => ">=",
217 Operator::Lt => "<",
218 Operator::Lte => "<=",
219 Operator::Fuzzy => "ILIKE",
220 Operator::In => "IN",
221 Operator::NotIn => "NOT IN",
222 Operator::IsNull => "IS NULL",
223 Operator::IsNotNull => "IS NOT NULL",
224 Operator::Contains => "@>",
225 Operator::KeyExists => "?",
226 Operator::JsonExists => "JSON_EXISTS",
227 Operator::JsonQuery => "JSON_QUERY",
228 Operator::JsonValue => "JSON_VALUE",
229 Operator::Like => "LIKE",
230 Operator::NotLike => "NOT LIKE",
231 Operator::ILike => "ILIKE",
232 Operator::NotILike => "NOT ILIKE",
233 Operator::Between => "BETWEEN",
234 Operator::NotBetween => "NOT BETWEEN",
235 Operator::Exists => "EXISTS",
236 Operator::NotExists => "NOT EXISTS",
237 Operator::Regex => "~",
238 Operator::RegexI => "~*",
239 Operator::SimilarTo => "SIMILAR TO",
240 Operator::ContainedBy => "<@",
241 Operator::Overlaps => "&&",
242 }
243 }
244
245 pub fn needs_value(&self) -> bool {
248 !matches!(
249 self,
250 Operator::IsNull | Operator::IsNotNull | Operator::Exists | Operator::NotExists
251 )
252 }
253
254 pub fn is_simple_binary(&self) -> bool {
256 matches!(
257 self,
258 Operator::Eq
259 | Operator::Ne
260 | Operator::Gt
261 | Operator::Gte
262 | Operator::Lt
263 | Operator::Lte
264 | Operator::Like
265 | Operator::NotLike
266 | Operator::ILike
267 | Operator::NotILike
268 )
269 }
270}
271
272#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
274pub enum AggregateFunc {
275 Count,
276 Sum,
277 Avg,
278 Min,
279 Max,
280 ArrayAgg,
282 StringAgg,
284 JsonAgg,
286 JsonbAgg,
288 BoolAnd,
290 BoolOr,
292}
293
294impl std::fmt::Display for AggregateFunc {
295 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
296 match self {
297 AggregateFunc::Count => write!(f, "COUNT"),
298 AggregateFunc::Sum => write!(f, "SUM"),
299 AggregateFunc::Avg => write!(f, "AVG"),
300 AggregateFunc::Min => write!(f, "MIN"),
301 AggregateFunc::Max => write!(f, "MAX"),
302 AggregateFunc::ArrayAgg => write!(f, "ARRAY_AGG"),
303 AggregateFunc::StringAgg => write!(f, "STRING_AGG"),
304 AggregateFunc::JsonAgg => write!(f, "JSON_AGG"),
305 AggregateFunc::JsonbAgg => write!(f, "JSONB_AGG"),
306 AggregateFunc::BoolAnd => write!(f, "BOOL_AND"),
307 AggregateFunc::BoolOr => write!(f, "BOOL_OR"),
308 }
309 }
310}
311
312#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
314pub enum JoinKind {
315 Inner,
316 Left,
317 Right,
318 Lateral,
320 Full,
322 Cross,
324}
325
326#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
328pub enum SetOp {
329 Union,
331 UnionAll,
333 Intersect,
335 Except,
337}
338
339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
341pub enum ModKind {
342 Add,
343 Drop,
344}
345
346#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
348pub enum GroupByMode {
349 #[default]
351 Simple,
352 Rollup,
354 Cube,
356}
357
358#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
360pub enum LockMode {
361 Update,
363 NoKeyUpdate,
365 Share,
367 KeyShare,
369}
370
371#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
373pub enum OverridingKind {
374 SystemValue,
376 UserValue,
378}
379
380#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
382pub enum SampleMethod {
383 Bernoulli,
385 System,
387}