also looking at this
fix(client)!: bind db.raw and db.sql fragment values or refuse them
#1152
16 files
+455
-118
| @@ -7,7 +7,7 @@ There are two ways to use bun-query-builder: as a library and via the CLI. This | ||
| 7 | 7 | ### Quick Start |
| 8 | 8 | |
| 9 | 9 | ```ts |
| 10 | import { buildDatabaseSchema, buildSchemaMeta, createQueryBuilder } from 'bun-query-builder' | |
| 10 | import { buildDatabaseSchema, buildSchemaMeta, createQueryBuilder, raw } from 'bun-query-builder' | |
| 11 | 11 | |
| 12 | 12 | // Define your models with relationships |
| 13 | 13 | const models = { |
| @@ -86,7 +86,7 @@ const featuredProducts = await db | ||
| 86 | 86 | // Buddy's analytics: User engagement metrics |
| 87 | 87 | const userStats = await db |
| 88 | 88 | .selectFrom('users') |
| 89 | .selectRaw(db.sql` | |
| 89 | .selectRaw(raw` | |
| 90 | 90 | COUNT(posts.id) as post_count, |
| 91 | 91 | AVG(posts.engagement_score) as avg_engagement |
| 92 | 92 | `) |
| @@ -233,7 +233,7 @@ async function processOrderTransaction(orderData: any) { | ||
| 233 | 233 | |
| 234 | 234 | await tx |
| 235 | 235 | .updateTable('products') |
| 236 | .set({ stock_quantity: db.sql`stock_quantity - ${item.quantity}` }) | |
| 236 | .set({ stock_quantity: db.raw('stock_quantity - ?', [item.quantity]) }) | |
| 237 | 237 | .where({ id: item.product_id }) |
| 238 | 238 | .execute() |
| 239 | 239 | } |