ReviewOS

also looking at this

stacks/bun-query-builder

fix(client)!: bind db.raw and db.sql fragment values or refuse them

#1152
Merged glennmichael123 wants to merge fix/db-sql-raw-bindings into main
16 files +455 -118
docs/advanced/api.mdmodified+5-4
Changes to docs/advanced/api.md
@@ -27,7 +27,7 @@ import {
2727} from 'bun-query-builder'
2828
2929// Example: Chris's team setup
30import { buildDatabaseSchema, buildSchemaMeta, config, createQueryBuilder } from 'bun-query-builder'
30import { buildDatabaseSchema, buildSchemaMeta, config, createQueryBuilder, raw } from 'bun-query-builder'
3131import { userModels } from './models'
3232
3333// Configure for PostgreSQL production environment
@@ -87,9 +87,10 @@ setConfig({ transactionDefaults: { retries: 5 } })
8787- updateTable(table)
8888- deleteFrom(table)
8989- 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`
9192- simple(strings, ...values)
92- unsafe(query, params?)
93- unsafe(query, params?): run SQL and return rows
9394- file(path, params?)
9495- reserve(): Promise<QueryBuilder & { release() }>
9596- close(opts?)
@@ -234,7 +235,7 @@ setConfig({ transactionDefaults: { retries: 5 } })
234235const userAnalytics = await db
235236 .selectFrom('users')
236237 .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`)
238239 .with('Profile', 'Team')
239240 .leftJoin('posts', 'posts.author_id', '=', 'users.id')
240241 .where({ 'users.active': true })