diff --git a/src/sql/data.rs b/src/sql/data.rs index 5b0ac69a..cd3ebd11 100644 --- a/src/sql/data.rs +++ b/src/sql/data.rs @@ -18,9 +18,9 @@ pub enum Data { EmptyExpression, SetExpression(Vec<(Idiom, Operator, Value)>), PatchExpression(Array), - MergeExpression(Object), - ReplaceExpression(Object), - ContentExpression(Object), + MergeExpression(Value), + ReplaceExpression(Value), + ContentExpression(Value), SingleExpression(Value), ValuesExpression(Vec>), UpdateExpression(Vec<(Idiom, Operator, Value)>), @@ -106,21 +106,21 @@ fn patch(i: &str) -> IResult<&str, Data> { fn merge(i: &str) -> IResult<&str, Data> { let (i, _) = tag_no_case("MERGE")(i)?; let (i, _) = shouldbespace(i)?; - let (i, v) = object(i)?; + let (i, v) = value(i)?; Ok((i, Data::MergeExpression(v))) } fn replace(i: &str) -> IResult<&str, Data> { let (i, _) = tag_no_case("REPLACE")(i)?; let (i, _) = shouldbespace(i)?; - let (i, v) = object(i)?; + let (i, v) = value(i)?; Ok((i, Data::ReplaceExpression(v))) } fn content(i: &str) -> IResult<&str, Data> { let (i, _) = tag_no_case("CONTENT")(i)?; let (i, _) = shouldbespace(i)?; - let (i, v) = object(i)?; + let (i, v) = value(i)?; Ok((i, Data::ContentExpression(v))) } diff --git a/src/sql/value/merge.rs b/src/sql/value/merge.rs index 4541dab5..44788252 100644 --- a/src/sql/value/merge.rs +++ b/src/sql/value/merge.rs @@ -2,7 +2,6 @@ use crate::dbs::Executor; use crate::dbs::Options; use crate::dbs::Runtime; use crate::err::Error; -use crate::sql::object::Object; use crate::sql::value::Value; impl Value { @@ -11,7 +10,7 @@ impl Value { ctx: &Runtime, opt: &Options, exe: &Executor<'_>, - val: &Object, + val: &Value, ) -> Result<(), Error> { match val.compute(ctx, opt, exe, Some(self)).await? { Value::Object(v) => { @@ -20,7 +19,7 @@ impl Value { } Ok(()) } - _ => unreachable!(), + _ => Ok(()), } } } diff --git a/src/sql/value/replace.rs b/src/sql/value/replace.rs index 87f5bf76..3a92edc7 100644 --- a/src/sql/value/replace.rs +++ b/src/sql/value/replace.rs @@ -2,20 +2,24 @@ use crate::dbs::Executor; use crate::dbs::Options; use crate::dbs::Runtime; use crate::err::Error; -use crate::sql::object::Object; use crate::sql::value::Value; impl Value { pub async fn replace( &mut self, - _ctx: &Runtime, - _opt: &Options, - _exe: &Executor<'_>, - val: &Object, + ctx: &Runtime, + opt: &Options, + exe: &Executor<'_>, + val: &Value, ) -> Result<(), Error> { // Clear all entries - *self = Value::from(val.clone()); - Ok(()) + match val.compute(ctx, opt, exe, Some(self)).await? { + Value::Object(v) => { + *self = Value::from(v); + Ok(()) + } + _ => Ok(()), + } } } @@ -31,7 +35,7 @@ mod tests { let (ctx, opt, exe) = mock(); let mut val = Value::parse("{ test: { other: null, something: 123 } }"); let res = Value::parse("{ other: true }"); - let obj = Object::from(map! {String::from("other") => Value::from(true) }); + let obj = Value::parse("{ other: true }"); val.replace(&ctx, &opt, &exe, &obj).await.unwrap(); assert_eq!(res, val); }