prisma-ts-select 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +266 -212
  2. package/assets/groupBy.gif +0 -0
  3. package/assets/joinUnsafeIgnoreType.gif +0 -0
  4. package/assets/joinUnsafeTypeEnforced.gif +0 -0
  5. package/assets/typesafe-join.gif +0 -0
  6. package/assets/typesafe-join.png +0 -0
  7. package/assets/{whereisNull.gif → whereIsNull.gif} +0 -0
  8. package/assets/whereNotNull.gif +0 -0
  9. package/dist/bin.cjs +1 -1
  10. package/dist/bin.js +1 -1
  11. package/dist/{chunk-54D2J5AR.cjs → chunk-GSIFF2TF.cjs} +19 -0
  12. package/dist/{chunk-47KZVQLD.js → chunk-NFKUA5XM.js} +19 -0
  13. package/dist/extend/dialects/index.d.ts +4 -4
  14. package/dist/extend/dialects/index.js +26 -2
  15. package/dist/extend/dialects/mysql-v6.d.ts +10 -6
  16. package/dist/extend/dialects/mysql-v6.js +15 -3
  17. package/dist/extend/dialects/mysql-v7.d.ts +2 -2
  18. package/dist/extend/dialects/mysql-v7.js +14 -2
  19. package/dist/extend/dialects/mysql.d.ts +9 -5
  20. package/dist/extend/dialects/mysql.js +14 -2
  21. package/dist/extend/dialects/postgresql-v6.d.ts +12 -7
  22. package/dist/extend/dialects/postgresql-v6.js +22 -4
  23. package/dist/extend/dialects/postgresql-v7.d.ts +12 -7
  24. package/dist/extend/dialects/postgresql-v7.js +22 -4
  25. package/dist/extend/dialects/postgresql.d.ts +10 -6
  26. package/dist/extend/dialects/postgresql.js +21 -3
  27. package/dist/extend/dialects/shared.d.ts +6 -1
  28. package/dist/extend/dialects/shared.js +11 -2
  29. package/dist/extend/dialects/sqlite.d.ts +12 -4
  30. package/dist/extend/dialects/sqlite.js +26 -2
  31. package/dist/extend/dialects/types.d.ts +2 -1
  32. package/dist/extend/extend.d.ts +9 -6
  33. package/dist/extend/extend.js +47 -12
  34. package/dist/extend/{sql-expr-BaKWzJ-r.d.ts → sql-expr-BGSEwzCi.d.ts} +5 -1
  35. package/dist/extend/types-B0F8m0ok.d.ts +8 -0
  36. package/dist/generator.cjs +1 -1
  37. package/dist/generator.js +1 -1
  38. package/package.json +27 -29
  39. package/LICENSE +0 -21
  40. package/dist/extend/types-D84lxYVc.d.ts +0 -5
package/README.md CHANGED
@@ -175,6 +175,47 @@ generator prisma-ts-select {
175
175
  }
176
176
  ```
177
177
 
178
+ #### Options
179
+
180
+ | Option | Default | Description |
181
+ |--------|---------|-------------|
182
+ | `output` | *(required)* | Output directory, relative to schema file |
183
+ | `packageName` | `prisma-ts-select-<hash>` | Package name in the generated `package.json`. Defaults to a stable hash of the output path — set this when referencing the generated output as a workspace package. |
184
+
185
+ Example with `packageName`:
186
+
187
+ ```prisma
188
+ generator prisma-ts-select {
189
+ provider = "prisma-ts-select"
190
+ output = "../generated/prisma-ts-select"
191
+ packageName = "my-app-prisma-types"
192
+ }
193
+ ```
194
+
195
+ Then register as a workspace package and import by name:
196
+
197
+ **npm / yarn** — `package.json`:
198
+ ```json
199
+ {
200
+ "workspaces": ["generated/prisma-ts-select"]
201
+ }
202
+ ```
203
+
204
+ **pnpm** — `pnpm-workspace.yaml`:
205
+ ```yaml
206
+ packages:
207
+ - generated/prisma-ts-select
208
+ ```
209
+
210
+ Then add it as a dependency:
211
+ ```shell
212
+ pnpm add my-app-prisma-types
213
+ ```
214
+
215
+ ```typescript
216
+ import tsSelectExtend from 'my-app-prisma-types/extend-v7.js'
217
+ ```
218
+
178
219
  The client generator differs between Prisma versions:
179
220
 
180
221
  **Prisma v6**
@@ -325,16 +366,16 @@ The way the methods are chained, are heavily inspired by [Dr Milan Milanović](h
325
366
  This takes the `base` table to work from.
326
367
 
327
368
  #### Example
328
- ```typescript file=../usage/tests/readme/from-basic.ts region=example
369
+ ```typescript file=../usage-sqlite-v7/tests/readme/from-basic.ts region=example-$from
329
370
  prisma.$from("User");
330
371
  ```
331
372
 
332
373
  #### Example - With Table Alias
333
- ```typescript file=../usage/tests/readme/from-inline-alias.ts region=example
374
+ ```typescript file=../usage-sqlite-v7/tests/readme/from-inline-alias.ts region=example-$from
334
375
  prisma.$from("User u");
335
376
  ```
336
377
  ##### SQL
337
- ```sql file=../usage/tests/readme/from-inline-alias.ts region=inline-alias-sql
378
+ ```sql file=../usage-sqlite-v7/tests/readme/from-inline-alias.ts region=inline-alias-sql
338
379
  FROM User AS `u`;
339
380
  ```
340
381
  **Note:** Alias can be inline (space-separated) or as second parameter.
@@ -354,7 +395,7 @@ Chain `.with(name, query)` before `.from()` to define additional CTEs.
354
395
 
355
396
  #### Example — CTE as joined table
356
397
 
357
- ```typescript file=../shared-tests/readme/with-cte.ts region=join
398
+ ```typescript file=../../shared-tests/readme/with-cte.ts region=join
358
399
  const posts = prisma.$from("Post").select("id").select("authorId").select("title");
359
400
 
360
401
  prisma.$with("pp", posts)
@@ -364,15 +405,19 @@ prisma.$with("pp", posts)
364
405
 
365
406
  ##### SQL
366
407
 
367
- ```sql file=../shared-tests/readme/with-cte.ts region=join-sql
368
- WITH pp AS (SELECT id, authorId, title FROM Post) FROM User JOIN pp ON pp.authorId = User.id;
408
+ ```sql file=../../shared-tests/readme/with-cte.ts region=join-sql
409
+ WITH pp AS (
410
+ SELECT id, authorId, title
411
+ FROM Post)
412
+ FROM User
413
+ JOIN pp ON pp.authorId = User.id;
369
414
  ```
370
415
 
371
416
  #### Example — CTE as base table
372
417
 
373
418
  Use `.from('cteName')` to query a CTE directly, without a real table as the base.
374
419
 
375
- ```typescript file=../shared-tests/readme/with-cte.ts region=cte-base
420
+ ```typescript file=../../shared-tests/readme/with-cte.ts region=cte-base
376
421
  const posts = prisma.$from("Post").select("id").select("title");
377
422
 
378
423
  prisma.$with("pp", posts)
@@ -383,15 +428,19 @@ prisma.$with("pp", posts)
383
428
 
384
429
  ##### SQL
385
430
 
386
- ```sql file=../shared-tests/readme/with-cte.ts region=cte-base-sql
387
- WITH pp AS (SELECT id, title FROM Post) SELECT pp.id AS `pp.id`, pp.title AS `pp.title` FROM pp;
431
+ ```sql file=../../shared-tests/readme/with-cte.ts region=cte-base-sql
432
+ WITH pp AS (
433
+ SELECT id, title
434
+ FROM Post)
435
+ SELECT pp.id AS `pp.id`, pp.title AS `pp.title`
436
+ FROM pp;
388
437
  ```
389
438
 
390
439
  **Type safety:** only CTEs declared in `.$with()` / `.with()` are accepted by `.from()`. Unknown CTE names are rejected at compile time.
