surrealdb_core/sql/statements/
set.rsuse crate::cnf::PROTECTED_PARAM_NAMES;
use crate::ctx::Context;
use crate::dbs::Options;
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::sql::Value;
use derive::Store;
use reblessive::tree::Stk;
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt;
#[revisioned(revision = 1)]
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[non_exhaustive]
pub struct SetStatement {
pub name: String,
pub what: Value,
}
impl SetStatement {
pub(crate) fn writeable(&self) -> bool {
self.what.writeable()
}
pub(crate) async fn compute(
&self,
stk: &mut Stk,
ctx: &Context<'_>,
opt: &Options,
doc: Option<&CursorDoc<'_>>,
) -> Result<Value, Error> {
match PROTECTED_PARAM_NAMES.contains(&self.name.as_str()) {
false => self.what.compute(stk, ctx, opt, doc).await,
true => Err(Error::InvalidParam {
name: self.name.to_owned(),
}),
}
}
}
impl fmt::Display for SetStatement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "LET ${} = {}", self.name, self.what)
}
}