surrealdb_sql/statements/remove/
function.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};
10
11#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
12#[revisioned(revision = 1)]
13pub struct RemoveFunctionStatement {
14 pub name: Ident,
15}
16
17impl RemoveFunctionStatement {
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::Function, &Base::Db)?;
27 let mut run = txn.lock().await;
29 run.clear_cache();
31 let key = crate::key::database::fc::new(opt.ns(), opt.db(), &self.name);
33 run.del(key).await?;
34 Ok(Value::None)
36 }
37}
38
39impl Display for RemoveFunctionStatement {
40 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41 write!(f, "REMOVE FUNCTION fn::{}", self.name.0)
43 }
44}