surrealdb_sql/statements/remove/
index.rs1use crate::ctx::Context;
2use crate::dbs::{Options, Transaction};
3use crate::err::Error;
4use crate::iam::{Action, ResourceKind};
5use crate::{Base, Ident, Value};
6use derive::Store;
7use revision::revisioned;
8use serde::{Deserialize, Serialize};
9use std::fmt::{self, Display, Formatter};
10
11#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
12#[revisioned(revision = 1)]
13pub struct RemoveIndexStatement {
14 pub name: Ident,
15 pub what: Ident,
16}
17
18impl RemoveIndexStatement {
19 pub(crate) async fn compute(
21 &self,
22 _ctx: &Context<'_>,
23 opt: &Options,
24 txn: &Transaction,
25 ) -> Result<Value, Error> {
26 opt.is_allowed(Action::Edit, ResourceKind::Index, &Base::Db)?;
28 let mut run = txn.lock().await;
30 run.clear_cache();
32 let key = crate::key::table::ix::new(opt.ns(), opt.db(), &self.what, &self.name);
34 run.del(key).await?;
35 let key = crate::key::index::all::new(opt.ns(), opt.db(), &self.what, &self.name);
37 run.delp(key, u32::MAX).await?;
38 let key = crate::key::table::ix::prefix(opt.ns(), opt.db(), &self.what);
40 run.clr(key).await?;
41 Ok(Value::None)
43 }
44}
45
46impl Display for RemoveIndexStatement {
47 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
48 write!(f, "REMOVE INDEX {} ON {}", self.name, self.what)
49 }
50}