also looking at this
fix(client)!: bind db.raw and db.sql fragment values or refuse them
#1152
16 files
+455
-118
| @@ -159,6 +159,7 @@ const highValueCustomers = await db | ||
| 159 | 159 | Use raw SQL for complex aggregations: |
| 160 | 160 | |
| 161 | 161 | ```typescript |
| 162 | import { raw } from 'bun-query-builder' | |
| 162 | 163 | |
| 163 | 164 | // Custom aggregation |
| 164 | 165 | const results = await db |
| @@ -173,12 +174,12 @@ const results = await db | ||
| 173 | 174 | // Group by with raw expressions |
| 174 | 175 | const weeklyStats = await db |
| 175 | 176 | .selectFrom('orders') |
| 176 | .selectRaw(` | |
| 177 | .selectRaw(raw` | |
| 177 | 178 | strftime('%Y-%W', created_at) AS week, |
| 178 | COUNT(_) AS orders, | |
| 179 | COUNT(*) AS orders, | |
| 179 | 180 | SUM(amount) AS revenue |
| 180 | 181 | `) |
| 181 | .groupByRaw("strftime('%Y-%W', created_at)") | |
| 182 | .groupByRaw(raw`strftime('%Y-%W', created_at)`) | |
| 182 | 183 | .get() |
| 183 | 184 | |
| 184 | 185 | ``` |
| @@ -237,7 +238,7 @@ const authorStats = await db | ||
| 237 | 238 | |
| 238 | 239 | ```typescript |
| 239 | 240 | |
| 240 | import { createQueryBuilder, buildDatabaseSchema, buildSchemaMeta } from 'bun-query-builder' | |
| 241 | import { createQueryBuilder, buildDatabaseSchema, buildSchemaMeta, raw } from 'bun-query-builder' | |
| 241 | 242 | |
| 242 | 243 | // Setup |
| 243 | 244 | const models = { |
| @@ -315,12 +316,12 @@ async function getAnalytics() { | ||
| 315 | 316 | // Monthly revenue trend |
| 316 | 317 | const monthlyRevenue = await db |
| 317 | 318 | .selectFrom('orders') |
| 318 | .selectRaw(` | |
| 319 | .selectRaw(raw` | |
| 319 | 320 | strftime('%Y-%m', created_at) AS month, |
| 320 | COUNT(_) AS orders, | |
| 321 | COUNT(*) AS orders, | |
| 321 | 322 | SUM(amount) AS revenue |
| 322 | 323 | `) |
| 323 | .groupByRaw("strftime('%Y-%m', created_at)") | |
| 324 | .groupByRaw(raw`strftime('%Y-%m', created_at)`) | |
| 324 | 325 | .orderBy('month') |
| 325 | 326 | .get() |
| 326 | 327 | |