391
440
 
392
441
  #### Example — Multiple CTEs
393
442
 
394
- ```typescript file=../shared-tests/readme/with-cte.ts region=multi-cte
443
+ ```typescript file=../../shared-tests/readme/with-cte.ts region=multi-cte
395
444
  const posts = prisma.$from("Post").select("id").select("authorId").select("title");
396
445
  const users = prisma.$from("User").select("id").select("name");
397
446
 
@@ -403,8 +452,14 @@ prisma.$with("pp", posts)
403
452
 
404
453
  ##### SQL
405
454
 
406
- ```sql file=../shared-tests/readme/with-cte.ts region=multi-cte-sql
407
- WITH pp AS (SELECT id, authorId, title FROM Post), uu AS (SELECT id, name FROM User) FROM User JOIN pp ON pp.authorId = User.id;
455
+ ```sql file=../../shared-tests/readme/with-cte.ts region=multi-cte-sql
456
+ WITH pp AS (
457
+ SELECT id, authorId, title
458
+ FROM Post), uu AS (
459
+ SELECT id, name
460
+ FROM User)
461
+ FROM User
462
+ JOIN pp ON pp.authorId = User.id;
408
463
  ```
409
464
 
410
465
  ### Table Aliases
@@ -424,7 +479,7 @@ Multiple syntaxes supported:
424
479
  #### Table Aliases with Joins
425
480
 
426
481
  ##### Inline Alias Syntax
427
- ```typescript file=../usage/tests/readme/table-alias.ts region=inline-join
482
+ ```typescript file=../usage-sqlite-v7/tests/readme/table-alias.ts region=inline-join
428
483
  prisma.$from("User u")
429
484
  .join("Post p", "authorId", "u.id")
430
485
  .select("u.name")
@@ -432,7 +487,7 @@ prisma.$from("User u")
432
487
  ```
433
488
 
434
489
  ##### Object Syntax
435
- ```typescript file=../usage/tests/readme/table-alias.ts region=object-join
490
+ ```typescript file=../usage-sqlite-v7/tests/readme/table-alias.ts region=object-join-1
436
491
  prisma.$from("User u")
437
492
  .join({table: "Post", src: "authorId", on: "u.id", alias: "p"})
438
493
  .select("u.name")
@@ -440,9 +495,9 @@ prisma.$from("User u")
440
495
  ```
441
496
 
442
497
  ##### SQL
443
- ```sql file=../usage/tests/readme/table-alias.ts region=inline-join-sql
444
- SELECT name, title
445
- FROM User AS `u`
498
+ ```sql file=../usage-sqlite-v7/tests/readme/table-alias.ts region=inline-join-sql
499
+ SELECT name, title
500
+ FROM User AS `u`
446
501
  JOIN Post AS `p` ON p.authorId = u.id;
447
502
  ```
448
503
 
@@ -452,7 +507,7 @@ JOIN Post AS `p` ON p.authorId = u.id;
452
507
 
453
508
  Self-joins require aliases to distinguish between the different "instances" of the same table:
454
509
 
455
- ```typescript file=../usage/tests/readme/table-alias.ts region=self-join
510
+ ```typescript file=../usage-sqlite-v7/tests/readme/table-alias.ts region=self-join
456
511
  prisma.$from("User u1")
457
512
  .joinUnsafeTypeEnforced("User u2", "id", "u1.id")
458
513
  .select("u1.name", "user1Name")
@@ -460,11 +515,9 @@ prisma.$from("User u1")
460
515
  ```
461
516
 
462
517
  ##### SQL
463
- ```sql file=../usage/tests/readme/table-alias.ts region=self-join-sql
464
- SELECT
465
- u1.name AS `user1Name`,
466
- u2.name AS `user2Name`
467
- FROM User AS `u1`
518
+ ```sql file=../usage-sqlite-v7/tests/readme/table-alias.ts region=self-join-sql
519
+ SELECT u1.name AS `user1Name`, u2.name AS `user2Name`
520
+ FROM User AS `u1`
468
521
  JOIN User AS `u2` ON u2.id = u1.id;
469
522
  ```
470
523
 
@@ -472,23 +525,19 @@ JOIN User AS `u2` ON u2.id = u1.id;
472
525
 
473
526
  You can use the `alias.*` syntax to select all columns from an aliased table:
474
527
 
475
- ```typescript file=../usage/tests/readme/table-alias.ts region=star-single
528
+ ```typescript file=../usage-sqlite-v7/tests/readme/table-alias.ts region=star-single
476
529
  prisma.$from("User u")
477
530
  .select("u.*");
478
531
  ```
479
532
 
480
533
  ##### SQL
481
- ```sql file=../usage/tests/readme/table-alias.ts region=star-single-sql
482
- SELECT
483
- id,
484
- email,
485
- name,
486
- age
534
+ ```sql file=../usage-sqlite-v7/tests/readme/table-alias.ts region=star-single-sql
535
+ SELECT id, email, name, age
487
536
  FROM User AS `u`;
488
537
  ```
489
538
 
490
539
  With joins:
491
- ```typescript file=../usage/tests/readme/table-alias.ts region=star-join
540
+ ```typescript file=../usage-sqlite-v7/tests/readme/table-alias.ts region=star-join
492
541
  prisma.$from("User u")
493
542
  .join("Post p", "authorId", "u.id")
494
543
  .select("u.*")
@@ -496,19 +545,9 @@ prisma.$from("User u")
496
545
  ```
497
546
 
498
547
  ##### SQL
499
- ```sql file=../usage/tests/readme/table-alias.ts region=star-join-sql
500
- SELECT
501
- u.id AS `u.id`,
502
- u.email AS `u.email`,
503
- u.name AS `u.name`,
504
- u.age AS `u.age`,
505
- p.id AS `p.id`,
506
- p.title AS `p.title`,
507
- p.content AS `p.content`,
508
- p.published AS `p.published`,
509
- p.authorId AS `p.authorId`,
510
- p.lastModifiedById AS `p.lastModifiedById`
511
- FROM User AS `u`
548
+ ```sql file=../usage-sqlite-v7/tests/readme/table-alias.ts region=star-join-sql
549
+ SELECT u.id AS `u.id`, u.email AS `u.email`, u.name AS `u.name`, u.age AS `u.age`, p.id AS `p.id`, p.title AS `p.title`, p.content AS `p.content`, p.published AS `p.published`, p.createdAt AS `p.createdAt`, p.authorId AS `p.authorId`, p.lastModifiedById AS `p.lastModifiedById`, p.metadata AS `p.metadata`
550
+ FROM User AS `u`
512
551
  JOIN Post AS `p` ON p.authorId = u.id;
513
552
  ```
514
553
 
@@ -538,7 +577,7 @@ Each method has `*UnsafeTypeEnforced` and `*UnsafeIgnoreType` variants with the
538
577
  Using the defined links (foreign keys) defined in the schema, provides a type-safe way of joining on tables.
539
578
 
540
579
  ##### Example
541
- ```typescript file=../usage/tests/readme/join-basic.ts region=example
580
+ ```typescript file=../usage-sqlite-v7/tests/readme/join-basic.ts region=example
542
581
  prisma.$from("User")
543
582
  .join("Post", "authorId", "User.id");
544
583
  ```
@@ -549,8 +588,8 @@ prisma.$from("User")
549
588
 
550
589
  The resulting SQL will look like:
551
590
 
552
- ```sql file=../usage/tests/readme/join-basic.ts region=join-basic-sql
553
- FROM User
591
+ ```sql file=../usage-sqlite-v7/tests/readme/join-basic.ts region=join-basic-sql
592
+ FROM User
554
593
  JOIN Post ON Post.authorId = User.id;
555
594
  ```
556
595
 
@@ -589,7 +628,8 @@ prisma.$from("User")
589
628
  ```
590
629
 
591
630
  ```sql file=../usage-sqlite-v7/tests/readme/join-type.ts region=join-type-left-sql
