surrealdb/sql/statements/remove/
event.rs

1use crate::ctx::Context;
2use crate::dbs::{Options, Transaction};
3use crate::err::Error;
4use crate::iam::{Action, ResourceKind};
5use crate::sql::{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 RemoveEventStatement {
14	pub name: Ident,
15	pub what: Ident,
16}
17
18impl RemoveEventStatement {
19	/// Process this type returning a computed simple Value
20	pub(crate) async fn compute(
21		&self,
22		_ctx: &Context<'_>,
23		opt: &Options,
24		txn: &Transaction,
25	) -> Result<Value, Error> {
26		// Allowed to run?
27		opt.is_allowed(Action::Edit, ResourceKind::Event, &Base::Db)?;
28		// Claim transaction
29		let mut run = txn.lock().await;
30		// Clear the cache
31		run.clear_cache();
32		// Delete the definition
33		let key = crate::key::table::ev::new(opt.ns(), opt.db(), &self.what, &self.name);
34		run.del(key).await?;
35		// Clear the cache
36		let key = crate::key::table::ev::prefix(opt.ns(), opt.db(), &self.what);
37		run.clr(key).await?;
38		// Ok all good
39		Ok(Value::None)
40	}
41}
42
43impl Display for RemoveEventStatement {
44	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
45		write!(f, "REMOVE EVENT {} ON {}", self.name, self.what)
46	}
47}