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/features/relations.mdmodified+15-13
Changes to docs/features/relations.md
@@ -462,11 +462,13 @@ the model layer's eager loading.
462462Example:
463463
464464```ts
465import { raw } from 'bun-query-builder'
466
465467await db
466468 .selectFrom('users')
467469 .with('Project')
468470 .select('users', 'id', 'email')
469 .selectRaw(db.sql`projects.name as projects_name`)
471 .selectRaw(raw`projects.name as projects_name`)
470472 .execute()
471473```
472474
renamed throughout · 10 hidden lines
Changes to docs/features/relations.md
@@ -508,8 +510,8 @@ await db renamed throughout
508510 .selectFrom('users')
509511 .with('Project')
510512 .select('users', 'id', 'email')
511 .selectRaw(db.sql`projects.id as projects_id`)
512 .selectRaw(db.sql`projects.name as projects_name`)
513 .selectRaw(raw`projects.id as projects_id`)
514 .selectRaw(raw`projects.name as projects_name`)
513515 .execute()
514516```
515517
Changes to docs/features/relations.md
@@ -520,7 +522,7 @@ await db
520522 .selectFrom('users')
521523 .with('Project')
522524 .groupBy('users.id')
523 .selectRaw(db.sql`COUNT(projects.id) as projects_count`)
525 .selectRaw(raw`COUNT(projects.id) as projects_count`)
524526 .execute()
525527```
526528
@@ -568,7 +570,7 @@ const teamData = await db
568570 .selectFrom('users')
569571 .with('Project')
570572 .select('users', 'id', 'name', 'role')
571 .selectRaw(db.sql`projects.id as project_id, projects.name as project_name`)
573 .selectRaw(raw`projects.id as project_id, projects.name as project_name`)
572574 .where({ 'users.team': 'Engineering' })
573575 .execute()
574576```
@@ -671,7 +673,7 @@ await db
671673 .with('Project')
672674 .whereHas('Project', ['status', '=', 'active'])
673675 .groupBy('users.id')
674 .havingRaw(db.sql`COUNT(CASE WHEN projects.status = 'inactive' THEN 1 END) = 0`)
676 .havingRaw(raw`COUNT(CASE WHEN projects.status = 'inactive' THEN 1 END) = 0`)
675677 .execute()
676678```
677679
@@ -682,7 +684,7 @@ await db
682684 .selectFrom('users')
683685 .with('Project')
684686 .groupBy('users.id')
685 .selectRaw(db.sql`COUNT(projects.id) as projects_count`)
687 .selectRaw(raw`COUNT(projects.id) as projects_count`)
686688 .orderByDesc('projects_count' as any)
687689 .limit(10)
688690 .execute()
@@ -696,7 +698,7 @@ await db
696698 .selectFrom('users')
697699 .with('Project')
698700 .groupBy('users.id')
699 .havingRaw(db.sql`COUNT(projects.id) >= ${db.sql(String(N))}`)
701 .havingRaw(raw`COUNT(projects.id) >= ${N}`)
700702 .execute()
701703```
702704
@@ -740,7 +742,7 @@ await db
740742 .selectFrom('users')
741743 .join('projects', 'projects.ownerId' as any, '=', 'users.uid' as any)
742744 .select('users', 'uid as id', 'email')
743 .selectRaw(db.sql`projects.title as projects_title`)
745 .selectRaw(raw`projects.title as projects_title`)
744746 .execute()
745747```
746748
renamed throughout · 10 hidden lines
Changes to docs/features/relations.md
@@ -782,8 +784,8 @@ await db renamed throughout
782784 .selectFrom('users')
783785 .with('Project')
784786 .select('users', 'id', 'email')
785 .selectRaw(db.sql`projects.id as projects_id`)
786 .selectRaw(db.sql`projects.status as projects_status`)
787 .selectRaw(raw`projects.id as projects_id`)
788 .selectRaw(raw`projects.status as projects_status`)
787789 .execute()
788790```
789791
renamed throughout · 10 hidden lines
Changes to docs/features/relations.md
@@ -794,8 +796,8 @@ await db renamed throughout
794796 .selectFrom('users')
795797 .with('Project')
796798 .groupBy('users.id')
797 .selectRaw(db.sql`COUNT(projects.id) as projects_count`)
798 .selectRaw(db.sql`SUM(CASE WHEN projects.status = 'active' THEN 1 ELSE 0 END) as active_count`)
799 .selectRaw(raw`COUNT(projects.id) as projects_count`)
800 .selectRaw(raw`SUM(CASE WHEN projects.status = 'active' THEN 1 ELSE 0 END) as active_count`)
799801 .execute()
800802```
801803