592
- FROM User LEFT JOIN Post ON Post.authorId = User.id;
631
+ FROM User
632
+ LEFT JOIN Post ON Post.authorId = User.id;
593
633
  ```
594
634
 
595
635
  `CROSS JOIN` has no `ON` clause — it is suppressed automatically:
@@ -600,7 +640,8 @@ prisma.$from("User")
600
640
  ```
601
641
 
602
642
  ```sql file=../usage-sqlite-v7/tests/readme/join-type.ts region=join-type-cross-sql
603
- FROM User CROSS JOIN Post;
643
+ FROM User
644
+ CROSS JOIN Post;
604
645
  ```
605
646
 
606
647
  `joinType` and `where` can be combined — `where` is ignored for `CROSS`:
@@ -614,7 +655,8 @@ prisma.$from("User")
614
655
  ```
615
656
 
616
657
  ```sql file=../usage-sqlite-v7/tests/readme/join-type.ts region=join-type-with-where-sql
617
- FROM User LEFT JOIN Post ON Post.authorId = User.id AND Post.published = true;
658
+ FROM User
659
+ LEFT JOIN Post ON Post.authorId = User.id AND Post.published = true;
618
660
  ```
619
661
 
620
662
  ##### Join-level WHERE
@@ -627,7 +669,8 @@ prisma.$from("User")
627
669
  ```
628
670
 
629
671
  ```sql file=../usage-sqlite-v7/tests/readme/join-where.ts region=join-where-sql
630
- FROM User JOIN Post ON Post.authorId = User.id AND Post.published = true;
672
+ FROM User
673
+ JOIN Post ON Post.authorId = User.id AND Post.published = true;
631
674
  ```
632
675
 
633
676
  Supports the same MongoDB-inspired operators as `.where()` — `$AND`, `$OR`, `$NOT`, `$NOR`:
@@ -645,7 +688,8 @@ prisma.$from("User")
645
688
  ```
646
689
 
647
690
  ```sql file=../usage-sqlite-v7/tests/readme/join-where.ts region=join-where-ops-sql
648
- FROM User JOIN Post ON Post.authorId = User.id AND (Post.published = true AND Post.id > 0);
691
+ FROM User
692
+ JOIN Post ON Post.authorId = User.id AND (Post.published = true AND Post.id > 0);
649
693
  ```
650
694
 
651
695
  > **Type safety**: only `"JoinedTable.field"` keys are accepted — other tables' fields are rejected at compile time.
@@ -655,7 +699,7 @@ FROM User JOIN Post ON Post.authorId = User.id AND (Post.published = true AND Po
655
699
  Unlike the `.join` command, this will allow you to join on columns that are not explicitly linked by a FK, but have the same type.
656
700
 
657
701
  ##### Example
658
- ```typescript file=../usage/tests/readme/join-unsafe.ts region=type-enforced
702
+ ```typescript file=../usage-sqlite-v7/tests/readme/join-unsafe.ts region=type-enforced
659
703
  prisma.$from("User")
660
704
  .joinUnsafeTypeEnforced("Post", "title", "User.name");
661
705
  ```
@@ -664,8 +708,8 @@ prisma.$from("User")
664
708
  ##### SQL
665
709
  The resulting SQL will look like:
666
710
 
667
- ```sql file=../usage/tests/readme/join-unsafe.ts region=type-enforced-sql
668
- FROM User
711
+ ```sql file=../usage-sqlite-v7/tests/readme/join-unsafe.ts region=type-enforced-sql
712
+ FROM User
669
713
  JOIN Post ON Post.title = User.name;
670
714
  ```
671
715
 
@@ -683,7 +727,7 @@ JOIN Post ON Post.title = User.name;
683
727
  Unlike the `.joinUnsafeIgnoreType` command, this will allow you to join on columns that are not explicitly linked by a FK, and do not have the same type.
684
728
 
685
729
  ##### Example
686
- ```typescript file=../usage/tests/readme/join-unsafe.ts region=ignore-type
730
+ ```typescript file=../usage-sqlite-v7/tests/readme/join-unsafe.ts region=ignore-type
687
731
  prisma.$from("User")
688
732
  .joinUnsafeIgnoreType("Post", "id", "User.name");
689
733
  ```
@@ -692,8 +736,8 @@ prisma.$from("User")
692
736
  ##### SQL
693
737
  The resulting SQL will look like:
694
738
 
695
- ```sql file=../usage/tests/readme/join-unsafe.ts region=ignore-type-sql
696
- FROM User
739
+ ```sql file=../usage-sqlite-v7/tests/readme/join-unsafe.ts region=ignore-type-sql
740
+ FROM User
697
741
  JOIN Post ON Post.id = User.name;
698
742
  ```
699
743
 
@@ -718,7 +762,9 @@ prisma.$from("M2M_Post")
718
762
 
719
763
  ##### SQL
720
764
  ```sql file=../usage-sqlite-v7/tests/readme/join-many-to-many.ts region=m2m-basic-sql
721
- FROM M2M_Post JOIN _M2M_CategoryToM2M_Post ON _M2M_CategoryToM2M_Post.B = M2M_Post.id JOIN M2M_Category ON M2M_Category.id = _M2M_CategoryToM2M_Post.A;
765
+ FROM M2M_Post
766
+ JOIN _M2M_CategoryToM2M_Post ON _M2M_CategoryToM2M_Post.B = M2M_Post.id
767
+ JOIN M2M_Category ON M2M_Category.id = _M2M_CategoryToM2M_Post.A;
722
768
  ```
723
769
 
724
770
  ##### Parameters
@@ -735,7 +781,9 @@ prisma.$from("M2M_Post")
735
781
  ```
736
782
 
737
783
  ```sql file=../usage-sqlite-v7/tests/readme/join-many-to-many.ts region=m2m-alias-sql
738
- FROM M2M_Post JOIN _M2M_CategoryToM2M_Post ON _M2M_CategoryToM2M_Post.B = M2M_Post.id JOIN M2M_Category AS `mc` ON mc.id = _M2M_CategoryToM2M_Post.A;
784
+ FROM M2M_Post
785
+ JOIN _M2M_CategoryToM2M_Post ON _M2M_CategoryToM2M_Post.B = M2M_Post.id
786
+ JOIN M2M_Category AS `mc` ON mc.id = _M2M_CategoryToM2M_Post.A;
739
787
  ```
740
788
 
741
789
  ##### Named Junction (`refName`)
@@ -748,7 +796,9 @@ prisma.$from("MMM_Post")
748
796
  ```
749
797
 
750
798
  ```sql file=../usage-sqlite-v7/tests/readme/join-many-to-many.ts region=m2m-refname-sql
751
- FROM MMM_Post JOIN _M2M_NC_M1 ON _M2M_NC_M1.B = MMM_Post.id JOIN MMM_Category ON MMM_Category.id = _M2M_NC_M1.A;
799
+ FROM MMM_Post
800
+ JOIN _M2M_NC_M1 ON _M2M_NC_M1.B = MMM_Post.id
801
+ JOIN MMM_Category ON MMM_Category.id = _M2M_NC_M1.A;
752
802
  ```
753
803
 
754
804
  ##### Explicit Source (`source`)
@@ -761,7 +811,9 @@ prisma.$from("M2M_Post mp")
761
811
  ```
762
812
 
763
813
  ```sql file=../usage-sqlite-v7/tests/readme/join-many-to-many.ts region=m2m-source-sql
764
- FROM M2M_Post AS `mp` JOIN _M2M_CategoryToM2M_Post ON _M2M_CategoryToM2M_Post.B = mp.id JOIN M2M_Category AS `mc` ON mc.id = _M2M_CategoryToM2M_Post.A;
814
+ FROM M2M_Post AS `mp`
815
+ JOIN _M2M_CategoryToM2M_Post ON _M2M_CategoryToM2M_Post.B = mp.id
816
+ JOIN M2M_Category AS `mc` ON mc.id = _M2M_CategoryToM2M_Post.A;
765
817
  ```
766
818
 
