diff --git a/lib/src/sql/thing.rs b/lib/src/sql/thing.rs index 460afa13..b5f66510 100644 --- a/lib/src/sql/thing.rs +++ b/lib/src/sql/thing.rs @@ -1,8 +1,13 @@ +use crate::ctx::Context; +use crate::dbs::Options; +use crate::dbs::Transaction; +use crate::err::Error; use crate::sql::error::IResult; use crate::sql::escape::escape_id; use crate::sql::id::{id, Id}; use crate::sql::ident::ident_raw; use crate::sql::serde::is_internal_serialization; +use crate::sql::value::Value; use derive::Store; use nom::branch::alt; use nom::character::complete::char; @@ -58,6 +63,32 @@ impl fmt::Display for Thing { } } +impl Thing { + pub(crate) async fn compute( + &self, + ctx: &Context<'_>, + opt: &Options, + txn: &Transaction, + doc: Option<&Value>, + ) -> 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!(), + }, + }, + })) + } +} + impl Serialize for Thing { fn serialize(&self, serializer: S) -> Result where diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index 47cd9c5f..162c5e8d 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -1115,6 +1115,7 @@ impl Value { Value::Null => Ok(Value::Null), Value::True => Ok(Value::True), Value::False => Ok(Value::False), + Value::Thing(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,