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 ScalarSubquery {
76 query: Box<SelectStatement>,
77 },
78 InSubquery {
81 expr: Box<SqlExpression>,
82 subquery: Box<SelectStatement>,
83 },
84 NotInSubquery {
87 expr: Box<SqlExpression>,
88 subquery: Box<SelectStatement>,
89 },
90}
91
92#[derive(Debug, Clone)]
93pub struct WhenBranch {
94 pub condition: Box<SqlExpression>,
95 pub result: Box<SqlExpression>,
96}
97
98#[derive(Debug, Clone)]
101pub struct WhereClause {
102 pub conditions: Vec<Condition>,
103}
104
105#[derive(Debug, Clone)]
106pub struct Condition {
107 pub expr: SqlExpression,
108 pub connector: Option<LogicalOp>, }
110
111#[derive(Debug, Clone)]
112pub enum LogicalOp {
113 And,
114 Or,
115}
116
117#[derive(Debug, Clone, PartialEq)]
120pub enum SortDirection {
121 Asc,
122 Desc,
123}
124
125#[derive(Debug, Clone)]
126pub struct OrderByColumn {
127 pub column: String,
128 pub direction: SortDirection,
129}
130
131#[derive(Debug, Clone, PartialEq)]
135pub enum FrameBound {
136 UnboundedPreceding,
137 CurrentRow,
138 Preceding(i64),
139 Following(i64),
140 UnboundedFollowing,
141}
142
143#[derive(Debug, Clone, PartialEq)]
145pub enum FrameUnit {
146 Rows,
147 Range,
148}
149
150#[derive(Debug, Clone)]
152pub struct WindowFrame {
153 pub unit: FrameUnit,
154 pub start: FrameBound,
155 pub end: Option<FrameBound>, }
157
158#[derive(Debug, Clone)]
159pub struct WindowSpec {
160 pub partition_by: Vec<String>,
161 pub order_by: Vec<OrderByColumn>,
162 pub frame: Option<WindowFrame>, }
164
165#[derive(Debug, Clone)]
169pub enum SelectItem {
170 Column(String),
172 Expression { expr: SqlExpression, alias: String },
174 Star,
176}
177
178#[derive(Debug, Clone)]
179pub struct SelectStatement {
180 pub distinct: bool, pub columns: Vec<String>, pub select_items: Vec<SelectItem>, pub from_table: Option<String>,
184 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>,
189 pub order_by: Option<Vec<OrderByColumn>>,
190 pub group_by: Option<Vec<SqlExpression>>, pub having: Option<SqlExpression>, pub limit: Option<usize>,
193 pub offset: Option<usize>,
194 pub ctes: Vec<CTE>, }
196
197#[derive(Debug, Clone)]
201pub enum TableFunction {
202 Range {
203 start: SqlExpression,
204 end: SqlExpression,
205 step: Option<SqlExpression>,
206 },
207}
208
209#[derive(Debug, Clone)]
211pub struct CTE {
212 pub name: String,
213 pub column_list: Option<Vec<String>>, pub cte_type: CTEType,
215}
216
217#[derive(Debug, Clone)]
219pub enum CTEType {
220 Standard(SelectStatement),
221 Web(WebCTESpec),
222}
223
224#[derive(Debug, Clone)]
226pub struct WebCTESpec {
227 pub url: String,
228 pub format: Option<DataFormat>, pub headers: Vec<(String, String)>, pub cache_seconds: Option<u64>, }
232
233#[derive(Debug, Clone)]
235pub enum DataFormat {
236 CSV,
237 JSON,
238 Auto, }
240
241#[derive(Debug, Clone)]
243pub enum TableSource {
244 Table(String), DerivedTable {
246 query: Box<SelectStatement>,
248 alias: String, },
250}
251
252#[derive(Debug, Clone, PartialEq)]
254pub enum JoinType {
255 Inner,
256 Left,
257 Right,
258 Full,
259 Cross,
260}
261
262#[derive(Debug, Clone, PartialEq)]
264pub enum JoinOperator {
265 Equal,
266 NotEqual,
267 LessThan,
268 GreaterThan,
269 LessThanOrEqual,
270 GreaterThanOrEqual,
271}
272
273#[derive(Debug, Clone)]
275pub struct JoinCondition {
276 pub left_column: String, pub operator: JoinOperator, pub right_column: String, }
280
281#[derive(Debug, Clone)]
283pub struct JoinClause {
284 pub join_type: JoinType,
285 pub table: TableSource, pub alias: Option<String>, pub condition: JoinCondition, }