767
819
  #### `.innerJoin`
@@ -769,40 +821,43 @@ FROM M2M_Post AS `mp` JOIN _M2M_CategoryToM2M_Post ON _M2M_CategoryToM2M_Post.B
769
821
  Alias for `.join` — explicitly emits `INNER JOIN`. Same type-safe FK constraints.
770
822
 
771
823
  ##### Example
772
- ```typescript file=../shared-tests/readme/join-inner.ts region=example
824
+ ```typescript file=../../shared-tests/readme/join-inner.ts region=example
773
825
  prisma.$from("User")
774
826
  .innerJoin("Post", "authorId", "User.id")
775
827
  ```
776
828
 
777
829
  ##### SQL
778
- ```sql file=../shared-tests/readme/join-inner.ts region=sql
779
- FROM User INNER JOIN Post ON Post.authorId = User.id;
830
+ ```sql file=../../shared-tests/readme/join-inner.ts region=sql
831
+ FROM User
832
+ INNER JOIN Post ON Post.authorId = User.id;
780
833
  ```
781
834
 
782
835
  ##### `.innerJoinUnsafeTypeEnforced`
783
836
 
784
837
  Same-type column join, INNER semantics.
785
838
 
786
- ```typescript file=../shared-tests/readme/join-inner.ts region=type-enforced
839
+ ```typescript file=../../shared-tests/readme/join-inner.ts region=type-enforced
787
840
  prisma.$from("User")
788
841
  .innerJoinUnsafeTypeEnforced("Post", "title", "User.name")
789
842
  ```
790
843
 
791
- ```sql file=../shared-tests/readme/join-inner.ts region=type-enforced-sql
792
- FROM User INNER JOIN Post ON Post.title = User.name;
844
+ ```sql file=../../shared-tests/readme/join-inner.ts region=type-enforced-sql
845
+ FROM User
846
+ INNER JOIN Post ON Post.title = User.name;
793
847
  ```
794
848
 
795
849
  ##### `.innerJoinUnsafeIgnoreType`
796
850
 
797
851
  Any-column join, INNER semantics.
798
852
 
799
- ```typescript file=../shared-tests/readme/join-inner.ts region=ignore-type
853
+ ```typescript file=../../shared-tests/readme/join-inner.ts region=ignore-type
800
854
  prisma.$from("User")
801
855
  .innerJoinUnsafeIgnoreType("Post", "id", "User.name")
802
856
  ```
803
857
 
804
- ```sql file=../shared-tests/readme/join-inner.ts region=ignore-type-sql
805
- FROM User INNER JOIN Post ON Post.id = User.name;
858
+ ```sql file=../../shared-tests/readme/join-inner.ts region=ignore-type-sql
859
+ FROM User
860
+ INNER JOIN Post ON Post.id = User.name;
806
861
  ```
807
862
 
808
863
  ---
@@ -812,40 +867,43 @@ FROM User INNER JOIN Post ON Post.id = User.name;
812
867
  FK-safe LEFT JOIN. Joined table fields become `T | null` in the result type.
813
868
 
814
869
  ##### Example
815
- ```typescript file=../shared-tests/readme/join-left.ts region=example
870
+ ```typescript file=../../shared-tests/readme/join-left.ts region=example
816
871
  prisma.$from("User")
817
872
  .leftJoin("Post", "authorId", "User.id")
818
873
  ```
819
874
 
820
875
  ##### SQL
821
- ```sql file=../shared-tests/readme/join-left.ts region=sql
822
- FROM User LEFT JOIN Post ON Post.authorId = User.id;
876
+ ```sql file=../../shared-tests/readme/join-left.ts region=sql
877
+ FROM User
878
+ LEFT JOIN Post ON Post.authorId = User.id;
823
879
  ```
824
880
 
825
881
  ##### `.leftJoinUnsafeTypeEnforced`
826
882
 
827
883
  Same-type column join, LEFT semantics.
828
884
 
829
- ```typescript file=../shared-tests/readme/join-left.ts region=type-enforced
885
+ ```typescript file=../../shared-tests/readme/join-left.ts region=type-enforced
830
886
  prisma.$from("User")
831
887
  .leftJoinUnsafeTypeEnforced("Post", "title", "User.name")
832
888
  ```
833
889
 
834
- ```sql file=../shared-tests/readme/join-left.ts region=type-enforced-sql
835
- FROM User LEFT JOIN Post ON Post.title = User.name;
890
+ ```sql file=../../shared-tests/readme/join-left.ts region=type-enforced-sql
891
+ FROM User
892
+ LEFT JOIN Post ON Post.title = User.name;
836
893
  ```
837
894
 
838
895
  ##### `.leftJoinUnsafeIgnoreType`
839
896
 
840
897
  Any-column join, LEFT semantics.
841
898
 
842
- ```typescript file=../shared-tests/readme/join-left.ts region=ignore-type
899
+ ```typescript file=../../shared-tests/readme/join-left.ts region=ignore-type
843
900
  prisma.$from("User")
844
901
  .leftJoinUnsafeIgnoreType("Post", "id", "User.name")
845
902
  ```
846
903
 
847
- ```sql file=../shared-tests/readme/join-left.ts region=ignore-type-sql
848
- FROM User LEFT JOIN Post ON Post.id = User.name;
904
+ ```sql file=../../shared-tests/readme/join-left.ts region=ignore-type-sql
905
+ FROM User
906
+ LEFT JOIN Post ON Post.id = User.name;
849
907
  ```
850
908
 
851
909
  ---
@@ -855,27 +913,29 @@ FROM User LEFT JOIN Post ON Post.id = User.name;
855
913
  Produces a cartesian product — no `ON` clause. All dialects supported.
856
914
 
857
915
  ##### Example
858
- ```typescript file=../shared-tests/readme/join-cross.ts region=example
916
+ ```typescript file=../../shared-tests/readme/join-cross.ts region=example
859
917
  prisma.$from("User")
860
918
  .crossJoin("Post")
861
919
  ```
862
920
 
863
921
  ##### SQL
864
- ```sql file=../shared-tests/readme/join-cross.ts region=sql
865
- FROM User CROSS JOIN Post;
922
+ ```sql file=../../shared-tests/readme/join-cross.ts region=sql
923
+ FROM User
924
+ CROSS JOIN Post;
866
925
  ```
867
926
 
868
927
  ##### `.crossJoinUnsafeTypeEnforced` / `.crossJoinUnsafeIgnoreType`
869
928
 
870
929
  Type-permission variants — still emit `CROSS JOIN` with no `ON` clause (takes only a table argument).
871
930
 
872
- ```typescript file=../shared-tests/readme/join-cross.ts region=type-enforced
931
+ ```typescript file=../../shared-tests/readme/join-cross.ts region=type-enforced
873
932
  prisma.$from("User")
874
933
  .crossJoinUnsafeTypeEnforced("Post")
875
934
  ```
876
935
 
877
- ```sql file=../shared-tests/readme/join-cross.ts region=type-enforced-sql
878
- FROM User CROSS JOIN Post;
936
+ ```sql file=../../shared-tests/readme/join-cross.ts region=type-enforced-sql
937
+ FROM User
938
+ CROSS JOIN Post;
879
939
  ```
880
940
 
881
941
  ---
