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