1use crate::Expression;
12
13#[derive(Debug, Clone, PartialEq)]
15pub struct CreateSchemaStmt {
16 pub schema_name: String,
17 pub if_not_exists: bool,
18 pub schema_elements: Vec<SchemaElement>,
19}
20
21#[derive(Debug, Clone, PartialEq)]
23pub enum SchemaElement {
24 CreateTable(super::table::CreateTableStmt),
25 }
27
28#[derive(Debug, Clone, PartialEq)]
30pub struct DropSchemaStmt {
31 pub schema_name: String,
32 pub if_exists: bool,
33 pub cascade: bool,
34}
35
36#[derive(Debug, Clone, PartialEq)]
38pub struct SetSchemaStmt {
39 pub schema_name: String,
40}
41
42#[derive(Debug, Clone, PartialEq)]
44pub struct SetCatalogStmt {
45 pub catalog_name: String,
46}
47
48#[derive(Debug, Clone, PartialEq)]
50pub struct SetNamesStmt {
51 pub charset_name: String,
52 pub collation: Option<String>,
53}
54
55#[derive(Debug, Clone, PartialEq)]
57pub struct SetTimeZoneStmt {
58 pub zone: TimeZoneSpec,
59}
60
61#[derive(Debug, Clone, PartialEq)]
63pub enum TimeZoneSpec {
64 Local,
65 Interval(String), }
67
68#[derive(Debug, Clone, PartialEq)]
71pub struct SetVariableStmt {
72 pub scope: VariableScope,
73 pub variable: String,
74 pub value: Expression,
75}
76
77#[derive(Debug, Clone, PartialEq)]
79pub enum VariableScope {
80 Session, Global, }
83
84#[derive(Debug, Clone, PartialEq)]
86pub struct CreateRoleStmt {
87 pub role_name: String,
88}
89
90#[derive(Debug, Clone, PartialEq)]
92pub struct DropRoleStmt {
93 pub role_name: String,
94}
95
96#[derive(Debug, Clone, PartialEq)]
98pub struct CreateViewStmt {
99 pub view_name: String,
100 pub columns: Option<Vec<String>>,
101 pub query: Box<crate::SelectStmt>,
102 pub with_check_option: bool,
103 pub or_replace: bool,
104 pub if_not_exists: bool,
106 pub temporary: bool,
108 pub sql_definition: Option<String>,
111}
112
113#[derive(Debug, Clone, PartialEq)]
115pub struct DropViewStmt {
116 pub view_name: String,
117 pub if_exists: bool,
118 pub cascade: bool,
119 pub restrict: bool,
124}
125
126#[derive(Debug, Clone, PartialEq)]
128pub struct CreateTriggerStmt {
129 pub trigger_name: String,
130 pub timing: TriggerTiming,
131 pub event: TriggerEvent,
132 pub table_name: String,
133 pub granularity: TriggerGranularity,
134 pub when_condition: Option<Box<Expression>>,
135 pub triggered_action: TriggerAction,
136}
137
138#[derive(Debug, Clone, PartialEq)]
140pub enum TriggerTiming {
141 Before,
142 After,
143 InsteadOf,
144}
145
146#[derive(Debug, Clone, PartialEq)]
148pub enum TriggerEvent {
149 Insert,
150 Update(Option<Vec<String>>), Delete,
152}
153
154#[derive(Debug, Clone, PartialEq)]
156pub enum TriggerGranularity {
157 Row, Statement, }
160
161#[derive(Debug, Clone, PartialEq)]
163pub enum TriggerAction {
164 RawSql(String),
166 }
169
170#[derive(Debug, Clone, PartialEq)]
172pub struct DropTriggerStmt {
173 pub trigger_name: String,
174 pub cascade: bool,
175}
176
177#[derive(Debug, Clone, PartialEq)]
179pub struct AlterTriggerStmt {
180 pub trigger_name: String,
181 pub action: AlterTriggerAction,
182}
183
184#[derive(Debug, Clone, PartialEq)]
186pub enum AlterTriggerAction {
187 Enable,
188 Disable,
189}
190
191#[derive(Debug, Clone, PartialEq)]
193pub struct CreateIndexStmt {
194 pub if_not_exists: bool,
195 pub index_name: String,
196 pub table_name: String,
197 pub index_type: IndexType,
198 pub columns: Vec<IndexColumn>,
199}
200
201#[derive(Debug, Clone, PartialEq)]
203pub enum IndexType {
204 BTree { unique: bool },
206 Fulltext,
208 Spatial,
210 IVFFlat {
212 metric: VectorDistanceMetric,
214 lists: u32,
216 },
217 Hnsw {
219 metric: VectorDistanceMetric,
221 m: u32,
223 ef_construction: u32,
225 },
226}
227
228#[derive(Debug, Clone, Copy, PartialEq, Eq)]
230pub enum VectorDistanceMetric {
231 L2,
233 Cosine,
235 InnerProduct,
237}
238
239#[derive(Debug, Clone, PartialEq)]
241pub enum IndexColumn {
242 Column {
244 column_name: String,
245 direction: crate::select::OrderDirection,
246 prefix_length: Option<u64>,
249 },
250 Expression { expr: Box<Expression>, direction: crate::select::OrderDirection },
253}
254
255impl IndexColumn {
256 pub fn new_column(column_name: String, direction: crate::select::OrderDirection) -> Self {
258 IndexColumn::Column { column_name, direction, prefix_length: None }
259 }
260
261 pub fn new_column_with_prefix(
263 column_name: String,
264 direction: crate::select::OrderDirection,
265 prefix_length: u64,
266 ) -> Self {
267 IndexColumn::Column { column_name, direction, prefix_length: Some(prefix_length) }
268 }
269
270 pub fn new_expression(expr: Expression, direction: crate::select::OrderDirection) -> Self {
272 IndexColumn::Expression { expr: Box::new(expr), direction }
273 }
274
275 pub fn column_name(&self) -> Option<&str> {
277 match self {
278 IndexColumn::Column { column_name, .. } => Some(column_name),
279 IndexColumn::Expression { .. } => None,
280 }
281 }
282
283 pub fn expect_column_name(&self) -> &str {
286 match self {
287 IndexColumn::Column { column_name, .. } => column_name,
288 IndexColumn::Expression { .. } => {
289 panic!("Expression indexes are not supported in this context")
290 }
291 }
292 }
293
294 pub fn direction(&self) -> crate::select::OrderDirection {
296 match self {
297 IndexColumn::Column { direction, .. } => direction.clone(),
298 IndexColumn::Expression { direction, .. } => direction.clone(),
299 }
300 }
301
302 pub fn prefix_length(&self) -> Option<u64> {
304 match self {
305 IndexColumn::Column { prefix_length, .. } => *prefix_length,
306 IndexColumn::Expression { .. } => None,
307 }
308 }
309
310 pub fn is_expression(&self) -> bool {
312 matches!(self, IndexColumn::Expression { .. })
313 }
314
315 pub fn get_expression(&self) -> Option<&Expression> {
317 match self {
318 IndexColumn::Expression { expr, .. } => Some(expr),
319 IndexColumn::Column { .. } => None,
320 }
321 }
322}
323
324#[derive(Debug, Clone, PartialEq)]
326pub struct DropIndexStmt {
327 pub if_exists: bool,
328 pub index_name: String,
329}
330
331#[derive(Debug, Clone, PartialEq)]
336pub struct ReindexStmt {
337 pub target: Option<String>,
339}
340
341#[derive(Debug, Clone, PartialEq)]
349pub struct AnalyzeStmt {
350 pub table_name: Option<String>,
352 pub columns: Option<Vec<String>>,
354}
355
356#[derive(Debug, Clone, PartialEq)]
368pub struct PragmaStmt {
369 pub database: Option<String>,
371 pub name: String,
373 pub value: Option<PragmaValue>,
375}
376
377#[derive(Debug, Clone, PartialEq)]
379pub enum PragmaValue {
380 Identifier(String),
382 String(String),
384 Number(String),
386 SignedNumber(String),
388}