@@ -993,7 +1053,7 @@ type WhereClause = {
993
1053
 
994
1054
 
995
1055
  ###### Columns
996
- ```typescript file=../usage/tests/readme/where.ts region=columns
1056
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=columns
997
1057
  prisma.$from("User")
998
1058
  .joinUnsafeIgnoreType("Post", "id", "User.name")
999
1059
  .where({
@@ -1003,7 +1063,7 @@ prisma.$from("User")
1003
1063
  ```
1004
1064
 
1005
1065
  ###### $AND
1006
- ```typescript file=../usage/tests/readme/where.ts region=and
1066
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=and
1007
1067
  prisma.$from("User")
1008
1068
  .joinUnsafeIgnoreType("Post", "id", "User.name")
1009
1069
  .where({
@@ -1015,7 +1075,7 @@ prisma.$from("User")
1015
1075
  ```
1016
1076
 
1017
1077
  ###### $OR
1018
- ```typescript file=../usage/tests/readme/where.ts region=or
1078
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=or
1019
1079
  prisma.$from("User")
1020
1080
  .joinUnsafeIgnoreType("Post", "id", "User.name")
1021
1081
  .where({
@@ -1027,7 +1087,7 @@ prisma.$from("User")
1027
1087
  ```
1028
1088
 
1029
1089
  ###### $NOT
1030
- ```typescript file=../usage/tests/readme/where.ts region=not
1090
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=not
1031
1091
  prisma.$from("User")
1032
1092
  .joinUnsafeIgnoreType("Post", "id", "User.name")
1033
1093
  .where({
@@ -1042,7 +1102,7 @@ prisma.$from("User")
1042
1102
  ```
1043
1103
 
1044
1104
  ###### $NOR
1045
- ```typescript file=../usage/tests/readme/where.ts region=nor
1105
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=nor
1046
1106
  prisma.$from("User")
1047
1107
  .joinUnsafeIgnoreType("Post", "id", "User.name")
1048
1108
  .where({
@@ -1057,7 +1117,7 @@ prisma.$from("User")
1057
1117
  ```
1058
1118
 
1059
1119
  ###### Array (Scalar → IN)
1060
- ```typescript file=../usage/tests/readme/where.ts region=array-scalar
1120
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=array-scalar
1061
1121
  prisma.$from("User")
1062
1122
  .joinUnsafeIgnoreType("Post", "id", "User.name")
1063
1123
  .where({
@@ -1066,7 +1126,7 @@ prisma.$from("User")
1066
1126
  ```
1067
1127
 
1068
1128
  ###### Array (Op-Object → OR)
1069
- ```typescript file=../usage/tests/readme/where.ts region=array-op
1129
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=array-op
1070
1130
  prisma.$from("User")
1071
1131
  .joinUnsafeIgnoreType("Post", "id", "User.name")
1072
1132
  .where({
@@ -1094,7 +1154,9 @@ prisma.$from("User")
1094
1154
  The resulting SQL will look like:
1095
1155
 
1096
1156
  ```sql file=../usage-sqlite-v7/tests/readme/whereNotNull.ts region=whereNotNull-sql
1097
- FROM User JOIN Post ON Post.authorId = User.id WHERE (User.name IS NOT NULL);
1157
+ FROM User
1158
+ JOIN Post ON Post.authorId = User.id
1159
+ WHERE (User.name IS NOT NULL);
1098
1160
  ```
1099
1161
 
1100
1162
  #### `.whereIsNull`
@@ -1113,21 +1175,25 @@ prisma.$from("User")
1113
1175
  The resulting SQL will look like:
1114
1176
 
1115
1177
  ```sql file=../usage-sqlite-v7/tests/readme/whereNotNull.ts region=whereIsNull-sql
1116
- FROM User JOIN Post ON Post.authorId = User.id WHERE (Post.content IS NULL);
1178
+ FROM User
1179
+ JOIN Post ON Post.authorId = User.id
1180
+ WHERE (Post.content IS NULL);
1117
1181
  ```
1118
1182
 
1119
1183
  #### `.where` — fn overload (SQL expressions)
1120
1184
 
1121
1185
  Pass a callback instead of a criteria object to apply SQL functions as conditions. The callback receives the same select-fn context as `.select()`, giving access to `upper`, `lower`, `length`, `count`, `avg`, etc.
1122
1186
 
1123
- ```typescript file=../shared-tests/readme/where.ts region=fn-upper-like
1187
+ ```typescript file=../../shared-tests/readme/where.ts region=fn-upper-like
1124
1188
  prisma.$from("User")
1125
1189
  .where(({ upper }) => [[upper('name'), { op: 'LIKE', value: 'John%' }]])
1126
1190
  .select("name")
1127
1191
  ```
1128
1192
 
1129
- ```sql file=../shared-tests/readme/where.ts region=fn-upper-like-sql
1130
- SELECT name FROM User WHERE UPPER(name) LIKE 'John%';
1193
+ ```sql file=../../shared-tests/readme/where.ts region=fn-upper-like-sql
1194
+ SELECT name
1195
+ FROM User
1196
+ WHERE UPPER(name) LIKE 'John%';
1131
1197
  ```
1132
1198
 
1133
1199
  Each array element is an `[SQLExpr<T>, condition]` pair — multiple pairs are AND-ed. The condition type is inferred from `SQLExpr<T>`: string expressions accept LIKE/NOT LIKE, numeric expressions accept `>`, `<`, BETWEEN, etc.
@@ -1137,7 +1203,7 @@ Each array element is an `[SQLExpr<T>, condition]` pair — multiple pairs are A
1137
1203
  When you want to write a complex `where`, or you just don't want the TypeSafety offered by the other methods, you can use `.whereRaw`.
1138
1204
 
1139
1205
  ##### Example
1140
- ```typescript file=../usage/tests/readme/where.ts region=raw
1206
+ ```typescript file=../usage-sqlite-v7/tests/readme/where.ts region=raw
1141
1207
  prisma.$from("User")
1142
1208
  .join("Post", "authorId", "User.id")
1143
1209
  .whereRaw("this is a raw where statement");
@@ -1146,11 +1212,11 @@ prisma.$from("User")
1146
1212
  ##### SQL
1147
1213
  The resulting SQL will look like:
1148
1214
 
1149
- ```sql file=../usage/tests/readme/where.ts region=raw-sql
1150
- FROM User
1151
- JOIN Post ON Post.authorId = User.id
1152
- WHERE this is a raw
1153
- WHERE statement;
1215
+ ```sql file=../usage-sqlite-v7/tests/readme/where.ts region=raw-sql
1216
+ FROM User
1217
+ JOIN Post ON Post.authorId = User.id
1218
+ WHERE this is a raw
1219
+ where statement;
1154
1220
  ```
1155
1221
 
1156
1222
 
@@ -1159,7 +1225,7 @@ WHERE statement;
1159
1225
  Will allow you to pass a list of columns, that haven been specified from the `.$from` and any `.join` methods.
1160
1226
 
1161
1227
  #### Example
1162
- ```typescript file=../usage/tests/readme/groupby.ts region=basic
1228
+ ```typescript file=../usage-sqlite-v7/tests/readme/groupby.ts region=basic
1163
1229
  prisma.$from("User")
1164
1230
  .join("Post", "authorId", "User.id")
1165
1231
  .groupBy(["name", "Post.content"]);
@@ -1169,9 +1235,9 @@ prisma.$from("User")
1169
1235
  #### SQL
1170
1236
  The resulting SQL will look like:
1171
1237
 
1172
- ```sql file=../usage/tests/readme/groupby.ts region=basic-sql
1173
- FROM User
1174
- JOIN Post ON Post.authorId = User.id
1238
+ ```sql file=../usage-sqlite-v7/tests/readme/groupby.ts region=basic-sql
1239
+ FROM User
1240
+ JOIN Post ON Post.authorId = User.id
1175
1241
  GROUP BY name, Post.content;
1176
1242
  ```
1177
1243
 
@@ -1182,17 +1248,17 @@ GROUP BY name, Post.content;
1182
1248
  Will add the keyword `DISTINCT` after the select.
1183
1249
 
1184
1250
  #### Example
1185
- ```typescript file=../usage/tests/readme/select-advanced.ts region=distinct
1251
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=distinct
1186
1252
  prisma.$from("User")
1187
1253
  .selectDistinct()
1188
- .select("name");
1254
+ .select("User.name");
1189
1255
  ```
1190
1256
 
1191
1257
  #### SQL
1192
1258
  The resulting SQL will look like:
1193
1259
 
1194
- ```sql file=../usage/tests/readme/select-advanced.ts region=distinct-sql
1195
- SELECT DISTINCT name
1260
+ ```sql file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=distinct-sql
1261
+ SELECT DISTINCT name
1196
1262
  FROM User;
1197
1263
  ```
1198
1264
 
@@ -1203,7 +1269,7 @@ This method will explicitly list all the tables from the `$from` and `.join`. So
1203
1269
 
1204
1270
 
1205
1271
  #### Example - Single Table
1206
- ```typescript file=../usage/tests/readme/select-advanced.ts region=all-single
1272
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=all-single
1207
1273
  prisma.$from("User")
1208
1274
  .selectAll();
1209
1275
  ```
@@ -1211,17 +1277,13 @@ prisma.$from("User")
1211
1277
  ##### SQL
1212
1278
  The resulting SQL will look like:
1213
1279
 
1214
- ```sql file=../usage/tests/readme/select-advanced.ts region=all-single-sql
1215
- SELECT
1216
- id,
1217
- email,
1218
- name,
1219
- age
1280
+ ```sql file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=all-single-sql
1281
+ SELECT id, email, name, age
1220
1282
  FROM User;
1221
1283
  ```
1222
1284
 
1223
1285
  #### Example - Join table
1224
- ```typescript file=../usage/tests/readme/select-advanced.ts region=all-join
1286
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=all-join
1225
1287
  prisma.$from("User")
1226
1288
  .join("Post", "authorId", "User.id")
1227
1289
  .selectAll();
@@ -1230,19 +1292,9 @@ prisma.$from("User")
1230
1292
  ##### SQL
1231
1293
  The resulting SQL will look like:
1232
1294
 
1233
- ```sql file=../usage/tests/readme/select-advanced.ts region=all-join-sql
1234
- SELECT
1235
- User.id AS `User.id`,
1236
- User.email AS `User.email`,
1237
- User.name AS `User.name`,
1238
- User.age AS `User.age`,
1239
- Post.id AS `Post.id`,
1240
- Post.title AS `Post.title`,
1241
- Post.content AS `Post.content`,
1242
- Post.published AS `Post.published`,
1243
- Post.authorId AS `Post.authorId`,
1244
- Post.lastModifiedById AS `Post.lastModifiedById`
1245
- FROM User
1295
+ ```sql file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=all-join-sql
1296
+ SELECT User.id AS `User.id`, User.email AS `User.email`, User.name AS `User.name`, User.age AS `User.age`, Post.id AS `Post.id`, Post.title AS `Post.title`, Post.content AS `Post.content`, Post.published AS `Post.published`, Post.createdAt AS `Post.createdAt`, Post.authorId AS `Post.authorId`, Post.lastModifiedById AS `Post.lastModifiedById`, Post.metadata AS `Post.metadata`
1297
+ FROM User
1246
1298
  JOIN Post ON Post.authorId = User.id;
1247
1299
  ```
1248
1300
 
@@ -1258,7 +1310,8 @@ prisma.$from("User")
1258
1310
 
1259
1311
  ##### SQL
1260
1312
  ```sql file=../usage-sqlite-v7/tests/readme/select-all-omit.ts region=single-omit-sql
1261
- SELECT id, name, age FROM User;
1313
+ SELECT `id`, `name`, `age`
1314
+ FROM `User`;
1262
1315
  ```
1263
1316
 
1264
1317
  #### Example - Multiple Columns
@@ -1281,7 +1334,7 @@ prisma.$from("User")
1281
1334
  You can supply either; `*`, `Table.*` OR `table.field` and then chain them together.
1282
1335
 
1283
1336
  #### Example - `*`
1284
- ```typescript file=../usage/tests/readme/select-star.ts region=example
1337
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-star.ts region=example
1285
1338
  prisma.$from("User")
1286
1339
  .select("*");
1287
1340
  ```
@@ -1289,13 +1342,13 @@ prisma.$from("User")
1289
1342
  ##### SQL
1290
1343
  The resulting SQL will look like:
1291
1344
 
1292
- ```sql file=../usage/tests/readme/select-star.ts region=example-sql
1293
- SELECT *
1345
+ ```sql file=../usage-sqlite-v7/tests/readme/select-star.ts region=example-sql
1346
+ SELECT *
1294
1347
  FROM User;
1295
1348
  ```
1296
1349
 
1297
1350
  #### Example - `Table.*` (Single Table)
1298
- ```typescript file=../usage/tests/readme/select-advanced.ts region=table-star-single
1351
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=table-star-single
1299
1352
  prisma.$from("User")
1300
1353
  .select("User.*");
1301
1354
  ```
@@ -1303,17 +1356,13 @@ prisma.$from("User")
1303
1356
  ##### SQL
1304
1357
  The resulting SQL will look like:
1305
1358
 
1306
- ```sql file=../usage/tests/readme/select-advanced.ts region=table-star-single-sql
1307
- SELECT
1308
- id,
1309
- email,
1310
- name,
1311
- age
1359
+ ```sql file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=table-star-single-sql
1360
+ SELECT id, email, name, age
1312
1361
  FROM User;
1313
1362
  ```
1314
1363
 
1315
1364
  #### Example - `Table.*` (With Join)
1316
- ```typescript file=../usage/tests/readme/select-advanced.ts region=table-star-join
1365
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=table-star-join
1317
1366
  prisma.$from("User")
1318
1367
  .join("Post", "authorId", "User.id")
1319
1368
  .select("User.*")
@@ -1323,19 +1372,9 @@ prisma.$from("User")
1323
1372
  ##### SQL
1324
1373
  The resulting SQL will look like:
1325
1374
 
1326
- ```sql file=../usage/tests/readme/select-advanced.ts region=table-star-join-sql
1327
- SELECT
1328
- User.id AS `User.id`,
1329
- User.email AS `User.email`,
1330
- User.name AS `User.name`,
1331
- User.age AS `User.age`,
1332
- Post.id AS `Post.id`,
1333
- Post.title AS `Post.title`,
1334
- Post.content AS `Post.content`,
1335
- Post.published AS `Post.published`,
1336
- Post.authorId AS `Post.authorId`,
1337
- Post.lastModifiedById AS `Post.lastModifiedById`
1338
- FROM User
1375
+ ```sql file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=table-star-join-sql
1376
+ SELECT User.id AS `User.id`, User.email AS `User.email`, User.name AS `User.name`, User.age AS `User.age`, Post.id AS `Post.id`, Post.title AS `Post.title`, Post.content AS `Post.content`, Post.published AS `Post.published`, Post.createdAt AS `Post.createdAt`, Post.authorId AS `Post.authorId`, Post.lastModifiedById AS `Post.lastModifiedById`, Post.metadata AS `Post.metadata`
1377
+ FROM User
1339
1378
  JOIN Post ON Post.authorId = User.id;
1340
1379
  ```
1341
1380
 
@@ -1343,7 +1382,7 @@ JOIN Post ON Post.authorId = User.id;
1343
1382
  > When using `Table.*` with joins, all columns are automatically aliased with the table name prefix to avoid column name conflicts.
1344
1383
 
1345
1384
  #### Example - Chained
1346
- ```typescript file=../usage/tests/readme/select-chained.ts region=example
1385
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-chained.ts region=example
1347
1386
  prisma.$from("User")
1348
1387
  .select("name")
1349
1388
  .select("email");
@@ -1352,13 +1391,13 @@ prisma.$from("User")
1352
1391
  ##### SQL
1353
1392
  The resulting SQL will look like:
1354
1393
 
1355
- ```sql file=../usage/tests/readme/select-chained.ts region=example-sql
1356
- SELECT name, email
1394
+ ```sql file=../usage-sqlite-v7/tests/readme/select-chained.ts region=example-sql
1395
+ SELECT name, email
1357
1396
  FROM User;
1358
1397
  ```
1359
1398
 
1360
1399
  #### Example - Join + Chained
1361
- ```typescript file=../usage/tests/readme/select-advanced.ts region=join-chained
1400
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=join-chained
1362
1401
  prisma.$from("User")
1363
1402
  .join("Post", "authorId", "User.id")
1364
1403
  .select("name")
@@ -1368,25 +1407,25 @@ prisma.$from("User")
1368
1407
  ##### SQL
1369
1408
  The resulting SQL will look like:
1370
1409
 
1371
- ```sql file=../usage/tests/readme/select-advanced.ts region=join-chained-sql
1372
- SELECT name, title
1373
- FROM User
1410
+ ```sql file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=join-chained-sql
1411
+ SELECT name, title
1412
+ FROM User
1374
1413
  JOIN Post ON Post.authorId = User.id;
1375
1414
  ```
1376
1415
 
1377
1416
  #### Example - Column Aliases
1378
- ```typescript file=../usage/tests/readme/select-column-alias.ts region=basic
1417
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-column-alias.ts region=basic
1379
1418
  prisma.$from("User")
1380
1419
  .select("User.name", "username");
1381
1420
  ```
1382
1421
 
1383
- ```typescript file=../usage/tests/readme/select-column-alias.ts region=multiple
1422
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-column-alias.ts region=multiple
1384
1423
  prisma.$from("User")
1385
1424
  .select("User.id", "userId")
1386
1425
  .select("User.email", "emailAddress");
1387
1426
  ```
1388
1427
 
1389
- ```typescript file=../usage/tests/readme/select-column-alias.ts region=mixed
1428
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-column-alias.ts region=mixed
1390
1429
  prisma.$from("User")
1391
1430
  .select("User.id")
1392
1431
  .select("User.name", "username")
@@ -1396,28 +1435,23 @@ prisma.$from("User")
1396
1435
  ##### SQL
1397
1436
  The resulting SQL will look like:
1398
1437
 
1399
- ```sql file=../usage/tests/readme/select-column-alias.ts region=basic-sql
1400
- SELECT User.name AS `username`
1438
+ ```sql file=../usage-sqlite-v7/tests/readme/select-column-alias.ts region=basic-sql
1439
+ SELECT User.name AS `username`
1401
1440
  FROM User;
1402
1441
  ```
1403
1442
 
1404
- ```sql file=../usage/tests/readme/select-column-alias.ts region=multiple-sql
1405
- SELECT
1406
- User.id AS `userId`,
1407
- User.email AS `emailAddress`
1443
+ ```sql file=../usage-sqlite-v7/tests/readme/select-column-alias.ts region=multiple-sql
1444
+ SELECT User.id AS `userId`, User.email AS `emailAddress`
1408
1445
  FROM User;
1409
1446
  ```
1410
1447
 
1411
- ```sql file=../usage/tests/readme/select-column-alias.ts region=mixed-sql
1412
- SELECT
1413
- id,
1414
- User.name AS `username`,
1415
- email
1448
+ ```sql file=../usage-sqlite-v7/tests/readme/select-column-alias.ts region=mixed-sql
1449
+ SELECT id, User.name AS `username`, email
1416
1450
  FROM User;
1417
1451
  ```
1418
1452
 
1419
1453
  #### Example - Aliases with Joins
1420
- ```typescript file=../usage/tests/readme/select-advanced.ts region=aliases-joins
1454
+ ```typescript file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=aliases-joins
1421
1455
  prisma.$from("User")
1422
1456
  .join("Post", "authorId", "User.id")
1423
1457
  .select("User.name", "authorName")
@@ -1427,11 +1461,9 @@ prisma.$from("User")
1427
1461
  ##### SQL
1428
1462
  The resulting SQL will look like:
1429
1463
 
1430
- ```sql file=../usage/tests/readme/select-advanced.ts region=aliases-joins-sql
1431
- SELECT
1432
- User.name AS `authorName`,
1433
- Post.title AS `postTitle`
1434
- FROM User
1464
+ ```sql file=../usage-sqlite-v7/tests/readme/select-advanced.ts region=aliases-joins-sql
1465
+ SELECT User.name AS `authorName`, Post.title AS `postTitle`
1466
+ FROM User
1435
1467
  JOIN Post ON Post.authorId = User.id;
1436
1468
  ```
1437
1469
 
@@ -1444,7 +1476,7 @@ JOIN Post ON Post.authorId = User.id;
1444
1476
 
1445
1477
  #### Criteria object
1446
1478
 
1447
- ```typescript file=../shared-tests/readme/having.ts region=with-groupby
1479
+ ```typescript file=../../shared-tests/readme/having.ts region=with-groupby
1448
1480
  prisma.$from("User")
1449
1481
  .join("Post", "authorId", "User.id")
1450
1482
  .groupBy(["name", "Post.content"])
@@ -1454,11 +1486,14 @@ prisma.$from("User")
1454
1486
  "value": "bob%"
1455
1487
  }
