1#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
3pub enum Action {
4 Get,
6 Cnt,
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 AlterAddConstraint,
34 AlterDropConstraint,
36 AlterDrop,
38 AlterType,
40 TxnStart,
42 TxnCommit,
44 TxnRollback,
46 Put,
48 DropCol,
50 RenameCol,
52 JsonTable,
54 Export,
56 Truncate,
58 Explain,
60 ExplainAnalyze,
62 Lock,
64 CreateMaterializedView,
66 RefreshMaterializedView,
68 DropMaterializedView,
70 Listen,
72 Notify,
74 Unlisten,
76 Savepoint,
78 ReleaseSavepoint,
80 RollbackToSavepoint,
82 CreateView,
84 DropView,
86 Search,
88 Upsert,
90 Merge,
92 Scroll,
94 CreateCollection,
96 DeleteCollection,
98 CreateFunction,
100 DropFunction,
102 CreateTrigger,
104 DropTrigger,
106 CreateExtension,
108 DropExtension,
110 CommentOn,
112 CreateSequence,
114 DropSequence,
116 CreateEnum,
118 DropEnum,
120 AlterEnumAddValue,
122 AlterSetNotNull,
124 AlterDropNotNull,
126 AlterSetDefault,
128 AlterDropDefault,
130 AlterEnableRls,
132 AlterDisableRls,
134 AlterForceRls,
136 AlterNoForceRls,
138 Call,
141 Do,
143 SessionSet,
145 SessionShow,
147 SessionReset,
149 CreateDatabase,
151 DropDatabase,
153 Grant,
155 Revoke,
157 CreatePolicy,
159 DropPolicy,
161}
162
163impl std::fmt::Display for Action {
164 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
165 match self {
166 Action::Get => write!(f, "GET"),
167 Action::Cnt => write!(f, "CNT"),
168 Action::Set => write!(f, "SET"),
169 Action::Del => write!(f, "DEL"),
170 Action::Add => write!(f, "ADD"),
171 Action::Gen => write!(f, "GEN"),
172 Action::Make => write!(f, "MAKE"),
173 Action::Drop => write!(f, "DROP"),
174 Action::Mod => write!(f, "MOD"),
175 Action::Over => write!(f, "OVER"),
176 Action::With => write!(f, "WITH"),
177 Action::Index => write!(f, "INDEX"),
178 Action::DropIndex => write!(f, "DROP_INDEX"),
179 Action::Alter => write!(f, "ALTER"),
180 Action::AlterAddConstraint => write!(f, "ALTER_ADD_CONSTRAINT"),
181 Action::AlterDropConstraint => write!(f, "ALTER_DROP_CONSTRAINT"),
182 Action::AlterDrop => write!(f, "ALTER_DROP"),
183 Action::AlterType => write!(f, "ALTER_TYPE"),
184 Action::TxnStart => write!(f, "TXN_START"),
185 Action::TxnCommit => write!(f, "TXN_COMMIT"),
186 Action::TxnRollback => write!(f, "TXN_ROLLBACK"),
187 Action::Put => write!(f, "PUT"),
188 Action::DropCol => write!(f, "DROP_COL"),
189 Action::RenameCol => write!(f, "RENAME_COL"),
190 Action::JsonTable => write!(f, "JSON_TABLE"),
191 Action::Export => write!(f, "EXPORT"),
192 Action::Truncate => write!(f, "TRUNCATE"),
193 Action::Explain => write!(f, "EXPLAIN"),
194 Action::ExplainAnalyze => write!(f, "EXPLAIN_ANALYZE"),
195 Action::Lock => write!(f, "LOCK"),
196 Action::CreateMaterializedView => write!(f, "CREATE_MATERIALIZED_VIEW"),
197 Action::RefreshMaterializedView => write!(f, "REFRESH_MATERIALIZED_VIEW"),
198 Action::DropMaterializedView => write!(f, "DROP_MATERIALIZED_VIEW"),
199 Action::Listen => write!(f, "LISTEN"),
200 Action::Notify => write!(f, "NOTIFY"),
201 Action::Unlisten => write!(f, "UNLISTEN"),
202 Action::Savepoint => write!(f, "SAVEPOINT"),
203 Action::ReleaseSavepoint => write!(f, "RELEASE_SAVEPOINT"),
204 Action::RollbackToSavepoint => write!(f, "ROLLBACK_TO_SAVEPOINT"),
205 Action::CreateView => write!(f, "CREATE_VIEW"),
206 Action::DropView => write!(f, "DROP_VIEW"),
207 Action::Search => write!(f, "SEARCH"),
208 Action::Upsert => write!(f, "UPSERT"),
209 Action::Merge => write!(f, "MERGE"),
210 Action::Scroll => write!(f, "SCROLL"),
211 Action::CreateCollection => write!(f, "CREATE_COLLECTION"),
212 Action::DeleteCollection => write!(f, "DELETE_COLLECTION"),
213 Action::CreateFunction => write!(f, "CREATE_FUNCTION"),
214 Action::DropFunction => write!(f, "DROP_FUNCTION"),
215 Action::CreateTrigger => write!(f, "CREATE_TRIGGER"),
216 Action::DropTrigger => write!(f, "DROP_TRIGGER"),
217 Action::CreateExtension => write!(f, "CREATE_EXTENSION"),
218 Action::DropExtension => write!(f, "DROP_EXTENSION"),
219 Action::CommentOn => write!(f, "COMMENT_ON"),
220 Action::CreateSequence => write!(f, "CREATE_SEQUENCE"),
221 Action::DropSequence => write!(f, "DROP_SEQUENCE"),
222 Action::CreateEnum => write!(f, "CREATE_ENUM"),
223 Action::DropEnum => write!(f, "DROP_ENUM"),
224 Action::AlterEnumAddValue => write!(f, "ALTER_ENUM_ADD_VALUE"),
225 Action::AlterSetNotNull => write!(f, "ALTER_SET_NOT_NULL"),
226 Action::AlterDropNotNull => write!(f, "ALTER_DROP_NOT_NULL"),
227 Action::AlterSetDefault => write!(f, "ALTER_SET_DEFAULT"),
228 Action::AlterDropDefault => write!(f, "ALTER_DROP_DEFAULT"),
229 Action::AlterEnableRls => write!(f, "ALTER_ENABLE_RLS"),
230 Action::AlterDisableRls => write!(f, "ALTER_DISABLE_RLS"),
231 Action::AlterForceRls => write!(f, "ALTER_FORCE_RLS"),
232 Action::AlterNoForceRls => write!(f, "ALTER_NO_FORCE_RLS"),
233 Action::Call => write!(f, "CALL"),
234 Action::Do => write!(f, "DO"),
235 Action::SessionSet => write!(f, "SESSION_SET"),
236 Action::SessionShow => write!(f, "SESSION_SHOW"),
237 Action::SessionReset => write!(f, "SESSION_RESET"),
238 Action::CreateDatabase => write!(f, "CREATE_DATABASE"),
239 Action::DropDatabase => write!(f, "DROP_DATABASE"),
240 Action::Grant => write!(f, "GRANT"),
241 Action::Revoke => write!(f, "REVOKE"),
242 Action::CreatePolicy => write!(f, "CREATE_POLICY"),
243 Action::DropPolicy => write!(f, "DROP_POLICY"),
244 }
245 }
246}
247
248#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
250pub enum LogicalOp {
251 #[default]
252 And,
254 Or,
256}
257
258#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
260pub enum SortOrder {
261 Asc,
263 Desc,
265 AscNullsFirst,
267 AscNullsLast,
269 DescNullsFirst,
271 DescNullsLast,
273}
274
275#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
277pub enum Operator {
278 Eq,
280 Ne,
282 Gt,
284 Gte,
286 Lt,
288 Lte,
290 Fuzzy,
292 In,
294 NotIn,
296 IsNull,
298 IsNotNull,
300 Contains,
302 KeyExists,
304 JsonExists,
306 JsonQuery,
308 JsonValue,
310 Like,
312 NotLike,
314 ILike,
316 NotILike,
318 Between,
320 NotBetween,
322 Exists,
324 NotExists,
326 Regex,
328 RegexI,
330 SimilarTo,
332 ContainedBy,
334 Overlaps,
336 TextSearch,
338 KeyExistsAny,
340 KeyExistsAll,
342 JsonPath,
344 JsonPathText,
346 ArrayElemContainedInText,
349}
350
351impl Operator {
352 pub fn sql_symbol(&self) -> &'static str {
355 match self {
356 Operator::Eq => "=",
357 Operator::Ne => "!=",
358 Operator::Gt => ">",
359 Operator::Gte => ">=",
360 Operator::Lt => "<",
361 Operator::Lte => "<=",
362 Operator::Fuzzy => "ILIKE",
363 Operator::In => "IN",
364 Operator::NotIn => "NOT IN",
365 Operator::IsNull => "IS NULL",
366 Operator::IsNotNull => "IS NOT NULL",
367 Operator::Contains => "@>",
368 Operator::KeyExists => "?",
369 Operator::JsonExists => "JSON_EXISTS",
370 Operator::JsonQuery => "JSON_QUERY",
371 Operator::JsonValue => "JSON_VALUE",
372 Operator::Like => "LIKE",
373 Operator::NotLike => "NOT LIKE",
374 Operator::ILike => "ILIKE",
375 Operator::NotILike => "NOT ILIKE",
376 Operator::Between => "BETWEEN",
377 Operator::NotBetween => "NOT BETWEEN",
378 Operator::Exists => "EXISTS",
379 Operator::NotExists => "NOT EXISTS",
380 Operator::Regex => "~",
381 Operator::RegexI => "~*",
382 Operator::SimilarTo => "SIMILAR TO",
383 Operator::ContainedBy => "<@",
384 Operator::Overlaps => "&&",
385 Operator::TextSearch => "@@",
386 Operator::KeyExistsAny => "?|",
387 Operator::KeyExistsAll => "?&",
388 Operator::JsonPath => "#>",
389 Operator::JsonPathText => "#>>",
390 Operator::ArrayElemContainedInText => "CONTAINS_ANY_TOKEN",
391 }
392 }
393
394 pub fn needs_value(&self) -> bool {
396 !matches!(
397 self,
398 Operator::IsNull | Operator::IsNotNull | Operator::Exists | Operator::NotExists
399 )
400 }
401
402 pub fn is_simple_binary(&self) -> bool {
404 matches!(
405 self,
406 Operator::Eq
407 | Operator::Ne
408 | Operator::Gt
409 | Operator::Gte
410 | Operator::Lt
411 | Operator::Lte
412 | Operator::Like
413 | Operator::NotLike
414 | Operator::ILike
415 | Operator::NotILike
416 )
417 }
418}
419
420#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
422pub enum AggregateFunc {
423 Count,
425 Sum,
427 Avg,
429 Min,
431 Max,
433 ArrayAgg,
435 StringAgg,
437 JsonAgg,
439 JsonbAgg,
441 BoolAnd,
443 BoolOr,
445}
446
447impl std::fmt::Display for AggregateFunc {
448 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
449 match self {
450 AggregateFunc::Count => write!(f, "COUNT"),
451 AggregateFunc::Sum => write!(f, "SUM"),
452 AggregateFunc::Avg => write!(f, "AVG"),
453 AggregateFunc::Min => write!(f, "MIN"),
454 AggregateFunc::Max => write!(f, "MAX"),
455 AggregateFunc::ArrayAgg => write!(f, "ARRAY_AGG"),
456 AggregateFunc::StringAgg => write!(f, "STRING_AGG"),
457 AggregateFunc::JsonAgg => write!(f, "JSON_AGG"),
458 AggregateFunc::JsonbAgg => write!(f, "JSONB_AGG"),
459 AggregateFunc::BoolAnd => write!(f, "BOOL_AND"),
460 AggregateFunc::BoolOr => write!(f, "BOOL_OR"),
461 }
462 }
463}
464
465#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
467pub enum JoinKind {
468 Inner,
470 Left,
472 Right,
474 Lateral,
476 Full,
478 Cross,
480}
481
482#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
484pub enum SetOp {
485 Union,
487 UnionAll,
489 Intersect,
491 Except,
493}
494
495#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
497pub enum ModKind {
498 Add,
500 Drop,
502}
503
504#[derive(Debug, Clone, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
506pub enum GroupByMode {
507 #[default]
508 Simple,
510 Rollup,
512 Cube,
514 GroupingSets(Vec<Vec<String>>),
516}
517
518impl GroupByMode {
519 pub fn is_simple(&self) -> bool {
521 matches!(self, GroupByMode::Simple)
522 }
523}
524
525#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
527pub enum LockMode {
528 Update,
530 NoKeyUpdate,
532 Share,
534 KeyShare,
536}
537
538#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
540pub enum OverridingKind {
541 SystemValue,
543 UserValue,
545}
546
547#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
549pub enum SampleMethod {
550 Bernoulli,
552 System,
554}
555
556#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
558pub enum Distance {
559 #[default]
560 Cosine,
562 Euclid,
564 Dot,
566}