1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Keyword {
6 Select,
7 Distinct,
8 From,
9 Where,
10 Insert,
11 Into,
12 Replace,
13 Ignore,
14 Update,
15 Delete,
16 Duplicate,
17 Create,
18 Table,
19 Truncate,
20 Drop,
21 Alter,
22 And,
23 Or,
24 Not,
25 Null,
26 True,
27 False,
28 As,
29 Join,
30 Left,
31 Right,
32 Inner,
33 Outer,
34 Cross,
35 Full,
36 Natural,
37 On,
38 Group,
39 By,
40 Rollup,
42 Cube,
43 Sets,
44 Grouping,
45 GroupingId,
46 Having,
47 Order,
48 Asc,
49 Desc,
50 Limit,
51 Offset,
52 Set,
53 Values,
54 In,
55 Between,
56 Asymmetric,
57 Symmetric,
58 Like,
59 Exists,
60 If,
61 All,
62 Any,
63 Some,
64 Union,
65 Intersect,
66 Except,
67 With,
68 Recursive,
69 Date,
70 Time,
71 Timestamp,
72 Interval,
73 Cast,
74 Case,
76 When,
77 Then,
78 Else,
79 End,
80 Over,
82 Partition,
83 Rows,
84 Range,
85 Preceding,
86 Following,
87 Unbounded,
88 Current,
89 Primary,
92 Foreign,
93 Key,
94 Unique,
95 Check,
96 References,
97 Is,
99 Begin,
101 Commit,
102 Rollback,
103 Cascade,
105 Restrict,
106 Schema,
107 Start,
108 Transaction,
109 Add,
111 Column,
112 Constraint,
113 Default,
114 Rename,
115 Modify,
116 Change,
117 Savepoint,
119 Release,
120 To,
121 Role,
123 Both,
125 Leading,
126 Trailing,
127 Div,
129 Varying,
131 Characters,
132 Octets,
133 Using,
134 For,
136 CurrentDate,
138 CurrentTime,
139 CurrentTimestamp,
140 Grant,
142 Privileges,
143 Usage,
144 Option,
145 Revoke,
147 Granted,
148 Execute,
150 Trigger,
151 Under,
152 Domain,
154 Sequence,
155 Type,
156 Collation,
157 Character,
158 Translation,
159 View,
160 Index,
161 Analyze,
162 Reindex,
163 Explain,
164 Assertion,
165 Specific,
166 Before,
168 After,
169 Instead,
170 Of,
171 Each,
172 Row,
173 Statement,
174 Enable,
175 Disable,
176 Increment,
178 Minvalue,
179 Maxvalue,
180 Cycle,
181 No,
182 Restart,
183 Next,
184 Action,
186 Catalog,
188 Names,
189 Zone,
190 Local,
191 Session,
192 Global,
193 Year,
195 Quarter,
196 Month,
197 Week,
198 Day,
199 Hour,
200 Minute,
201 Second,
202 Microsecond,
203 Function,
205 Procedure,
206 Call,
207 Routine,
208 Method,
209 Constructor,
210 Static,
211 Instance,
212 Out,
214 InOut,
215 Returns,
217 While,
218 Do,
219 Loop,
220 Repeat,
221 Until,
222 Return,
223 Leave,
224 Iterate,
225 Deterministic,
227 Language,
228 Sql,
229 Security,
230 Definer,
231 Invoker,
232 Get,
234 Pad,
235 Space,
236 Collate,
237 Declare,
239 Cursor,
240 Insensitive,
241 Prepare,
243 Deallocate,
244 Scroll,
245 Hold,
246 Without,
247 Read,
248 Only,
249 Oids,
250 Open,
251 Fetch,
252 Close,
253 Prior,
254 First,
255 Last,
256 Absolute,
257 Relative,
258 Serializable,
259 Isolation,
260 Level,
261 Write,
262 Comment,
263 KeyBlockSize,
265 Connection,
266 InsertMethod,
267 RowFormat,
268 DelayKeyWrite,
269 TableChecksum,
270 Checksum,
271 StatsSamplePages,
272 Password,
273 AvgRowLength,
274 MinRows,
275 MaxRows,
276 SecondaryEngine,
277 Dynamic,
279 Fixed,
280 Compressed,
281 Redundant,
282 Compact,
283 Fulltext,
285 Match,
286 Against,
287 Boolean,
288 Expansion,
289 Mode,
290 Query,
291 Spatial,
293 Ivfflat,
295 Hnsw,
296 Lists,
297 Probes,
298 EfConstruction,
299 EfSearch,
300 M,
301 Show,
303 Describe,
304 Databases,
305 Tables,
306 Columns,
307 Fields,
308 Indexes,
309 Keys,
310 AutoIncrement,
312 Temp,
314 Temporary,
315 Storage,
317 Columnar,
318}
319
320impl Keyword {
321 pub fn can_be_identifier(&self) -> bool {
327 matches!(
328 self,
329 Keyword::Timestamp | Keyword::Date | Keyword::Time | Keyword::Interval |
331 Keyword::Year | Keyword::Quarter | Keyword::Month | Keyword::Week |
333 Keyword::Day | Keyword::Hour | Keyword::Minute | Keyword::Second |
334 Keyword::Microsecond
335 )
336 }
337}
338
339impl fmt::Display for Keyword {
340 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
341 let keyword_str = match self {
342 Keyword::Select => "SELECT",
343 Keyword::Distinct => "DISTINCT",
344 Keyword::From => "FROM",
345 Keyword::Where => "WHERE",
346 Keyword::Insert => "INSERT",
347 Keyword::Into => "INTO",
348 Keyword::Replace => "REPLACE",
349 Keyword::Ignore => "IGNORE",
350 Keyword::Update => "UPDATE",
351 Keyword::Delete => "DELETE",
352 Keyword::Duplicate => "DUPLICATE",
353 Keyword::Create => "CREATE",
354 Keyword::Table => "TABLE",
355 Keyword::Truncate => "TRUNCATE",
356 Keyword::Drop => "DROP",
357 Keyword::Alter => "ALTER",
358 Keyword::And => "AND",
359 Keyword::Or => "OR",
360 Keyword::Not => "NOT",
361 Keyword::Null => "NULL",
362 Keyword::True => "TRUE",
363 Keyword::False => "FALSE",
364 Keyword::As => "AS",
365 Keyword::Join => "JOIN",
366 Keyword::Left => "LEFT",
367 Keyword::Right => "RIGHT",
368 Keyword::Inner => "INNER",
369 Keyword::Outer => "OUTER",
370 Keyword::Cross => "CROSS",
371 Keyword::Full => "FULL",
372 Keyword::Natural => "NATURAL",
373 Keyword::On => "ON",
374 Keyword::Group => "GROUP",
375 Keyword::By => "BY",
376 Keyword::Rollup => "ROLLUP",
377 Keyword::Cube => "CUBE",
378 Keyword::Sets => "SETS",
379 Keyword::Grouping => "GROUPING",
380 Keyword::GroupingId => "GROUPING_ID",
381 Keyword::Having => "HAVING",
382 Keyword::Order => "ORDER",
383 Keyword::Asc => "ASC",
384 Keyword::Desc => "DESC",
385 Keyword::Limit => "LIMIT",
386 Keyword::Offset => "OFFSET",
387 Keyword::Set => "SET",
388 Keyword::Values => "VALUES",
389 Keyword::In => "IN",
390 Keyword::Between => "BETWEEN",
391 Keyword::Asymmetric => "ASYMMETRIC",
392 Keyword::Symmetric => "SYMMETRIC",
393 Keyword::Like => "LIKE",
394 Keyword::Exists => "EXISTS",
395 Keyword::If => "IF",
396 Keyword::All => "ALL",
397 Keyword::Any => "ANY",
398 Keyword::Some => "SOME",
399 Keyword::Union => "UNION",
400 Keyword::Intersect => "INTERSECT",
401 Keyword::Except => "EXCEPT",
402 Keyword::With => "WITH",
403 Keyword::Recursive => "RECURSIVE",
404 Keyword::Date => "DATE",
405 Keyword::Time => "TIME",
406 Keyword::Timestamp => "TIMESTAMP",
407 Keyword::Interval => "INTERVAL",
408 Keyword::Cast => "CAST",
409 Keyword::Case => "CASE",
410 Keyword::When => "WHEN",
411 Keyword::Then => "THEN",
412 Keyword::Else => "ELSE",
413 Keyword::End => "END",
414 Keyword::Over => "OVER",
415 Keyword::Partition => "PARTITION",
416 Keyword::Rows => "ROWS",
417 Keyword::Range => "RANGE",
418 Keyword::Preceding => "PRECEDING",
419 Keyword::Following => "FOLLOWING",
420 Keyword::Unbounded => "UNBOUNDED",
421 Keyword::Current => "CURRENT",
422 Keyword::Primary => "PRIMARY",
423 Keyword::Foreign => "FOREIGN",
424 Keyword::Key => "KEY",
425 Keyword::Unique => "UNIQUE",
426 Keyword::Check => "CHECK",
427 Keyword::References => "REFERENCES",
428 Keyword::Is => "IS",
429 Keyword::Begin => "BEGIN",
430 Keyword::Commit => "COMMIT",
431 Keyword::Rollback => "ROLLBACK",
432 Keyword::Cascade => "CASCADE",
433 Keyword::Restrict => "RESTRICT",
434 Keyword::Schema => "SCHEMA",
435 Keyword::Start => "START",
436 Keyword::Transaction => "TRANSACTION",
437 Keyword::Add => "ADD",
438 Keyword::Column => "COLUMN",
439 Keyword::Constraint => "CONSTRAINT",
440 Keyword::Default => "DEFAULT",
441 Keyword::Rename => "RENAME",
442 Keyword::Modify => "MODIFY",
443 Keyword::Change => "CHANGE",
444 Keyword::Savepoint => "SAVEPOINT",
445 Keyword::Release => "RELEASE",
446 Keyword::To => "TO",
447 Keyword::Role => "ROLE",
448 Keyword::Both => "BOTH",
449 Keyword::Leading => "LEADING",
450 Keyword::Trailing => "TRAILING",
451 Keyword::Div => "DIV",
452 Keyword::Varying => "VARYING",
453 Keyword::Characters => "CHARACTERS",
454 Keyword::Octets => "OCTETS",
455 Keyword::Using => "USING",
456 Keyword::For => "FOR",
457 Keyword::CurrentDate => "CURRENT_DATE",
458 Keyword::CurrentTime => "CURRENT_TIME",
459 Keyword::CurrentTimestamp => "CURRENT_TIMESTAMP",
460 Keyword::Grant => "GRANT",
461 Keyword::Privileges => "PRIVILEGES",
462 Keyword::Usage => "USAGE",
463 Keyword::Option => "OPTION",
464 Keyword::Revoke => "REVOKE",
465 Keyword::Granted => "GRANTED",
466 Keyword::Execute => "EXECUTE",
467 Keyword::Trigger => "TRIGGER",
468 Keyword::Under => "UNDER",
469 Keyword::Domain => "DOMAIN",
470 Keyword::Sequence => "SEQUENCE",
471 Keyword::Type => "TYPE",
472 Keyword::Collation => "COLLATION",
473 Keyword::Character => "CHARACTER",
474 Keyword::Translation => "TRANSLATION",
475 Keyword::View => "VIEW",
476 Keyword::Index => "INDEX",
477 Keyword::Analyze => "ANALYZE",
478 Keyword::Reindex => "REINDEX",
479 Keyword::Explain => "EXPLAIN",
480 Keyword::Assertion => "ASSERTION",
481 Keyword::Specific => "SPECIFIC",
482 Keyword::Before => "BEFORE",
483 Keyword::After => "AFTER",
484 Keyword::Instead => "INSTEAD",
485 Keyword::Of => "OF",
486 Keyword::Each => "EACH",
487 Keyword::Row => "ROW",
488 Keyword::Statement => "STATEMENT",
489 Keyword::Enable => "ENABLE",
490 Keyword::Disable => "DISABLE",
491 Keyword::Increment => "INCREMENT",
492 Keyword::Minvalue => "MINVALUE",
493 Keyword::Maxvalue => "MAXVALUE",
494 Keyword::Cycle => "CYCLE",
495 Keyword::No => "NO",
496 Keyword::Restart => "RESTART",
497 Keyword::Next => "NEXT",
498 Keyword::Action => "ACTION",
499 Keyword::Catalog => "CATALOG",
500 Keyword::Names => "NAMES",
501 Keyword::Zone => "ZONE",
502 Keyword::Local => "LOCAL",
503 Keyword::Session => "SESSION",
504 Keyword::Global => "GLOBAL",
505 Keyword::Year => "YEAR",
506 Keyword::Quarter => "QUARTER",
507 Keyword::Month => "MONTH",
508 Keyword::Week => "WEEK",
509 Keyword::Day => "DAY",
510 Keyword::Hour => "HOUR",
511 Keyword::Minute => "MINUTE",
512 Keyword::Second => "SECOND",
513 Keyword::Microsecond => "MICROSECOND",
514 Keyword::Function => "FUNCTION",
515 Keyword::Procedure => "PROCEDURE",
516 Keyword::Call => "CALL",
517 Keyword::Routine => "ROUTINE",
518 Keyword::Method => "METHOD",
519 Keyword::Constructor => "CONSTRUCTOR",
520 Keyword::Static => "STATIC",
521 Keyword::Instance => "INSTANCE",
522 Keyword::Out => "OUT",
523 Keyword::InOut => "INOUT",
524 Keyword::Returns => "RETURNS",
525 Keyword::While => "WHILE",
526 Keyword::Do => "DO",
527 Keyword::Loop => "LOOP",
528 Keyword::Repeat => "REPEAT",
529 Keyword::Until => "UNTIL",
530 Keyword::Return => "RETURN",
531 Keyword::Leave => "LEAVE",
532 Keyword::Iterate => "ITERATE",
533 Keyword::Deterministic => "DETERMINISTIC",
534 Keyword::Language => "LANGUAGE",
535 Keyword::Sql => "SQL",
536 Keyword::Security => "SECURITY",
537 Keyword::Definer => "DEFINER",
538 Keyword::Invoker => "INVOKER",
539 Keyword::Comment => "COMMENT",
540 Keyword::Get => "GET",
541 Keyword::Pad => "PAD",
542 Keyword::Space => "SPACE",
543 Keyword::Collate => "COLLATE",
544 Keyword::Declare => "DECLARE",
545 Keyword::Cursor => "CURSOR",
546 Keyword::Insensitive => "INSENSITIVE",
547 Keyword::Prepare => "PREPARE",
548 Keyword::Deallocate => "DEALLOCATE",
549 Keyword::Scroll => "SCROLL",
550 Keyword::Hold => "HOLD",
551 Keyword::Without => "WITHOUT",
552 Keyword::Read => "READ",
553 Keyword::Only => "ONLY",
554 Keyword::Oids => "OIDS",
555 Keyword::Open => "OPEN",
556 Keyword::Fetch => "FETCH",
557 Keyword::Close => "CLOSE",
558 Keyword::Prior => "PRIOR",
559 Keyword::First => "FIRST",
560 Keyword::Last => "LAST",
561 Keyword::Absolute => "ABSOLUTE",
562 Keyword::Relative => "RELATIVE",
563 Keyword::Serializable => "SERIALIZABLE",
564 Keyword::Isolation => "ISOLATION",
565 Keyword::Level => "LEVEL",
566 Keyword::Write => "WRITE",
567 Keyword::KeyBlockSize => "KEY_BLOCK_SIZE",
569 Keyword::Connection => "CONNECTION",
570 Keyword::InsertMethod => "INSERT_METHOD",
571 Keyword::RowFormat => "ROW_FORMAT",
572 Keyword::DelayKeyWrite => "DELAY_KEY_WRITE",
573 Keyword::TableChecksum => "TABLE_CHECKSUM",
574 Keyword::Checksum => "CHECKSUM",
575 Keyword::StatsSamplePages => "STATS_SAMPLE_PAGES",
576 Keyword::Password => "PASSWORD",
577 Keyword::AvgRowLength => "AVG_ROW_LENGTH",
578 Keyword::MinRows => "MIN_ROWS",
579 Keyword::MaxRows => "MAX_ROWS",
580 Keyword::SecondaryEngine => "SECONDARY_ENGINE",
581 Keyword::Dynamic => "DYNAMIC",
583 Keyword::Fixed => "FIXED",
584 Keyword::Compressed => "COMPRESSED",
585 Keyword::Redundant => "REDUNDANT",
586 Keyword::Compact => "COMPACT",
587 Keyword::Fulltext => "FULLTEXT",
589 Keyword::Match => "MATCH",
590 Keyword::Against => "AGAINST",
591 Keyword::Boolean => "BOOLEAN",
592 Keyword::Expansion => "EXPANSION",
593 Keyword::Mode => "MODE",
594 Keyword::Query => "QUERY",
595 Keyword::Spatial => "SPATIAL",
597 Keyword::Ivfflat => "IVFFLAT",
599 Keyword::Hnsw => "HNSW",
600 Keyword::Lists => "LISTS",
601 Keyword::Probes => "PROBES",
602 Keyword::EfConstruction => "EF_CONSTRUCTION",
603 Keyword::EfSearch => "EF_SEARCH",
604 Keyword::M => "M",
605 Keyword::Show => "SHOW",
607 Keyword::Describe => "DESCRIBE",
608 Keyword::Databases => "DATABASES",
609 Keyword::Tables => "TABLES",
610 Keyword::Columns => "COLUMNS",
611 Keyword::Fields => "FIELDS",
612 Keyword::Indexes => "INDEXES",
613 Keyword::Keys => "KEYS",
614 Keyword::AutoIncrement => "AUTO_INCREMENT",
616 Keyword::Temp => "TEMP",
618 Keyword::Temporary => "TEMPORARY",
619 Keyword::Storage => "STORAGE",
621 Keyword::Columnar => "COLUMNAR",
622 };
623 write!(f, "{}", keyword_str)
624 }
625}