1456
1488
  })
1457
- .select("*");
1489
+ .select("email");
1458
1490
  ```
1459
1491
 
1460
- ```sql file=../shared-tests/readme/having.ts region=with-groupby-sql
1461
- SELECT * FROM User JOIN Post ON Post.authorId = User.id GROUP BY name, Post.content HAVING User.name LIKE 'bob%';
1492
+ ```sql file=../../shared-tests/readme/having.ts region=with-groupby-sql
1493
+ SELECT email
1494
+ FROM User
1495
+ JOIN Post ON Post.authorId = User.id
1496
+ GROUP BY name, Post.content HAVING User.name LIKE 'bob%';
1462
1497
  ```
1463
1498
 
1464
1499
  #### fn overload — aggregate functions
@@ -1467,7 +1502,7 @@ Pass a callback returning `Array<[SQLExpr<T>, condition]>` pairs. The callback r
1467
1502
 
1468
1503
  ##### `countAll()` with comparison op
1469
1504
 
1470
- ```typescript file=../shared-tests/readme/having.ts region=agg-fn-tuple-countall
1505
+ ```typescript file=../../shared-tests/readme/having.ts region=agg-fn-tuple-countall
1471
1506
  prisma.$from("User")
1472
1507
  .join("Post", "authorId", "User.id")
