Skip to content

Commit

Permalink
fix (parse): queries with multiple columns need to properly handle
Browse files Browse the repository at this point in the history
right-side logic expressions when they are complete expressions (having
both a left and right side).
  • Loading branch information
jimlambrt committed Dec 19, 2023
1 parent eaa1a8f commit 4a6bc8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ func TestParse(t *testing.T) {
Args: []any{"alice", "[email protected]", "1", 21, 1.5},
},
},
{
name: "success-multi-columned",
query: "(name=`alice`) and (email=`[email protected]`) and (member_number = 1)",
model: &testModel{},
want: &mql.WhereClause{
Condition: "(name=? and (email=? and member_number=?))",
Args: []any{"alice", "[email protected]", "1"},
},
},
{
name: "null-string",
query: "name=\"null\"",
Expand Down
8 changes: 8 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ TkLoop:
return nil, fmt.Errorf("%s: %w before right side expression in: %q", op, ErrMissingLogicalOp, p.raw)
// finally, assign the right expr
case logicExpr.rightExpr == nil:
if e.rightExpr != nil {
// if e.rightExpr isn't nil, then we've got a complete
// expr (left + op + right) and we need to assign this to
// our rightExpr
logicExpr.rightExpr = e
break TkLoop
}
// otherwise, we need to assign the left side of e to our
logicExpr.rightExpr = e.leftExpr
break TkLoop
}
Expand Down

0 comments on commit 4a6bc8b

Please sign in to comment.