Skip to content

Commit 31a5b27

Browse files
committed
fix: preserve and grouping inside v2 or
1 parent 0f0b419 commit 31a5b27

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

query/v2/query.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ func Or(operands ...cypher.SyntaxNode) cypher.SyntaxNode {
363363
return errExpression
364364
}
365365

366+
for idx, expression := range expressions {
367+
expressions[idx] = parenthesizeLogicalExpression(expression)
368+
}
369+
366370
return cypher.NewParenthetical(cypher.NewDisjunction(expressions...))
367371
}
368372

query/v2/query_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ func TestLogicalHelpersPreservePrecedence(t *testing.T) {
148148
).Return(v2.Node()),
149149
expected: "match (n) where n.a = $p0 and (n.b = $p1 or n.c = $p2) return n",
150150
},
151+
{
152+
name: "nested and is parenthesized inside or",
153+
builder: v2.New().Where(
154+
v2.Or(v2.And(a, b), c),
155+
).Return(v2.Node()),
156+
expected: "match (n) where ((n.a = $p0 and n.b = $p1) or n.c = $p2) return n",
157+
},
151158
{
152159
name: "not wraps or",
153160
builder: v2.New().Where(

0 commit comments

Comments
 (0)