1use serde::Serialize;
8use text_size::TextRange;
9
10#[derive(Debug, Clone, Serialize)]
11pub struct Statement {
12 pub range: TextRange,
13 pub kind: StatementKind,
14}
15
16#[derive(Debug, Clone, Serialize)]
17pub enum StatementKind {
18 Select(SelectStmt),
19 Insert(InsertStmt),
20 Update(UpdateStmt),
21 Delete(DeleteStmt),
22 CreateTable(CreateTableStmt),
23 AlterTable(AlterTableStmt),
24 DropTable(DropTableStmt),
25 Unknown {
27 text: String,
28 },
29}
30
31#[derive(Debug, Clone, Default, Serialize)]
36pub struct SelectStmt {
37 pub projections: Vec<Projection>,
38 pub from: Vec<TableRef>,
39 pub joins: Vec<JoinClause>,
40 pub where_clause: Option<Expr>,
41 #[serde(default)]
46 pub cte_names: Vec<String>,
47}
48
49#[derive(Debug, Clone, Serialize)]
50pub enum Projection {
51 Star,
52 QualifiedStar(String),
53 Expr { expr: Expr, alias: Option<String> },
54}
55
56#[derive(Debug, Clone, Serialize, Default)]
61pub struct TableRef {
62 pub schema: Option<String>,
64 pub name: String,
65 pub alias: Option<String>,
66 pub range: TextRange,
67}
68
69#[derive(Debug, Clone, Serialize)]
70pub struct JoinClause {
71 pub kind: JoinKind,
72 pub table: TableRef,
73 pub on: Option<Expr>,
74}
75
76#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
77pub enum JoinKind {
78 Inner,
79 Left,
80 Right,
81 Full,
82 Cross,
83}
84
85#[derive(Debug, Clone, Serialize)]
90pub enum Expr {
91 Column {
92 qualifier: Option<String>,
93 name: String,
94 range: TextRange,
95 },
96 Literal(String),
97 BinaryOp {
98 op: String,
99 left: Box<Expr>,
100 right: Box<Expr>,
101 },
102 Call {
103 name: String,
104 args: Vec<Expr>,
105 },
106 Other(String),
108 List(Vec<Expr>),
114}
115
116#[derive(Debug, Clone, Default, Serialize)]
121pub struct InsertStmt {
122 pub table: TableRef,
123 pub columns: Vec<String>,
124}
125
126#[derive(Debug, Clone, Default, Serialize)]
127pub struct UpdateStmt {
128 pub table: TableRef,
129 pub assignments: Vec<(String, Expr)>,
130 pub where_clause: Option<Expr>,
131 pub from_tables: Vec<TableRef>,
134}
135
136#[derive(Debug, Clone, Default, Serialize)]
137pub struct DeleteStmt {
138 pub table: TableRef,
139 pub where_clause: Option<Expr>,
140 pub using_tables: Vec<TableRef>,
143}
144
145#[derive(Debug, Clone, Default, Serialize)]
150pub struct CreateTableStmt {
151 pub table: TableRef,
152 pub if_not_exists: bool,
153 pub columns: Vec<ColumnDef>,
154}
155
156#[derive(Debug, Clone, Serialize)]
157pub struct ColumnDef {
158 pub name: String,
159 pub type_name: String,
160 pub nullable: bool,
161 pub default: Option<String>,
162 pub range: TextRange,
163}
164
165#[derive(Debug, Clone, Default, Serialize)]
166pub struct AlterTableStmt {
167 pub table: TableRef,
168}
169
170#[derive(Debug, Clone, Default, Serialize)]
171pub struct DropTableStmt {
172 pub tables: Vec<TableRef>,
173 pub if_exists: bool,
174}