surrealdb_sql/statements/remove/
field.rsuse crate::ctx::Context;
use crate::dbs::{Options, Transaction};
use crate::err::Error;
use crate::iam::{Action, ResourceKind};
use crate::{Base, Ident, Idiom, 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 RemoveFieldStatement {
pub name: Idiom,
pub what: Ident,
}
impl RemoveFieldStatement {
pub(crate) async fn compute(
&self,
_ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
) -> Result<Value, Error> {
opt.is_allowed(Action::Edit, ResourceKind::Field, &Base::Db)?;
let mut run = txn.lock().await;
run.clear_cache();
let fd = self.name.to_string();
let key = crate::key::table::fd::new(opt.ns(), opt.db(), &self.what, &fd);
run.del(key).await?;
let key = crate::key::table::fd::prefix(opt.ns(), opt.db(), &self.what);
run.clr(key).await?;
Ok(Value::None)
}
}
impl Display for RemoveFieldStatement {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "REMOVE FIELD {} ON {}", self.name, self.what)
}
}