1#[derive(Debug, Clone)]
9pub enum SqlExpression {
10 Column(String),
11 StringLiteral(String),
12 NumberLiteral(String),
13 BooleanLiteral(bool),
14 Null, DateTimeConstructor {
16 year: i32,
17 month: u32,
18 day: u32,
19 hour: Option<u32>,
20 minute: Option<u32>,
21 second: Option<u32>,
22 },
23 DateTimeToday {
24 hour: Option<u32>,
25 minute: Option<u32>,
26 second: Option<u32>,
27 },
28 MethodCall {
29 object: String,
30 method: String,
31 args: Vec<SqlExpression>,
32 },
33 ChainedMethodCall {
34 base: Box<SqlExpression>,
35 method: String,
36 args: Vec<SqlExpression>,
37 },
38 FunctionCall {
39 name: String,
40 args: Vec<SqlExpression>,
41 distinct: bool, },
43 WindowFunction {
44 name: String,
45 args: Vec<SqlExpression>,
46 window_spec: WindowSpec,
47 },
48 BinaryOp {
49 left: Box<SqlExpression>,
50 op: String,
51 right: Box<SqlExpression>,
52 },
53 InList {
54 expr: Box<SqlExpression>,
55 values: Vec<SqlExpression>,
56 },
57 NotInList {
58 expr: Box<SqlExpression>,
59 values: Vec<SqlExpression>,
60 },
61 Between {
62 expr: Box<SqlExpression>,
63 lower: Box<SqlExpression>,
64 upper: Box<SqlExpression>,
65 },
66 Not {
67 expr: Box<SqlExpression>,
68 },
69 CaseExpression {
70 when_branches: Vec<WhenBranch>,
71 else_branch: Option<Box<SqlExpression>>,
72 },
73}
74
75#[derive(Debug, Clone)]
76pub struct WhenBranch {
77 pub condition: Box<SqlExpression>,
78 pub result: Box<SqlExpression>,
79}
80
81#[derive(Debug, Clone)]
84pub struct WhereClause {
85 pub conditions: Vec<Condition>,
86}
87
88#[derive(Debug, Clone)]
89pub struct Condition {
90 pub expr: SqlExpression,
91 pub connector: Option<LogicalOp>, }
93
94#[derive(Debug, Clone)]
95pub enum LogicalOp {
96 And,
97 Or,
98}
99
100#[derive(Debug, Clone, PartialEq)]
103pub enum SortDirection {
104 Asc,
105 Desc,
106}
107
108#[derive(Debug, Clone)]
109pub struct OrderByColumn {
110 pub column: String,
111 pub direction: SortDirection,
112}
113
114#[derive(Debug, Clone)]
117pub struct WindowSpec {
118 pub partition_by: Vec<String>,
119 pub order_by: Vec<OrderByColumn>,
120}
121
122#[derive(Debug, Clone)]
126pub enum SelectItem {
127 Column(String),
129 Expression { expr: SqlExpression, alias: String },
131 Star,
133}
134
135#[derive(Debug, Clone)]
136pub struct SelectStatement {
137 pub distinct: bool, pub columns: Vec<String>, pub select_items: Vec<SelectItem>, pub from_table: Option<String>,
141 pub from_subquery: Option<Box<SelectStatement>>, pub from_function: Option<TableFunction>, pub from_alias: Option<String>, pub joins: Vec<JoinClause>, pub where_clause: Option<WhereClause>,
146 pub order_by: Option<Vec<OrderByColumn>>,
147 pub group_by: Option<Vec<String>>,
148 pub having: Option<SqlExpression>, pub limit: Option<usize>,
150 pub offset: Option<usize>,
151 pub ctes: Vec<CTE>, }
153
154#[derive(Debug, Clone)]
158pub enum TableFunction {
159 Range {
160 start: SqlExpression,
161 end: SqlExpression,
162 step: Option<SqlExpression>,
163 },
164}
165
166#[derive(Debug, Clone)]
168pub struct CTE {
169 pub name: String,
170 pub column_list: Option<Vec<String>>, pub query: SelectStatement,
172}
173
174#[derive(Debug, Clone)]
176pub enum TableSource {
177 Table(String), DerivedTable {
179 query: Box<SelectStatement>,
181 alias: String, },
183}
184
185#[derive(Debug, Clone, PartialEq)]
187pub enum JoinType {
188 Inner,
189 Left,
190 Right,
191 Full,
192 Cross,
193}
194
195#[derive(Debug, Clone, PartialEq)]
197pub enum JoinOperator {
198 Equal,
199 NotEqual,
200 LessThan,
201 GreaterThan,
202 LessThanOrEqual,
203 GreaterThanOrEqual,
204}
205
206#[derive(Debug, Clone)]
208pub struct JoinCondition {
209 pub left_column: String, pub operator: JoinOperator, pub right_column: String, }
213
214#[derive(Debug, Clone)]
216pub struct JoinClause {
217 pub join_type: JoinType,
218 pub table: TableSource, pub alias: Option<String>, pub condition: JoinCondition, }