surrealpatch/core/src/sql/v1/future.rs

47 lines
1.2 KiB
Rust
Raw Normal View History

2022-10-31 23:12:41 +00:00
use crate::ctx::Context;
use crate::dbs::{Options, Transaction};
use crate::doc::CursorDoc;
2022-10-31 23:12:41 +00:00
use crate::err::Error;
use crate::sql::block::Block;
use crate::sql::value::Value;
use revision::revisioned;
2022-10-31 23:12:41 +00:00
use serde::{Deserialize, Serialize};
use std::fmt;
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Future";
2023-04-29 15:58:22 +00:00
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
#[serde(rename = "$surrealdb::private::sql::Future")]
#[revisioned(revision = 1)]
2024-01-09 15:34:52 +00:00
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct Future(pub Block);
impl From<Value> for Future {
fn from(v: Value) -> Self {
Future(Block::from(v))
}
}
2022-10-31 23:12:41 +00:00
impl Future {
/// Process this type returning a computed simple Value
pub(crate) async fn compute(
&self,
ctx: &Context<'_>,
opt: &Options,
txn: &Transaction,
doc: Option<&CursorDoc<'_>>,
) -> Result<Value, Error> {
2022-10-31 23:12:41 +00:00
// Process the future if enabled
match opt.futures {
true => self.0.compute(ctx, opt, txn, doc).await?.ok(),
2022-10-31 23:12:41 +00:00
false => Ok(self.clone().into()),
}
}
}
impl fmt::Display for Future {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "<future> {}", self.0)
2022-10-31 23:12:41 +00:00
}
}