|
17 | 17 | /// SQL Abstract Syntax Tree (AST)
|
18 | 18 | #[derive(Debug, Clone, PartialEq)]
|
19 | 19 | pub enum ASTNode {
|
| 20 | + /// Identifier e.g. table name or column name |
20 | 21 | SQLIdentifier(String),
|
| 22 | + /// Wildcard e.g. `*` |
21 | 23 | SQLWildcard,
|
| 24 | + /// Multi part identifier e.g. `myschema.dbo.mytable` |
22 | 25 | SQLCompoundIdentifier(Vec<String>),
|
| 26 | + /// Assigment e.g. `name = 'Fred'` in an UPDATE statement |
| 27 | + SQLAssignment(String, Box<ASTNode>), |
| 28 | + /// `IS NULL` expression |
23 | 29 | SQLIsNull(Box<ASTNode>),
|
| 30 | + /// `IS NOT NULL` expression |
24 | 31 | SQLIsNotNull(Box<ASTNode>),
|
| 32 | + /// Binary expression e.g. `1 + 1` or `foo > bar` |
25 | 33 | SQLBinaryExpr {
|
26 | 34 | left: Box<ASTNode>,
|
27 | 35 | op: SQLOperator,
|
28 | 36 | right: Box<ASTNode>,
|
29 | 37 | },
|
| 38 | + /// CAST an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))` |
30 | 39 | SQLCast {
|
31 | 40 | expr: Box<ASTNode>,
|
32 | 41 | data_type: SQLType,
|
33 | 42 | },
|
| 43 | + /// Nested expression e.g. `(foo > bar)` or `(1)` |
34 | 44 | SQLNested(Box<ASTNode>),
|
| 45 | + /// Unary expression |
35 | 46 | SQLUnary {
|
36 | 47 | operator: SQLOperator,
|
37 | 48 | rex: Box<ASTNode>,
|
38 | 49 | },
|
| 50 | + /// Literal signed long |
39 | 51 | SQLLiteralLong(i64),
|
| 52 | + /// Literal floating point value |
40 | 53 | SQLLiteralDouble(f64),
|
| 54 | + /// Literal string |
41 | 55 | SQLLiteralString(String),
|
| 56 | + /// Scalar function call e.g. `LEFT(foo, 5)` |
42 | 57 | SQLFunction {
|
43 | 58 | id: String,
|
44 | 59 | args: Vec<ASTNode>,
|
45 | 60 | },
|
| 61 | + /// Expression with ASC/DESC attribute e.g. `foo ASC` or `foo DESC`.= |
46 | 62 | SQLOrderBy {
|
47 | 63 | expr: Box<ASTNode>,
|
48 | 64 | asc: bool,
|
49 | 65 | },
|
| 66 | + /// SELECT |
50 | 67 | SQLSelect {
|
| 68 | + /// projection expressions |
51 | 69 | projection: Vec<ASTNode>,
|
| 70 | + /// FROM |
52 | 71 | relation: Option<Box<ASTNode>>,
|
| 72 | + /// WHERE |
53 | 73 | selection: Option<Box<ASTNode>>,
|
| 74 | + /// ORDER BY |
54 | 75 | order_by: Option<Vec<ASTNode>>,
|
| 76 | + /// GROUP BY |
55 | 77 | group_by: Option<Vec<ASTNode>>,
|
| 78 | + /// HAVING |
56 | 79 | having: Option<Box<ASTNode>>,
|
| 80 | + /// LIMIT |
57 | 81 | limit: Option<Box<ASTNode>>,
|
58 | 82 | },
|
| 83 | + /// INSERT |
| 84 | + SQLInsert { |
| 85 | + /// TABLE |
| 86 | + table_name: String, |
| 87 | + /// COLUMNS |
| 88 | + columns: Vec<String>, |
| 89 | + /// VALUES (vector of rows to insert) |
| 90 | + values: Vec<Vec<ASTNode>>, |
| 91 | + }, |
| 92 | + /// UPDATE |
| 93 | + SQLUpdate { |
| 94 | + /// TABLE |
| 95 | + table_name: String, |
| 96 | + /// Columns being assigned |
| 97 | + columns: Vec<String>, |
| 98 | + /// Values being assigned |
| 99 | + values: Vec<ASTNode>, |
| 100 | + /// WHERE |
| 101 | + selection: Option<Box<ASTNode>>, |
| 102 | + }, |
| 103 | + /// DELETE |
59 | 104 | SQLDelete {
|
60 |
| - relation: Option<Box<ASTNode>>, // FROM statement |
61 |
| - selection: Option<Box<ASTNode>>, // WHERE statement |
| 105 | + /// FROM |
| 106 | + relation: Option<Box<ASTNode>>, |
| 107 | + /// WHERE |
| 108 | + selection: Option<Box<ASTNode>>, |
| 109 | + /// ORDER BY |
62 | 110 | order_by: Option<Vec<ASTNode>>,
|
63 | 111 | limit: Option<Box<ASTNode>>,
|
64 | 112 | },
|
| 113 | + /// CREATE TABLE |
65 | 114 | SQLCreateTable {
|
66 | 115 | /// Table name
|
67 | 116 | name: String,
|
|
0 commit comments