surrealdb_core/sql/statements/
throw.rs

1use crate::ctx::Context;
2use crate::dbs::Options;
3use crate::doc::CursorDoc;
4use crate::err::Error;
5use crate::sql::Value;
6
7use reblessive::tree::Stk;
8use revision::revisioned;
9use serde::{Deserialize, Serialize};
10use std::fmt;
11
12#[revisioned(revision = 1)]
13#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
14#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
15#[non_exhaustive]
16pub struct ThrowStatement {
17	pub error: Value,
18}
19
20impl ThrowStatement {
21	/// Check if we require a writeable transaction
22	pub(crate) fn writeable(&self) -> bool {
23		false
24	}
25	/// Process this type returning a computed simple Value
26	pub(crate) async fn compute(
27		&self,
28		stk: &mut Stk,
29		ctx: &Context,
30		opt: &Options,
31		doc: Option<&CursorDoc>,
32	) -> Result<Value, Error> {
33		Err(Error::Thrown(self.error.compute(stk, ctx, opt, doc).await?.to_raw_string()))
34	}
35}
36
37impl fmt::Display for ThrowStatement {
38	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39		write!(f, "THROW {}", self.error)
40	}
41}