also looking at this
fix(client): orWhere now groups, so an earlier where keeps applying (#1083)
#1088
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.
| @@ -117,8 +117,19 @@ describe('query builder - modifiers and raws', () => { | ||
| 117 | 117 | it('date/json helpers compose', () => { |
| 118 | 118 | const q1 = qb().selectFrom('users').whereDate('created_at', '>=', '2024-01-01').toSQL() as any |
| 119 | 119 | 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 | } | |
| 122 | 133 | }) |
| 123 | 134 | }) |
| 124 | 135 | |
| @@ -23,8 +23,8 @@ | ||
| 23 | 23 | * injected operator cannot be walked back. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | import { describe, expect, it } from 'bun:test' | |
| 27 | import { buildDatabaseSchema, buildSchemaMeta, createQueryBuilder } from '../src' | |
| 26 | import { afterEach, beforeEach, describe, expect, it } from 'bun:test' | |
| 27 | import { buildDatabaseSchema, buildSchemaMeta, config, createQueryBuilder } from '../src' | |
| 28 | 28 | |
| 29 | 29 | function qb() { |
| 30 | 30 | const models = { |
| @@ -44,7 +44,16 @@ function qb() { | ||
| 44 | 44 | }) |
| 45 | 45 | } |
| 46 | 46 | |
| 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. | |
| 47 | 52 | describe('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 | ||
| 48 | 57 | it('renders one placeholder per element, parenthesised', () => { |
| 49 | 58 | const sql = String((qb() as any) |
| 50 | 59 | .updateTable('notifications') |
| @@ -67,7 +76,7 @@ describe('IN on an UPDATE', () => { | ||
| 67 | 76 | .where('id', 'in', [7, 8]) |
| 68 | 77 | .toSQL()) |
| 69 | 78 | |
| 70 | expect(sql).toMatch(/IN \(\$2, \$3\)|IN \(\?, \?\)/) | |
| 79 | expect(sql).toContain('IN ($2, $3)') | |
| 71 | 80 | }) |
| 72 | 81 | |
| 73 | 82 | it('continues an existing WHERE with AND rather than opening a second one', () => { |
| @@ -125,6 +134,10 @@ describe('IN on an UPDATE', () => { | ||
| 125 | 134 | }) |
| 126 | 135 | |
| 127 | 136 | describe('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 | ||
| 128 | 141 | it('renders one placeholder per element', () => { |
| 129 | 142 | const sql = String((qb() as any) |
| 130 | 143 | .deleteFrom('notifications') |