1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
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 AlterDrop,
34 AlterType,
36 TxnStart,
38 TxnCommit,
40 TxnRollback,
42 Put,
44 DropCol,
46 RenameCol,
48 JsonTable,
50 Export,
52 Truncate,
54 Explain,
56 ExplainAnalyze,
58 Lock,
60 CreateMaterializedView,
62 RefreshMaterializedView,
64 DropMaterializedView,
66 Listen,
68 Notify,
70 Unlisten,
72 Savepoint,
74 ReleaseSavepoint,
76 RollbackToSavepoint,
78 CreateView,
80 DropView,
82 Search,
84 Upsert,
86 Scroll,
88 CreateCollection,
90 DeleteCollection,
92 CreateFunction,
94 DropFunction,
96 CreateTrigger,
98 DropTrigger,
100 CreateExtension,
102 DropExtension,
104 CommentOn,
106 CreateSequence,
108 DropSequence,
110 CreateEnum,
112 DropEnum,
114 AlterEnumAddValue,
116 AlterSetNotNull,
118 AlterDropNotNull,
120 AlterSetDefault,
122 AlterDropDefault,
124 AlterEnableRls,
126 AlterDisableRls,
128 AlterForceRls,
130 AlterNoForceRls,
132 Call,
135 Do,
137 SessionSet,
139 SessionShow,
141 SessionReset,
143 CreateDatabase,
145 DropDatabase,
147 Grant,
149 Revoke,
151 CreatePolicy,
153 DropPolicy,
155}
156
157impl std::fmt::Display for Action {
158 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
159 match self {
160 Action::Get => write!(f, "GET"),
161 Action::Cnt => write!(f, "CNT"),
162 Action::Set => write!(f, "SET"),
163 Action::Del => write!(f, "DEL"),
164 Action::Add => write!(f, "ADD"),
165 Action::Gen => write!(f, "GEN"),
166 Action::Make => write!(f, "MAKE"),
167 Action::Drop => write!(f, "DROP"),
168 Action::Mod => write!(f, "MOD"),
169 Action::Over => write!(f, "OVER"),
170 Action::With => write!(f, "WITH"),
171 Action::Index => write!(f, "INDEX"),
172 Action::DropIndex => write!(f, "DROP_INDEX"),
173 Action::Alter => write!(f, "ALTER"),
174 Action::AlterDrop => write!(f, "ALTER_DROP"),
175 Action::AlterType => write!(f, "ALTER_TYPE"),
176 Action::TxnStart => write!(f, "TXN_START"),
177 Action::TxnCommit => write!(f, "TXN_COMMIT"),
178 Action::TxnRollback => write!(f, "TXN_ROLLBACK"),
179 Action::Put => write!(f, "PUT"),
180 Action::DropCol => write!(f, "DROP_COL"),
181 Action::RenameCol => write!(f, "RENAME_COL"),
182 Action::JsonTable => write!(f, "JSON_TABLE"),
183 Action::Export => write!(f, "EXPORT"),
184 Action::Truncate => write!(f, "TRUNCATE"),
185 Action::Explain => write!(f, "EXPLAIN"),
186 Action::ExplainAnalyze => write!(f, "EXPLAIN_ANALYZE"),
187 Action::Lock => write!(f, "LOCK"),
188 Action::CreateMaterializedView => write!(f, "CREATE_MATERIALIZED_VIEW"),
189 Action::RefreshMaterializedView => write!(f, "REFRESH_MATERIALIZED_VIEW"),
190 Action::DropMaterializedView => write!(f, "DROP_MATERIALIZED_VIEW"),
191 Action::Listen => write!(f, "LISTEN"),
192 Action::Notify => write!(f, "NOTIFY"),
193 Action::Unlisten => write!(f, "UNLISTEN"),
194 Action::Savepoint => write!(f, "SAVEPOINT"),
195 Action::ReleaseSavepoint => write!(f, "RELEASE_SAVEPOINT"),
196 Action::RollbackToSavepoint => write!(f, "ROLLBACK_TO_SAVEPOINT"),
197 Action::CreateView => write!(f, "CREATE_VIEW"),
198 Action::DropView => write!(f, "DROP_VIEW"),
199 Action::Search => write!(f, "SEARCH"),
200 Action::Upsert => write!(f, "UPSERT"),
201 Action::Scroll => write!(f, "SCROLL"),
202 Action::CreateCollection => write!(f, "CREATE_COLLECTION"),
203 Action::DeleteCollection => write!(f, "DELETE_COLLECTION"),
204 Action::CreateFunction => write!(f, "CREATE_FUNCTION"),
205 Action::DropFunction => write!(f, "DROP_FUNCTION"),
206 Action::CreateTrigger => write!(f, "CREATE_TRIGGER"),
207 Action::DropTrigger => write!(f, "DROP_TRIGGER"),
208 Action::CreateExtension => write!(f, "CREATE_EXTENSION"),
209 Action::DropExtension => write!(f, "DROP_EXTENSION"),
210 Action::CommentOn => write!(f, "COMMENT_ON"),
211 Action::CreateSequence => write!(f, "CREATE_SEQUENCE"),
212 Action::DropSequence => write!(f, "DROP_SEQUENCE"),
213 Action::CreateEnum => write!(f, "CREATE_ENUM"),
214 Action::DropEnum => write!(f, "DROP_ENUM"),
215 Action::AlterEnumAddValue => write!(f, "ALTER_ENUM_ADD_VALUE"),
216 Action::AlterSetNotNull => write!(f, "ALTER_SET_NOT_NULL"),
217 Action::AlterDropNotNull => write!(f, "ALTER_DROP_NOT_NULL"),
218 Action::AlterSetDefault => write!(f, "ALTER_SET_DEFAULT"),
219 Action::AlterDropDefault => write!(f, "ALTER_DROP_DEFAULT"),
220 Action::AlterEnableRls => write!(f, "ALTER_ENABLE_RLS"),
221 Action::AlterDisableRls => write!(f, "ALTER_DISABLE_RLS"),
222 Action::AlterForceRls => write!(f, "ALTER_FORCE_RLS"),
223 Action::AlterNoForceRls => write!(f, "ALTER_NO_FORCE_RLS"),
224 Action::Call => write!(f, "CALL"),
225 Action::Do => write!(f, "DO"),
226 Action::SessionSet => write!(f, "SESSION_SET"),
227 Action::SessionShow => write!(f, "SESSION_SHOW"),
228 Action::SessionReset => write!(f, "SESSION_RESET"),
229 Action::CreateDatabase => write!(f, "CREATE_DATABASE"),
230 Action::DropDatabase => write!(f, "DROP_DATABASE"),
231 Action::Grant => write!(f, "GRANT"),
232 Action::Revoke => write!(f, "REVOKE"),
233 Action::CreatePolicy => write!(f, "CREATE_POLICY"),
234 Action::DropPolicy => write!(f, "DROP_POLICY"),
235 }
236 }
237}
238
239#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
241pub enum LogicalOp {
242 #[default]
243 And,
245 Or,
247}
248
249#[derive(Debug, Clone, Copy, PartialEq, Eq)]
251pub enum SortOrder {
252 Asc,
254 Desc,
256 AscNullsFirst,
258 AscNullsLast,
260 DescNullsFirst,
262 DescNullsLast,
264}
265
266#[derive(Debug, Clone, Copy, PartialEq, Eq)]
268pub enum Operator {
269 Eq,
271 Ne,
273 Gt,
275 Gte,
277 Lt,
279 Lte,
281 Fuzzy,
283 In,
285 NotIn,
287 IsNull,
289 IsNotNull,
291 Contains,
293 KeyExists,
295 JsonExists,
297 JsonQuery,
299 JsonValue,
301 Like,
303 NotLike,
305 ILike,
307 NotILike,
309 Between,
311 NotBetween,
313 Exists,
315 NotExists,
317 Regex,
319 RegexI,
321 SimilarTo,
323 ContainedBy,
325 Overlaps,
327 TextSearch,
329 KeyExistsAny,
331 KeyExistsAll,
333 JsonPath,
335 JsonPathText,
337 ArrayElemContainedInText,
340}
341
342impl Operator {
343 pub fn sql_symbol(&self) -> &'static str {
346 match self {
347 Operator::Eq => "=",
348 Operator::Ne => "!=",
349 Operator::Gt => ">",
350 Operator::Gte => ">=",
351 Operator::Lt => "<",
352 Operator::Lte => "<=",
353 Operator::Fuzzy => "ILIKE",
354 Operator::In => "IN",
355 Operator::NotIn => "NOT IN",
356 Operator::IsNull => "IS NULL",
357 Operator::IsNotNull => "IS NOT NULL",
358 Operator::Contains => "@>",
359 Operator::KeyExists => "?",
360 Operator::JsonExists => "JSON_EXISTS",
361 Operator::JsonQuery => "JSON_QUERY",
362 Operator::JsonValue => "JSON_VALUE",
363 Operator::Like => "LIKE",
364 Operator::NotLike => "NOT LIKE",
365 Operator::ILike => "ILIKE",
366 Operator::NotILike => "NOT ILIKE",
367 Operator::Between => "BETWEEN",
368 Operator::NotBetween => "NOT BETWEEN",
369 Operator::Exists => "EXISTS",
370 Operator::NotExists => "NOT EXISTS",
371 Operator::Regex => "~",
372 Operator::RegexI => "~*",
373 Operator::SimilarTo => "SIMILAR TO",
374 Operator::ContainedBy => "<@",
375 Operator::Overlaps => "&&",
376 Operator::TextSearch => "@@",
377 Operator::KeyExistsAny => "?|",
378 Operator::KeyExistsAll => "?&",
379 Operator::JsonPath => "#>",
380 Operator::JsonPathText => "#>>",
381 Operator::ArrayElemContainedInText => "CONTAINS_ANY_TOKEN",
382 }
383 }
384
385 pub fn needs_value(&self) -> bool {
387 !matches!(
388 self,
389 Operator::IsNull | Operator::IsNotNull | Operator::Exists | Operator::NotExists
390 )
391 }
392
393 pub fn is_simple_binary(&self) -> bool {
395 matches!(
396 self,
397 Operator::Eq
398 | Operator::Ne
399 | Operator::Gt
400 | Operator::Gte
401 | Operator::Lt
402 | Operator::Lte
403 | Operator::Like
404 | Operator::NotLike
405 | Operator::ILike
406 | Operator::NotILike
407 )
408 }
409}
410
411#[derive(Debug, Clone, Copy, PartialEq, Eq)]
413pub enum AggregateFunc {
414 Count,
416 Sum,
418 Avg,
420 Min,
422 Max,
424 ArrayAgg,
426 StringAgg,
428 JsonAgg,
430 JsonbAgg,
432 BoolAnd,
434 BoolOr,
436}
437
438impl std::fmt::Display for AggregateFunc {
439 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
440 match self {
441 AggregateFunc::Count => write!(f, "COUNT"),
442 AggregateFunc::Sum => write!(f, "SUM"),
443 AggregateFunc::Avg => write!(f, "AVG"),
444 AggregateFunc::Min => write!(f, "MIN"),
445 AggregateFunc::Max => write!(f, "MAX"),
446 AggregateFunc::ArrayAgg => write!(f, "ARRAY_AGG"),
447 AggregateFunc::StringAgg => write!(f, "STRING_AGG"),
448 AggregateFunc::JsonAgg => write!(f, "JSON_AGG"),
449 AggregateFunc::JsonbAgg => write!(f, "JSONB_AGG"),
450 AggregateFunc::BoolAnd => write!(f, "BOOL_AND"),
451 AggregateFunc::BoolOr => write!(f, "BOOL_OR"),
452 }
453 }
454}
455
456#[derive(Debug, Clone, PartialEq)]
458pub enum JoinKind {
459 Inner,
461 Left,
463 Right,
465 Lateral,
467 Full,
469 Cross,
471}
472
473#[derive(Debug, Clone, Copy, PartialEq, Eq)]
475pub enum SetOp {
476 Union,
478 UnionAll,
480 Intersect,
482 Except,
484}
485
486#[derive(Debug, Clone, PartialEq)]
488pub enum ModKind {
489 Add,
491 Drop,
493}
494
495#[derive(Debug, Clone, PartialEq, Eq, Default)]
497pub enum GroupByMode {
498 #[default]
499 Simple,
501 Rollup,
503 Cube,
505 GroupingSets(Vec<Vec<String>>),
507}
508
509impl GroupByMode {
510 pub fn is_simple(&self) -> bool {
512 matches!(self, GroupByMode::Simple)
513 }
514}
515
516#[derive(Debug, Clone, Copy, PartialEq, Eq)]
518pub enum LockMode {
519 Update,
521 NoKeyUpdate,
523 Share,
525 KeyShare,
527}
528
529#[derive(Debug, Clone, Copy, PartialEq, Eq)]
531pub enum OverridingKind {
532 SystemValue,
534 UserValue,
536}
537
538#[derive(Debug, Clone, Copy, PartialEq, Eq)]
540pub enum SampleMethod {
541 Bernoulli,
543 System,
545}
546
547#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
549pub enum Distance {
550 #[default]
551 Cosine,
553 Euclid,
555 Dot,
557}