bun
bun copied to clipboard
Missing starting parenthesis when calling WhereGroup first
Hello,
Here's an example of the issue:
err := db.NewSelect().
Model(book).
WhereGroup("", func (q *bun.Query) {
q.Where("a = 1").Where("b = 1")
}).
WhereGroup(" OR ", func(q *bun.Query) {
q.Where("a = 2").Where("b = 2")
}).
Scan(ctx)
Leads to a query like this:
SELECT "books"."a", "books.b" FROM "books" AS "books" WHERE (a = 1) AND (b = 1)) OR ((a = 2) AND (b = 2))
It's missing the first opening parenthesis.
I quickly fixed it by changing query_base.go:641 from:
if i > 0 {
To:
if i > 0 || where.Sep == "(" {
Also, the documentation https://bun.uptrace.dev/guide/queries.html#select is not up to date about WhereGroup.
Thanks.
(Note that I tested the same with go-pg and it works correctly).
Thanks for the details report - this should be fixed in v0.3.8