also looking at this
fix(client)!: bind db.raw and db.sql fragment values or refuse them
#1152
16 files
+455
-118
| @@ -27,7 +27,7 @@ import { | ||
| 27 | 27 | } from 'bun-query-builder' |
| 28 | 28 | |
| 29 | 29 | // Example: Chris's team setup |
| 30 | import { buildDatabaseSchema, buildSchemaMeta, config, createQueryBuilder } from 'bun-query-builder' | |
| 30 | import { buildDatabaseSchema, buildSchemaMeta, config, createQueryBuilder, raw } from 'bun-query-builder' | |
| 31 | 31 | import { userModels } from './models' |
| 32 | 32 | |
| 33 | 33 | // Configure for PostgreSQL production environment |
| @@ -87,9 +87,10 @@ setConfig({ transactionDefaults: { retries: 5 } }) | ||
| 87 | 87 | - updateTable(table) |
| 88 | 88 | - deleteFrom(table) |
| 89 | 89 | - sql: passthrough to Bun’s `sql` |
| 90 | - raw(strings, ...values) | |
| 90 | - raw(sql, bindings?): bound `{ sql, parameters }` fragment for `set()` / `where()` (not a query; awaiting it rejects) | |
| 91 | - ``raw`...` `` (tagged template): passthrough to Bun’s `sql` | |
| 91 | 92 | - simple(strings, ...values) |
| 92 | - unsafe(query, params?) | |
| 93 | - unsafe(query, params?): run SQL and return rows | |
| 93 | 94 | - file(path, params?) |
| 94 | 95 | - reserve(): Promise<QueryBuilder & { release() }> |
| 95 | 96 | - close(opts?) |
| @@ -234,7 +235,7 @@ setConfig({ transactionDefaults: { retries: 5 } }) | ||
| 234 | 235 | const userAnalytics = await db |
| 235 | 236 | .selectFrom('users') |
| 236 | 237 | .select('users', 'id', 'name', 'email', 'created_at') |
| 237 | .selectRaw(db.sql`COUNT(posts.id) as post_count`) | |
| 238 | .selectRaw(raw`COUNT(posts.id) as post_count`) | |
| 238 | 239 | .with('Profile', 'Team') |
| 239 | 240 | .leftJoin('posts', 'posts.author_id', '=', 'users.id') |
| 240 | 241 | .where({ 'users.active': true }) |