Allow any value in CONTENT / REPLACE / MERGE clauses
This commit is contained in:
parent
1ca5f085c5
commit
6715ac251b
3 changed files with 20 additions and 17 deletions
|
@ -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<Vec<(Idiom, Value)>>),
|
||||
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)))
|
||||
}
|
||||
|
||||
|
|
|
@ -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(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,21 +2,25 @@ 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());
|
||||
match val.compute(ctx, opt, exe, Some(self)).await? {
|
||||
Value::Object(v) => {
|
||||
*self = Value::from(v);
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue