ReviewOS

stacks/bun-query-builder

Multiple having() calls emit a second HAVING keyword instead of AND

#1034
Closed glennmichael123 opened this 22 days ago · 0 comments
22 days ago

Summary

Each having() appends ... HAVING ... to text; reorderSelectClauses groups same-key fragments by joining with a space, so two calls become HAVING COUNT(id) > $1 HAVING SUM(age) < $2 — invalid SQL.

Evidence (repro)

.having(['COUNT(id)','>',3]).having(['SUM(age)','<',100]).toSQL()
-> ... HAVING COUNT(id) > $1 HAVING SUM(age) < $2

Location

src/client.ts:~4429-4458.

Suggested fix

Detect an existing HAVING (like orderBy/groupBy do) and append subsequent conditions with AND.

Severity: medium. Found via internal code audit.

Sign in to comment on this issue.