Use new SQL Block type for <future> expressions

This commit is contained in:
Tobie Morgan Hitchcock 2023-02-21 14:15:19 +00:00
parent 9fcf4c9419
commit 9c18025cca
2 changed files with 13 additions and 10 deletions

View file

@ -322,7 +322,7 @@ impl Datastore {
/// async fn main() -> Result<(), Error> {
/// let ds = Datastore::new("memory").await?;
/// let ses = Session::for_kv();
/// let val = Value::Future(Box::new(Future(Value::True)));
/// let val = Value::Future(Box::new(Future::from(Value::True)));
/// let res = ds.compute(val, &ses, None, false).await?;
/// Ok(())
/// }

View file

@ -2,16 +2,23 @@ use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::block::{block, Block};
use crate::sql::comment::mightbespace;
use crate::sql::error::IResult;
use crate::sql::value::{value, Value};
use crate::sql::value::Value;
use nom::bytes::complete::tag;
use nom::character::complete::char;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
pub struct Future(pub Value);
pub struct Future(pub Block);
impl From<Value> for Future {
fn from(v: Value) -> Self {
Future(Block::from(v))
}
}
impl Future {
pub(crate) async fn compute(
@ -33,7 +40,7 @@ impl Future {
impl fmt::Display for Future {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "<future> {{ {} }}", self.0)
write!(f, "<future> {}", self.0)
}
}
@ -42,11 +49,7 @@ pub fn future(i: &str) -> IResult<&str, Future> {
let (i, _) = tag("future")(i)?;
let (i, _) = char('>')(i)?;
let (i, _) = mightbespace(i)?;
let (i, _) = char('{')(i)?;
let (i, _) = mightbespace(i)?;
let (i, v) = value(i)?;
let (i, _) = mightbespace(i)?;
let (i, _) = char('}')(i)?;
let (i, v) = block(i)?;
Ok((i, Future(v)))
}
#[cfg(test)]
@ -63,6 +66,6 @@ mod tests {
assert!(res.is_ok());
let out = res.unwrap().1;
assert_eq!("<future> { 1.2345 + 5.4321 }", format!("{}", out));
assert_eq!(out, Future(Value::from(Expression::parse("1.2345 + 5.4321"))));
assert_eq!(out, Future(Block::from(Value::from(Expression::parse("1.2345 + 5.4321")))));
}
}