diff --git a/mql_test.go b/mql_test.go index 9c80eeb..fc9fd2d 100644 --- a/mql_test.go +++ b/mql_test.go @@ -67,6 +67,15 @@ func TestParse(t *testing.T) { Args: []any{"alice", "eve@example.com", "1", 21, 1.5}, }, }, + { + name: "success-multi-columned", + query: "(name=`alice`) and (email=`eve@example.com`) and (member_number = 1)", + model: &testModel{}, + want: &mql.WhereClause{ + Condition: "(name=? and (email=? and member_number=?))", + Args: []any{"alice", "eve@example.com", "1"}, + }, + }, { name: "null-string", query: "name=\"null\"", diff --git a/parser.go b/parser.go index 8a9b8a0..c86c765 100644 --- a/parser.go +++ b/parser.go @@ -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 }