surrealdb_sql/statements/remove/
event.rsuse crate::ctx::Context;
use crate::dbs::{Options, Transaction};
use crate::err::Error;
use crate::iam::{Action, ResourceKind};
use crate::{Base, Ident, Value};
use derive::Store;
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter};
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
#[revisioned(revision = 1)]
pub struct RemoveEventStatement {
pub name: Ident,
pub what: Ident,
}
impl RemoveEventStatement {
pub(crate) async fn compute(
&self,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
) -> Result<Value, Error> {
opt.is_allowed(Action::Edit, ResourceKind::Event, &Base::Db)?;
let mut run = txn.lock().await;
run.clear_cache();
let key = crate::key::table::ev::new(opt.ns(), opt.db(), &self.what, &self.name);
run.del(key).await?;
let key = crate::key::table::ev::prefix(opt.ns(), opt.db(), &self.what);
run.clr(key).await?;
Ok(Value::None)
}
}
impl Display for RemoveEventStatement {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "REMOVE EVENT {} ON {}", self.name, self.what)
}
}