surrealdb_sql/statements/
throw.rs1use crate::ctx::Context;
2use crate::dbs::{Options, Transaction};
3use crate::doc::CursorDoc;
4use crate::err::Error;
5use crate::Value;
6use derive::Store;
7use revision::revisioned;
8use serde::{Deserialize, Serialize};
9use std::fmt;
10
11#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
12#[revisioned(revision = 1)]
13pub struct ThrowStatement {
14 pub error: Value,
15}
16
17impl ThrowStatement {
18 pub(crate) fn writeable(&self) -> bool {
20 false
21 }
22 pub(crate) async fn compute(
24 &self,
25 ctx: &Context<'_>,
26 opt: &Options,
27 txn: &Transaction,
28 doc: Option<&CursorDoc<'_>>,
29 ) -> Result<Value, Error> {
30 Err(Error::Thrown(self.error.compute(ctx, opt, txn, doc).await?.to_raw_string()))
31 }
32}
33
34impl fmt::Display for ThrowStatement {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 write!(f, "THROW {}", self.error)
37 }
38}