1473
1508
  .groupBy(["User.name"])
@@ -1475,13 +1510,16 @@ prisma.$from("User")
1475
1510
  .select("User.name")
1476
1511
  ```
1477
1512
 
1478
- ```sql file=../shared-tests/readme/having.ts region=agg-fn-tuple-countall-sql
1479
- SELECT name FROM User JOIN Post ON Post.authorId = User.id GROUP BY User.name HAVING COUNT(*) > 1;
1513
+ ```sql file=../../shared-tests/readme/having.ts region=agg-fn-tuple-countall-sql
1514
+ SELECT name
1515
+ FROM User
1516
+ JOIN Post ON Post.authorId = User.id
1517
+ GROUP BY User.name HAVING COUNT(*) > 1;
1480
1518
  ```
1481
1519
 
1482
1520
  ##### `count(col)` with bigint value
1483
1521
 
1484
- ```typescript file=../shared-tests/readme/having.ts region=agg-fn-tuple-count
1522
+ ```typescript file=../../shared-tests/readme/having.ts region=agg-fn-tuple-count
1485
1523
  prisma.$from("User")
1486
1524
  .join("Post", "authorId", "User.id")
1487
1525
  .groupBy(["User.name"])
@@ -1489,13 +1527,16 @@ prisma.$from("User")
1489
1527
  .select("User.name")
1490
1528
  ```
1491
1529
 
1492
- ```sql file=../shared-tests/readme/having.ts region=agg-fn-tuple-count-sql
1493
- SELECT name FROM User JOIN Post ON Post.authorId = User.id GROUP BY User.name HAVING COUNT(User.id) >= 2;
1530
+ ```sql file=../../shared-tests/readme/having.ts region=agg-fn-tuple-count-sql
1531
+ SELECT name
1532
+ FROM User
1533
+ JOIN Post ON Post.authorId = User.id
1534
+ GROUP BY User.name HAVING COUNT(User.id) >= 2;
1494
1535
  ```
1495
1536
 
1496
1537
  ##### String expr — `upper(col)` LIKE
1497
1538
 
