reinhardt_query/query/
drop_index.rs1use crate::{
6 backend::QueryBuilder,
7 types::{DynIden, IntoIden, IntoTableRef, TableRef},
8};
9
10use super::traits::{QueryBuilderTrait, QueryStatementBuilder, QueryStatementWriter};
11
12#[derive(Debug, Clone)]
27pub struct DropIndexStatement {
28 pub(crate) name: Option<DynIden>,
29 pub(crate) table: Option<TableRef>,
30 pub(crate) if_exists: bool,
31 pub(crate) cascade: bool,
32 pub(crate) restrict: bool,
33}
34
35impl DropIndexStatement {
36 pub fn new() -> Self {
38 Self {
39 name: None,
40 table: None,
41 if_exists: false,
42 cascade: false,
43 restrict: false,
44 }
45 }
46
47 pub fn take(&mut self) -> Self {
49 Self {
50 name: self.name.take(),
51 table: self.table.take(),
52 if_exists: self.if_exists,
53 cascade: self.cascade,
54 restrict: self.restrict,
55 }
56 }
57
58 pub fn name<T>(&mut self, name: T) -> &mut Self
69 where
70 T: IntoIden,
71 {
72 self.name = Some(name.into_iden());
73 self
74 }
75
76 pub fn table<T>(&mut self, tbl: T) -> &mut Self
90 where
91 T: IntoTableRef,
92 {
93 self.table = Some(tbl.into_table_ref());
94 self
95 }
96
97 pub fn if_exists(&mut self) -> &mut Self {
109 self.if_exists = true;
110 self
111 }
112
113 pub fn cascade(&mut self) -> &mut Self {
128 self.cascade = true;
129 self.restrict = false;
130 self
131 }
132
133 pub fn restrict(&mut self) -> &mut Self {
148 self.restrict = true;
149 self.cascade = false;
150 self
151 }
152}
153
154impl Default for DropIndexStatement {
155 fn default() -> Self {
156 Self::new()
157 }
158}
159
160impl QueryStatementBuilder for DropIndexStatement {
161 fn build_any(&self, query_builder: &dyn QueryBuilderTrait) -> (String, crate::value::Values) {
162 use std::any::Any;
164 if let Some(builder) =
165 (query_builder as &dyn Any).downcast_ref::<crate::backend::PostgresQueryBuilder>()
166 {
167 return builder.build_drop_index(self);
168 }
169 if let Some(builder) =
170 (query_builder as &dyn Any).downcast_ref::<crate::backend::MySqlQueryBuilder>()
171 {
172 return builder.build_drop_index(self);
173 }
174 if let Some(builder) =
175 (query_builder as &dyn Any).downcast_ref::<crate::backend::SqliteQueryBuilder>()
176 {
177 return builder.build_drop_index(self);
178 }
179 panic!("Unsupported query builder type");
180 }
181}
182
183impl QueryStatementWriter for DropIndexStatement {}