1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5pub enum Action {
6 Get,
8 Cnt,
10 Set,
12 Del,
14 Add,
16 Gen,
18 Make,
20 Drop,
22 Mod,
24 Over,
26 With,
28 Index,
30 DropIndex,
32 Alter,
34 AlterDrop,
36 AlterType,
38 TxnStart,
40 TxnCommit,
42 TxnRollback,
44 Put,
46 DropCol,
48 RenameCol,
50 JsonTable,
52 Export,
54 Truncate,
56 Explain,
58 ExplainAnalyze,
60 Lock,
62 CreateMaterializedView,
64 RefreshMaterializedView,
66 DropMaterializedView,
68 Listen,
70 Notify,
72 Unlisten,
74 Savepoint,
76 ReleaseSavepoint,
78 RollbackToSavepoint,
80 CreateView,
82 DropView,
84 Search,
86 Upsert,
88 Scroll,
90 CreateCollection,
92 DeleteCollection,
94 CreateFunction,
96 DropFunction,
98 CreateTrigger,
100 DropTrigger,
102 CreateExtension,
104 DropExtension,
106 CommentOn,
108 CreateSequence,
110 DropSequence,
112 CreateEnum,
114 DropEnum,
116 AlterEnumAddValue,
118 AlterSetNotNull,
120 AlterDropNotNull,
122 AlterSetDefault,
124 AlterDropDefault,
126 AlterEnableRls,
128 AlterDisableRls,
130 AlterForceRls,
132 AlterNoForceRls,
134 Call,
137 Do,
139 SessionSet,
141 SessionShow,
143 SessionReset,
145}
146
147impl std::fmt::Display for Action {
148 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
149 match self {
150 Action::Get => write!(f, "GET"),
151 Action::Cnt => write!(f, "CNT"),
152 Action::Set => write!(f, "SET"),
153 Action::Del => write!(f, "DEL"),
154 Action::Add => write!(f, "ADD"),
155 Action::Gen => write!(f, "GEN"),
156 Action::Make => write!(f, "MAKE"),
157 Action::Drop => write!(f, "DROP"),
158 Action::Mod => write!(f, "MOD"),
159 Action::Over => write!(f, "OVER"),
160 Action::With => write!(f, "WITH"),
161 Action::Index => write!(f, "INDEX"),
162 Action::DropIndex => write!(f, "DROP_INDEX"),
163 Action::Alter => write!(f, "ALTER"),
164 Action::AlterDrop => write!(f, "ALTER_DROP"),
165 Action::AlterType => write!(f, "ALTER_TYPE"),
166 Action::TxnStart => write!(f, "TXN_START"),
167 Action::TxnCommit => write!(f, "TXN_COMMIT"),
168 Action::TxnRollback => write!(f, "TXN_ROLLBACK"),
169 Action::Put => write!(f, "PUT"),
170 Action::DropCol => write!(f, "DROP_COL"),
171 Action::RenameCol => write!(f, "RENAME_COL"),
172 Action::JsonTable => write!(f, "JSON_TABLE"),
173 Action::Export => write!(f, "EXPORT"),
174 Action::Truncate => write!(f, "TRUNCATE"),
175 Action::Explain => write!(f, "EXPLAIN"),
176 Action::ExplainAnalyze => write!(f, "EXPLAIN_ANALYZE"),
177 Action::Lock => write!(f, "LOCK"),
178 Action::CreateMaterializedView => write!(f, "CREATE_MATERIALIZED_VIEW"),
179 Action::RefreshMaterializedView => write!(f, "REFRESH_MATERIALIZED_VIEW"),
180 Action::DropMaterializedView => write!(f, "DROP_MATERIALIZED_VIEW"),
181 Action::Listen => write!(f, "LISTEN"),
182 Action::Notify => write!(f, "NOTIFY"),
183 Action::Unlisten => write!(f, "UNLISTEN"),
184 Action::Savepoint => write!(f, "SAVEPOINT"),
185 Action::ReleaseSavepoint => write!(f, "RELEASE_SAVEPOINT"),
186 Action::RollbackToSavepoint => write!(f, "ROLLBACK_TO_SAVEPOINT"),
187 Action::CreateView => write!(f, "CREATE_VIEW"),
188 Action::DropView => write!(f, "DROP_VIEW"),
189 Action::Search => write!(f, "SEARCH"),
190 Action::Upsert => write!(f, "UPSERT"),
191 Action::Scroll => write!(f, "SCROLL"),
192 Action::CreateCollection => write!(f, "CREATE_COLLECTION"),
193 Action::DeleteCollection => write!(f, "DELETE_COLLECTION"),
194 Action::CreateFunction => write!(f, "CREATE_FUNCTION"),
195 Action::DropFunction => write!(f, "DROP_FUNCTION"),
196 Action::CreateTrigger => write!(f, "CREATE_TRIGGER"),
197 Action::DropTrigger => write!(f, "DROP_TRIGGER"),
198 Action::CreateExtension => write!(f, "CREATE_EXTENSION"),
199 Action::DropExtension => write!(f, "DROP_EXTENSION"),
200 Action::CommentOn => write!(f, "COMMENT_ON"),
201 Action::CreateSequence => write!(f, "CREATE_SEQUENCE"),
202 Action::DropSequence => write!(f, "DROP_SEQUENCE"),
203 Action::CreateEnum => write!(f, "CREATE_ENUM"),
204 Action::DropEnum => write!(f, "DROP_ENUM"),
205 Action::AlterEnumAddValue => write!(f, "ALTER_ENUM_ADD_VALUE"),
206 Action::AlterSetNotNull => write!(f, "ALTER_SET_NOT_NULL"),
207 Action::AlterDropNotNull => write!(f, "ALTER_DROP_NOT_NULL"),
208 Action::AlterSetDefault => write!(f, "ALTER_SET_DEFAULT"),
209 Action::AlterDropDefault => write!(f, "ALTER_DROP_DEFAULT"),
210 Action::AlterEnableRls => write!(f, "ALTER_ENABLE_RLS"),
211 Action::AlterDisableRls => write!(f, "ALTER_DISABLE_RLS"),
212 Action::AlterForceRls => write!(f, "ALTER_FORCE_RLS"),
213 Action::AlterNoForceRls => write!(f, "ALTER_NO_FORCE_RLS"),
214 Action::Call => write!(f, "CALL"),
215 Action::Do => write!(f, "DO"),
216 Action::SessionSet => write!(f, "SESSION_SET"),
217 Action::SessionShow => write!(f, "SESSION_SHOW"),
218 Action::SessionReset => write!(f, "SESSION_RESET"),
219 }
220 }
221}
222
223#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
225pub enum LogicalOp {
226 #[default]
227 And,
229 Or,
231}
232
233#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
235pub enum SortOrder {
236 Asc,
238 Desc,
240 AscNullsFirst,
242 AscNullsLast,
244 DescNullsFirst,
246 DescNullsLast,
248}
249
250#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
252pub enum Operator {
253 Eq,
255 Ne,
257 Gt,
259 Gte,
261 Lt,
263 Lte,
265 Fuzzy,
267 In,
269 NotIn,
271 IsNull,
273 IsNotNull,
275 Contains,
277 KeyExists,
279 JsonExists,
281 JsonQuery,
283 JsonValue,
285 Like,
287 NotLike,
289 ILike,
291 NotILike,
293 Between,
295 NotBetween,
297 Exists,
299 NotExists,
301 Regex,
303 RegexI,
305 SimilarTo,
307 ContainedBy,
309 Overlaps,
311 TextSearch,
313 KeyExistsAny,
315 KeyExistsAll,
317 JsonPath,
319 JsonPathText,
321 ArrayElemContainedInText,
324}
325
326impl Operator {
327 pub fn sql_symbol(&self) -> &'static str {
330 match self {
331 Operator::Eq => "=",
332 Operator::Ne => "!=",
333 Operator::Gt => ">",
334 Operator::Gte => ">=",
335 Operator::Lt => "<",
336 Operator::Lte => "<=",
337 Operator::Fuzzy => "ILIKE",
338 Operator::In => "IN",
339 Operator::NotIn => "NOT IN",
340 Operator::IsNull => "IS NULL",
341 Operator::IsNotNull => "IS NOT NULL",
342 Operator::Contains => "@>",
343 Operator::KeyExists => "?",
344 Operator::JsonExists => "JSON_EXISTS",
345 Operator::JsonQuery => "JSON_QUERY",
346 Operator::JsonValue => "JSON_VALUE",
347 Operator::Like => "LIKE",
348 Operator::NotLike => "NOT LIKE",
349 Operator::ILike => "ILIKE",
350 Operator::NotILike => "NOT ILIKE",
351 Operator::Between => "BETWEEN",
352 Operator::NotBetween => "NOT BETWEEN",
353 Operator::Exists => "EXISTS",
354 Operator::NotExists => "NOT EXISTS",
355 Operator::Regex => "~",
356 Operator::RegexI => "~*",
357 Operator::SimilarTo => "SIMILAR TO",
358 Operator::ContainedBy => "<@",
359 Operator::Overlaps => "&&",
360 Operator::TextSearch => "@@",
361 Operator::KeyExistsAny => "?|",
362 Operator::KeyExistsAll => "?&",
363 Operator::JsonPath => "#>",
364 Operator::JsonPathText => "#>>",
365 Operator::ArrayElemContainedInText => "CONTAINS_ANY_TOKEN",
366 }
367 }
368
369 pub fn needs_value(&self) -> bool {
371 !matches!(
372 self,
373 Operator::IsNull | Operator::IsNotNull | Operator::Exists | Operator::NotExists
374 )
375 }
376
377 pub fn is_simple_binary(&self) -> bool {
379 matches!(
380 self,
381 Operator::Eq
382 | Operator::Ne
383 | Operator::Gt
384 | Operator::Gte
385 | Operator::Lt
386 | Operator::Lte
387 | Operator::Like
388 | Operator::NotLike
389 | Operator::ILike
390 | Operator::NotILike
391 )
392 }
393}
394
395#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
397pub enum AggregateFunc {
398 Count,
400 Sum,
402 Avg,
404 Min,
406 Max,
408 ArrayAgg,
410 StringAgg,
412 JsonAgg,
414 JsonbAgg,
416 BoolAnd,
418 BoolOr,
420}
421
422impl std::fmt::Display for AggregateFunc {
423 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
424 match self {
425 AggregateFunc::Count => write!(f, "COUNT"),
426 AggregateFunc::Sum => write!(f, "SUM"),
427 AggregateFunc::Avg => write!(f, "AVG"),
428 AggregateFunc::Min => write!(f, "MIN"),
429 AggregateFunc::Max => write!(f, "MAX"),
430 AggregateFunc::ArrayAgg => write!(f, "ARRAY_AGG"),
431 AggregateFunc::StringAgg => write!(f, "STRING_AGG"),
432 AggregateFunc::JsonAgg => write!(f, "JSON_AGG"),
433 AggregateFunc::JsonbAgg => write!(f, "JSONB_AGG"),
434 AggregateFunc::BoolAnd => write!(f, "BOOL_AND"),
435 AggregateFunc::BoolOr => write!(f, "BOOL_OR"),
436 }
437 }
438}
439
440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
442pub enum JoinKind {
443 Inner,
445 Left,
447 Right,
449 Lateral,
451 Full,
453 Cross,
455}
456
457#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
459pub enum SetOp {
460 Union,
462 UnionAll,
464 Intersect,
466 Except,
468}
469
470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
472pub enum ModKind {
473 Add,
475 Drop,
477}
478
479#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
481pub enum GroupByMode {
482 #[default]
483 Simple,
485 Rollup,
487 Cube,
489 GroupingSets(Vec<Vec<String>>),
491}
492
493impl GroupByMode {
494 pub fn is_simple(&self) -> bool {
496 matches!(self, GroupByMode::Simple)
497 }
498}
499
500#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
502pub enum LockMode {
503 Update,
505 NoKeyUpdate,
507 Share,
509 KeyShare,
511}
512
513#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
515pub enum OverridingKind {
516 SystemValue,
518 UserValue,
520}
521
522#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
524pub enum SampleMethod {
525 Bernoulli,
527 System,
529}
530
531#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
533pub enum Distance {
534 #[default]
535 Cosine,
537 Euclid,
539 Dot,
541}