surrealdb_sql/statements/remove/
model.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 RemoveModelStatement {
14 pub name: Ident,
15 pub version: String,
16}
17
18impl RemoveModelStatement {
19 pub(crate) async fn compute(
21 &self,
22 _ctx: &Context<'_>,
23 opt: &Options,
24 txn: &Transaction,
25 ) -> Result<Value, Error> {
26 opt.is_allowed(Action::Edit, ResourceKind::Model, &Base::Db)?;
28 let mut run = txn.lock().await;
30 run.clear_cache();
32 let key = crate::key::database::ml::new(opt.ns(), opt.db(), &self.name, &self.version);
34 run.del(key).await?;
35 Ok(Value::None)
39 }
40}
41
42impl Display for RemoveModelStatement {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 write!(f, "REMOVE MODEL ml::{}<{}>", self.name.0, self.version)
46 }
47}