surrealdb/sql/statements/
output.rsuse crate::ctx::Context;
use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::sql::fetch::Fetchs;
use crate::sql::value::Value;
use derive::Store;
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Store, Hash)]
#[revisioned(revision = 1)]
pub struct OutputStatement {
pub what: Value,
pub fetch: Option<Fetchs>,
}
impl OutputStatement {
pub(crate) fn writeable(&self) -> bool {
self.what.writeable()
}
pub(crate) async fn compute(
&self,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&CursorDoc<'_>>,
) -> Result<Value, Error> {
let opt = &opt.new_with_futures(true);
let mut val = self.what.compute(ctx, opt, txn, doc).await?;
if let Some(fetchs) = &self.fetch {
for fetch in fetchs.iter() {
val.fetch(ctx, opt, txn, fetch).await?;
}
}
Ok(val)
}
}
impl fmt::Display for OutputStatement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "RETURN {}", self.what)?;
if let Some(ref v) = self.fetch {
write!(f, " {v}")?
}
Ok(())
}
}