surrealdb_core/sql/statements/
output.rsuse crate::ctx::Context;
use crate::dbs::Options;
use crate::doc::CursorDoc;
use crate::err::Error;
use crate::sql::fetch::Fetchs;
use crate::sql::value::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 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,
stk: &mut Stk,
ctx: &Context<'_>,
opt: &Options,
doc: Option<&CursorDoc<'_>>,
) -> Result<Value, Error> {
let opt = &opt.new_with_futures(true);
let mut value = self.what.compute(stk, ctx, opt, doc).await?;
if let Some(fetchs) = &self.fetch {
let mut idioms = Vec::with_capacity(fetchs.0.len());
for fetch in fetchs.iter() {
fetch.compute(stk, ctx, opt, &mut idioms).await?
}
for i in &idioms {
value.fetch(stk, ctx, opt, i).await?;
}
}
Err(Error::Return {
value,
})
}
}
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(())
}
}