Ensure CONTENT and REPLACE clauses accept only an object
This commit is contained in:
parent
9390ae9821
commit
3ffd194a05
1 changed files with 13 additions and 4 deletions
|
@ -19,8 +19,8 @@ pub enum Data {
|
||||||
SetExpression(Vec<(Idiom, Operator, Value)>),
|
SetExpression(Vec<(Idiom, Operator, Value)>),
|
||||||
DiffExpression(Array),
|
DiffExpression(Array),
|
||||||
MergeExpression(Object),
|
MergeExpression(Object),
|
||||||
ReplaceExpression(Value),
|
ReplaceExpression(Object),
|
||||||
ContentExpression(Value),
|
ContentExpression(Object),
|
||||||
SingleExpression(Value),
|
SingleExpression(Value),
|
||||||
ValuesExpression(Vec<Vec<(Idiom, Value)>>),
|
ValuesExpression(Vec<Vec<(Idiom, Value)>>),
|
||||||
UpdateExpression(Vec<(Idiom, Operator, Value)>),
|
UpdateExpression(Vec<(Idiom, Operator, Value)>),
|
||||||
|
@ -113,14 +113,14 @@ fn merge(i: &str) -> IResult<&str, Data> {
|
||||||
fn replace(i: &str) -> IResult<&str, Data> {
|
fn replace(i: &str) -> IResult<&str, Data> {
|
||||||
let (i, _) = tag_no_case("REPLACE")(i)?;
|
let (i, _) = tag_no_case("REPLACE")(i)?;
|
||||||
let (i, _) = shouldbespace(i)?;
|
let (i, _) = shouldbespace(i)?;
|
||||||
let (i, v) = value(i)?;
|
let (i, v) = object(i)?;
|
||||||
Ok((i, Data::ReplaceExpression(v)))
|
Ok((i, Data::ReplaceExpression(v)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn content(i: &str) -> IResult<&str, Data> {
|
fn content(i: &str) -> IResult<&str, Data> {
|
||||||
let (i, _) = tag_no_case("CONTENT")(i)?;
|
let (i, _) = tag_no_case("CONTENT")(i)?;
|
||||||
let (i, _) = shouldbespace(i)?;
|
let (i, _) = shouldbespace(i)?;
|
||||||
let (i, v) = value(i)?;
|
let (i, v) = object(i)?;
|
||||||
Ok((i, Data::ContentExpression(v)))
|
Ok((i, Data::ContentExpression(v)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +217,15 @@ mod tests {
|
||||||
assert_eq!("CONTENT { field: true }", format!("{}", out));
|
assert_eq!("CONTENT { field: true }", format!("{}", out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn replace_statement() {
|
||||||
|
let sql = "REPLACE { field: true }";
|
||||||
|
let res = data(sql);
|
||||||
|
assert!(res.is_ok());
|
||||||
|
let out = res.unwrap().1;
|
||||||
|
assert_eq!("REPLACE { field: true }", format!("{}", out));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn values_statement() {
|
fn values_statement() {
|
||||||
let sql = "(one, two, three) VALUES ($param, true, [1, 2, 3]), ($param, false, [4, 5, 6])";
|
let sql = "(one, two, three) VALUES ($param, true, [1, 2, 3]), ($param, false, [4, 5, 6])";
|
||||||
|
|
Loading…
Reference in a new issue