surrealdb_sql/statements/remove/
namespace.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 RemoveNamespaceStatement {
14 pub name: Ident,
15}
16
17impl RemoveNamespaceStatement {
18 pub(crate) async fn compute(
20 &self,
21 _ctx: &Context<'_>,
22 opt: &Options,
23 txn: &Transaction,
24 ) -> Result<Value, Error> {
25 opt.is_allowed(Action::Edit, ResourceKind::Namespace, &Base::Root)?;
27 let mut run = txn.lock().await;
29 run.clear_cache();
31 let key = crate::key::root::ns::new(&self.name);
33 run.del(key).await?;
34 let key = crate::key::namespace::all::new(&self.name);
36 run.delp(key, u32::MAX).await?;
37 Ok(Value::None)
39 }
40}
41
42impl Display for RemoveNamespaceStatement {
43 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
44 write!(f, "REMOVE NAMESPACE {}", self.name)
45 }
46}