ReviewOS

also looking at this

stacks/bun-query-builder

fix(client): orWhere now groups, so an earlier where keeps applying (#1083)

#1088
Merged glennmichael123 wants to merge fix/or-where-precedence into main
13 files +1310 -450

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/bun-query-builder/test/client.test.tsmodified+13-2
Changes to packages/bun-query-builder/test/client.test.ts
@@ -117,8 +117,19 @@ describe('query builder - modifiers and raws', () => {
117117 it('date/json helpers compose', () => {
118118 const q1 = qb().selectFrom('users').whereDate('created_at', '>=', '2024-01-01').toSQL() as any
119119 expect(typeof q1.execute).toBe('function')
120 const q2 = qb().selectFrom('users').whereJsonContains('meta', { a: 1 }).toSQL() as any
121 expect(typeof q2.execute).toBe('function')
120
121 // Pinned: OBJECT containment throws on SQLite by design (there is no
122 // json_each equivalent for it), so this assertion silently depended on some
123 // earlier test file leaving the process-wide dialect on postgres.
124 const dialect = config.dialect
125 try {
126 config.dialect = 'postgres' as any
127 const q2 = qb().selectFrom('users').whereJsonContains('meta', { a: 1 }).toSQL() as any
128 expect(typeof q2.execute).toBe('function')
129 }
130 finally {
131 config.dialect = dialect as any
132 }
122133 })
123134})
124135
packages/bun-query-builder/test/client.where-in-writes.test.tsmodified+16-3
Changes to packages/bun-query-builder/test/client.where-in-writes.test.ts
@@ -23,8 +23,8 @@
2323 * injected operator cannot be walked back.
2424 */
2525
26import { describe, expect, it } from 'bun:test'
27import { buildDatabaseSchema, buildSchemaMeta, createQueryBuilder } from '../src'
26import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
27import { buildDatabaseSchema, buildSchemaMeta, config, createQueryBuilder } from '../src'
2828
2929function qb() {
3030 const models = {
@@ -44,7 +44,16 @@ function qb() {
4444 })
4545}
4646
47// The dialect decides whether placeholders are `$n` or `?`, and it lives in
48// process-wide config — so without pinning it here these assertions depended on
49// whichever test file happened to run first. Pinned rather than hedged, because
50// the numbering (`$2, $3`, not `$1, $2`) is exactly what this file is about:
51// an IN that restarted at $1 would update every row in the table.
4752describe('IN on an UPDATE', () => {
53 let dialect: string
54 beforeEach(() => { dialect = config.dialect; config.dialect = 'postgres' as any })
55 afterEach(() => { config.dialect = dialect as any })
56
4857 it('renders one placeholder per element, parenthesised', () => {
4958 const sql = String((qb() as any)
5059 .updateTable('notifications')
@@ -67,7 +76,7 @@ describe('IN on an UPDATE', () => {
6776 .where('id', 'in', [7, 8])
6877 .toSQL())
6978
70 expect(sql).toMatch(/IN \(\$2, \$3\)|IN \(\?, \?\)/)
79 expect(sql).toContain('IN ($2, $3)')
7180 })
7281
7382 it('continues an existing WHERE with AND rather than opening a second one', () => {
@@ -125,6 +134,10 @@ describe('IN on an UPDATE', () => {
125134})
126135
127136describe('IN on a DELETE', () => {
137 let dialect: string
138 beforeEach(() => { dialect = config.dialect; config.dialect = 'postgres' as any })
139 afterEach(() => { config.dialect = dialect as any })
140
128141 it('renders one placeholder per element', () => {
129142 const sql = String((qb() as any)
130143 .deleteFrom('notifications')