diff --git a/lib/src/sql/id.rs b/lib/src/sql/id.rs index eff71caf..0f6436c8 100644 --- a/lib/src/sql/id.rs +++ b/lib/src/sql/id.rs @@ -1,4 +1,8 @@ use crate::cnf::ID_CHARS; +use crate::ctx::Context; +use crate::dbs::Options; +use crate::dbs::Transaction; +use crate::err::Error; use crate::sql::array::{array, Array}; use crate::sql::error::IResult; use crate::sql::escape::escape_rid; @@ -109,6 +113,29 @@ impl Display for Id { } } +impl Id { + pub(crate) async fn compute( + &self, + ctx: &Context<'_>, + opt: &Options, + txn: &Transaction, + doc: Option<&Value>, + ) -> Result { + match self { + Id::Number(v) => Ok(Id::Number(*v)), + Id::String(v) => Ok(Id::String(v.clone())), + Id::Object(v) => match v.compute(ctx, opt, txn, doc).await? { + Value::Object(v) => Ok(Id::Object(v)), + _ => unreachable!(), + }, + Id::Array(v) => match v.compute(ctx, opt, txn, doc).await? { + Value::Array(v) => Ok(Id::Array(v)), + _ => unreachable!(), + }, + } + } +} + pub fn id(i: &str) -> IResult<&str, Id> { alt(( map(integer, Id::Number), diff --git a/lib/src/sql/range.rs b/lib/src/sql/range.rs index e637ca22..07bea1f6 100644 --- a/lib/src/sql/range.rs +++ b/lib/src/sql/range.rs @@ -1,6 +1,11 @@ +use crate::ctx::Context; +use crate::dbs::Options; +use crate::dbs::Transaction; +use crate::err::Error; use crate::sql::error::IResult; use crate::sql::id::{id, Id}; use crate::sql::ident::ident_raw; +use crate::sql::value::Value; use nom::branch::alt; use nom::character::complete::char; use nom::combinator::map; @@ -19,6 +24,30 @@ pub struct Range { pub end: Bound, } +impl Range { + pub(crate) async fn compute( + &self, + ctx: &Context<'_>, + opt: &Options, + txn: &Transaction, + doc: Option<&Value>, + ) -> Result { + Ok(Value::Range(Box::new(Range { + tb: self.tb.clone(), + beg: match &self.beg { + Bound::Included(id) => Bound::Included(id.compute(ctx, opt, txn, doc).await?), + Bound::Excluded(id) => Bound::Excluded(id.compute(ctx, opt, txn, doc).await?), + Bound::Unbounded => Bound::Unbounded, + }, + end: match &self.end { + Bound::Included(id) => Bound::Included(id.compute(ctx, opt, txn, doc).await?), + Bound::Excluded(id) => Bound::Excluded(id.compute(ctx, opt, txn, doc).await?), + Bound::Unbounded => Bound::Unbounded, + }, + }))) + } +} + impl PartialOrd for Range { fn partial_cmp(&self, other: &Self) -> Option { match self.tb.partial_cmp(&other.tb) { diff --git a/lib/src/sql/thing.rs b/lib/src/sql/thing.rs index 76766e5c..967323f7 100644 --- a/lib/src/sql/thing.rs +++ b/lib/src/sql/thing.rs @@ -66,18 +66,7 @@ impl Thing { ) -> Result { Ok(Value::Thing(Thing { tb: self.tb.clone(), - id: match &self.id { - Id::Number(v) => Id::Number(*v), - Id::String(v) => Id::String(v.clone()), - Id::Object(v) => match v.compute(ctx, opt, txn, doc).await? { - Value::Object(v) => Id::Object(v), - _ => unreachable!(), - }, - Id::Array(v) => match v.compute(ctx, opt, txn, doc).await? { - Value::Array(v) => Id::Array(v), - _ => unreachable!(), - }, - }, + id: self.id.compute(ctx, opt, txn, doc).await?, })) } } diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index c1a895b1..54fa5bc0 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -1278,6 +1278,7 @@ impl Value { Value::True => Ok(Value::True), Value::False => Ok(Value::False), Value::Thing(v) => v.compute(ctx, opt, txn, doc).await, + Value::Range(v) => v.compute(ctx, opt, txn, doc).await, Value::Param(v) => v.compute(ctx, opt, txn, doc).await, Value::Idiom(v) => v.compute(ctx, opt, txn, doc).await, Value::Array(v) => v.compute(ctx, opt, txn, doc).await,