also looking at this
fix(client)!: bind db.raw and db.sql fragment values or refuse them
#1152
16 files
+455
-118
| @@ -462,11 +462,13 @@ the model layer's eager loading. | ||
| 462 | 462 | Example: |
| 463 | 463 | |
| 464 | 464 | ```ts |
| 465 | import { raw } from 'bun-query-builder' | |
| 466 | ||
| 465 | 467 | await db |
| 466 | 468 | .selectFrom('users') |
| 467 | 469 | .with('Project') |
| 468 | 470 | .select('users', 'id', 'email') |
| 469 | .selectRaw(db.sql`projects.name as projects_name`) | |
| 471 | .selectRaw(raw`projects.name as projects_name`) | |
| 470 | 472 | .execute() |
| 471 | 473 | ``` |
| 472 | 474 | |
renamed throughout · 10 hidden lines
| @@ -508,8 +510,8 @@ await db renamed throughout | ||
| 508 | 510 | .selectFrom('users') |
| 509 | 511 | .with('Project') |
| 510 | 512 | .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`) | |
| 513 | 515 | .execute() |
| 514 | 516 | ``` |
| 515 | 517 | |
| @@ -520,7 +522,7 @@ await db | ||
| 520 | 522 | .selectFrom('users') |
| 521 | 523 | .with('Project') |
| 522 | 524 | .groupBy('users.id') |
| 523 | .selectRaw(db.sql`COUNT(projects.id) as projects_count`) | |
| 525 | .selectRaw(raw`COUNT(projects.id) as projects_count`) | |
| 524 | 526 | .execute() |
| 525 | 527 | ``` |
| 526 | 528 | |
| @@ -568,7 +570,7 @@ const teamData = await db | ||
| 568 | 570 | .selectFrom('users') |
| 569 | 571 | .with('Project') |
| 570 | 572 | .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`) | |
| 572 | 574 | .where({ 'users.team': 'Engineering' }) |
| 573 | 575 | .execute() |
| 574 | 576 | ``` |
| @@ -671,7 +673,7 @@ await db | ||
| 671 | 673 | .with('Project') |
| 672 | 674 | .whereHas('Project', ['status', '=', 'active']) |
| 673 | 675 | .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`) | |
| 675 | 677 | .execute() |
| 676 | 678 | ``` |
| 677 | 679 | |
| @@ -682,7 +684,7 @@ await db | ||
| 682 | 684 | .selectFrom('users') |
| 683 | 685 | .with('Project') |
| 684 | 686 | .groupBy('users.id') |
| 685 | .selectRaw(db.sql`COUNT(projects.id) as projects_count`) | |
| 687 | .selectRaw(raw`COUNT(projects.id) as projects_count`) | |
| 686 | 688 | .orderByDesc('projects_count' as any) |
| 687 | 689 | .limit(10) |
| 688 | 690 | .execute() |
| @@ -696,7 +698,7 @@ await db | ||
| 696 | 698 | .selectFrom('users') |
| 697 | 699 | .with('Project') |
| 698 | 700 | .groupBy('users.id') |
| 699 | .havingRaw(db.sql`COUNT(projects.id) >= ${db.sql(String(N))}`) | |
| 701 | .havingRaw(raw`COUNT(projects.id) >= ${N}`) | |
| 700 | 702 | .execute() |
| 701 | 703 | ``` |
| 702 | 704 | |
| @@ -740,7 +742,7 @@ await db | ||
| 740 | 742 | .selectFrom('users') |
| 741 | 743 | .join('projects', 'projects.ownerId' as any, '=', 'users.uid' as any) |
| 742 | 744 | .select('users', 'uid as id', 'email') |
| 743 | .selectRaw(db.sql`projects.title as projects_title`) | |
| 745 | .selectRaw(raw`projects.title as projects_title`) | |
| 744 | 746 | .execute() |
| 745 | 747 | ``` |
| 746 | 748 | |
renamed throughout · 10 hidden lines
| @@ -782,8 +784,8 @@ await db renamed throughout | ||
| 782 | 784 | .selectFrom('users') |
| 783 | 785 | .with('Project') |
| 784 | 786 | .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`) | |
| 787 | 789 | .execute() |
| 788 | 790 | ``` |
| 789 | 791 | |
renamed throughout · 10 hidden lines
| @@ -794,8 +796,8 @@ await db renamed throughout | ||
| 794 | 796 | .selectFrom('users') |
| 795 | 797 | .with('Project') |
| 796 | 798 | .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`) | |
| 799 | 801 | .execute() |
| 800 | 802 | ``` |
| 801 | 803 | |