1498
- ```typescript file=../shared-tests/readme/having.ts region=agg-fn-string-upper
1539
+ ```typescript file=../../shared-tests/readme/having.ts region=agg-fn-string-upper
1499
1540
  prisma.$from("User")
1500
1541
  .join("Post", "authorId", "User.id")
1501
1542
  .groupBy(["User.name"])
@@ -1503,8 +1544,11 @@ prisma.$from("User")
1503
1544
  .select("User.name")
1504
1545
  ```
1505
1546
 
1506
- ```sql file=../shared-tests/readme/having.ts region=agg-fn-string-upper-sql
1507
- SELECT name FROM User JOIN Post ON Post.authorId = User.id GROUP BY User.name HAVING UPPER(User.name) LIKE 'John%';
1547
+ ```sql file=../../shared-tests/readme/having.ts region=agg-fn-string-upper-sql
1548
+ SELECT name
1549
+ FROM User
1550
+ JOIN Post ON Post.authorId = User.id
1551
+ GROUP BY User.name HAVING UPPER(User.name) LIKE 'John%';
1508
1552
  ```
1509
1553
 
1510
1554
  Multiple pairs in one `.having()` call are AND-ed together. `.having()` can also be chained — each call appends an AND condition.
@@ -1515,7 +1559,7 @@ Multiple pairs in one `.having()` call are AND-ed together. `.having()` can also
1515
1559
 
1516
1560
  #### Example
1517
1561
 
1518
- ```typescript file=../usage/tests/readme/orderby.ts region=basic
1562
+ ```typescript file=../usage-sqlite-v7/tests/readme/orderby.ts region=basic
1519
1563
  prisma.$from("User")
1520
1564
  .join("Post", "authorId", "User.id")
1521
1565
  .orderBy(["name", "Post.content DESC"]);
@@ -1523,9 +1567,9 @@ prisma.$from("User")
1523
1567
 
1524
1568
  ##### SQL
1525
1569
 
1526
- ```sql file=../usage/tests/readme/orderby.ts region=basic-sql
1527
- FROM User
1528
- JOIN Post ON Post.authorId = User.id
1570
+ ```sql file=../usage-sqlite-v7/tests/readme/orderby.ts region=basic-sql
1571
+ FROM User
1572
+ JOIN Post ON Post.authorId = User.id
1529
1573
  ORDER BY name, Post.content DESC;
1530
1574
  ```
1531
1575
 
@@ -1535,7 +1579,7 @@ ORDER BY name, Post.content DESC;
1535
1579
 
1536
1580
  #### Example
1537
1581
 
1538
- ```typescript file=../usage/tests/readme/pagination.ts region=limit
1582
+ ```typescript file=../usage-sqlite-v7/tests/readme/pagination.ts region=limit
1539
1583
  prisma.$from("User")
1540
1584
  .join("Post", "authorId", "User.id")
1541
1585
  .limit(1);
@@ -1543,9 +1587,9 @@ prisma.$from("User")
1543
1587
 
1544
1588
  ##### SQL
1545
1589
 
1546
- ```sql file=../usage/tests/readme/pagination.ts region=limit-sql
1547
- FROM User
1548
- JOIN Post ON Post.authorId = User.id
1590
+ ```sql file=../usage-sqlite-v7/tests/readme/pagination.ts region=limit-sql
1591
+ FROM User
1592
+ JOIN Post ON Post.authorId = User.id
1549
1593
  LIMIT 1;
1550
1594
  ```
1551
1595
 
@@ -1554,7 +1598,7 @@ LIMIT 1;
1554
1598
  `.offSet`, the number of rows to skip. Requires `.limit` to have been used first.
1555
1599
 
1556
1600
  #### Example
1557
- ```typescript file=../usage/tests/readme/pagination.ts region=offset
1601
+ ```typescript file=../usage-sqlite-v7/tests/readme/pagination.ts region=offset
1558
1602
  prisma.$from("User")
1559
1603
  .join("Post", "authorId", "User.id")
1560
1604
  .limit(1)
@@ -1563,10 +1607,10 @@ prisma.$from("User")
1563
1607
 
1564
1608
  ##### SQL
1565
1609
 
1566
- ```sql file=../usage/tests/readme/pagination.ts region=offset-sql
1567
- FROM User
1568
- JOIN Post ON Post.authorId = User.id
1569
- LIMIT 1
1610
+ ```sql file=../usage-sqlite-v7/tests/readme/pagination.ts region=offset-sql
1611
+ FROM User
1612
+ JOIN Post ON Post.authorId = User.id
1613
+ LIMIT 1
1570
1614
  OFFSET 1;
1571
1615
  ```
1572
1616
 
@@ -1598,7 +1642,8 @@ prisma.$from("User")
1598
1642
 
1599
1643
  ##### SQL
1600
1644
  ```sql file=../usage-sqlite-v7/tests/readme/select-fns.ts region=count-all-sql
1601
- SELECT COUNT(*) AS `total` FROM User;
1645
+ SELECT COUNT(*) AS `total`
1646
+ FROM User;
1602
1647
  ```
1603
1648
 
1604
1649
  #### `count(col)` — COUNT(col)
@@ -1772,6 +1817,7 @@ GROUP BY User.name;
1772
1817
 
1773
1818
  | Function | SQL | Returns |
1774
1819
  |---|---|---|
1820
+ | `distinct(col)` | `DISTINCT col` | `ColType` (use inside `avg`, `sum`, `count`, `groupConcat`) |
1775
1821
  | `groupConcat(col, sep?)` | `GROUP_CONCAT(col SEPARATOR sep)` | `string` |
1776
1822
  | `bitAnd(col)` | `BIT_AND(col)` | `number` |
1777
1823
  | `bitOr(col)` | `BIT_OR(col)` | `number` |
@@ -1826,6 +1872,7 @@ GROUP BY User.name;
1826
1872
  |---|---|---|
1827
1873
  | `greatest(...args)` | `GREATEST(a, b, ...)` | `T` |
1828
1874
  | `least(...args)` | `LEAST(a, b, ...)` | `T` |
1875
+ | `distinct(col)` | `DISTINCT col` | `ColType` (use inside `avg`, `sum`, `count`, `stringAgg`, `arrayAgg`) |
1829
1876
  | `stringAgg(col, sep)` | `STRING_AGG(col, sep)` | `string` |
1830
1877
  | `arrayAgg(col)` | `ARRAY_AGG(col)` | `unknown[]` |
1831
1878
  | `stddevPop(col)` | `STDDEV_POP(col)` | `number` |
@@ -1877,6 +1924,7 @@ GROUP BY User.name;
1877
1924
  |---|---|---|
1878
1925
  | `iif(cond, trueVal, falseVal)` | `IIF(cond, a, b)` | `T` |
1879
1926
  | `ifNull(col, fallback)` | `IFNULL(col, fallback)` | `NonNullable<T>` |
1927
+ | `distinct(col)` | `DISTINCT col` | `ColType` (use inside `avg`, `sum`, `count`, `groupConcat`; sep with ≥ 3.44) |
1880
1928
  | `groupConcat(col, sep?)` | `GROUP_CONCAT(col, sep)` | `string` |
1881
1929
  | `total(col)` | `TOTAL(col)` | `number` |
1882
1930
  | `concat(...cols)` | `a \|\| b \|\| ...` | `string` |
@@ -1900,6 +1948,12 @@ GROUP BY User.name;
1900
1948
 
1901
1949
  ---
1902
1950
 
1951
+ ## Security
1952
+
1953
+ All queries execute via Prisma's `$queryRawUnsafe`. The `esc()` helper escapes single quotes in string literals, but **never pass user-supplied values directly** to query builder methods — use Prisma's parameterized queries for user input.
1954
+
1955
+ `whereRaw()` in particular inserts SQL verbatim. Only use it with trusted, static SQL strings.
1956
+
1903
1957
  ## Future updates
1904
1958
 
1905
1959
  - Support specifying `JOIN` type [issue#2](https://github.com/adrianbrowning/prisma-ts-select/issues/2)