@prisma/orm-mongo 8.0.0-rc.9-dev.13 → 8.0.1-dev.1

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 (150) hide show
  1. package/README.md +48 -8
  2. package/dist/components-CWskH7lF-Dkc9ysZz.mjs +18 -0
  3. package/dist/components-CWskH7lF-Dkc9ysZz.mjs.map +1 -0
  4. package/dist/config.d.mts +14 -5
  5. package/dist/config.d.mts.map +1 -1
  6. package/dist/config.mjs +47 -25
  7. package/dist/config.mjs.map +1 -1
  8. package/dist/contract-builder.d.mts +33 -91
  9. package/dist/contract-builder.d.mts.map +1 -1
  10. package/dist/contract-builder.mjs +23 -7
  11. package/dist/contract-builder.mjs.map +1 -1
  12. package/dist/contract-types.d.mts +3 -0
  13. package/dist/contract-types.mjs +1 -0
  14. package/dist/contract__format-version.d.mts +1 -0
  15. package/dist/contract__format-version.mjs +2 -0
  16. package/dist/contract__internal__format-version.d.mts +1 -0
  17. package/dist/contract__internal__format-version.mjs +2 -0
  18. package/dist/contract__validate-once.d.mts +1 -0
  19. package/dist/contract__validate-once.mjs +2 -0
  20. package/dist/contract__validate-storage.d.mts +1 -0
  21. package/dist/contract__validate-storage.mjs +2 -0
  22. package/dist/control.d.mts +1 -1
  23. package/dist/control.d.mts.map +1 -1
  24. package/dist/control.mjs +3 -9
  25. package/dist/control.mjs.map +1 -1
  26. package/dist/driver__runtime.d.mts +3 -0
  27. package/dist/driver__runtime.mjs +3 -0
  28. package/dist/family-contract__data-type.d.mts +1 -0
  29. package/dist/family-contract__data-type.mjs +2 -0
  30. package/dist/init-quick-reference.md +116 -0
  31. package/dist/init-readme.md +35 -0
  32. package/dist/init.d.mts +7 -0
  33. package/dist/init.d.mts.map +1 -0
  34. package/dist/init.mjs +245 -0
  35. package/dist/init.mjs.map +1 -0
  36. package/dist/migration.d.mts +1 -0
  37. package/dist/migration.mjs +2 -0
  38. package/dist/module-base-B70DHaBE-k_c3Klu4.mjs +6 -0
  39. package/dist/module-base-B70DHaBE-k_c3Klu4.mjs.map +1 -0
  40. package/dist/mongo-static-CfvV1-qX-DdckMRxc.mjs +74 -0
  41. package/dist/mongo-static-CfvV1-qX-DdckMRxc.mjs.map +1 -0
  42. package/dist/{mongo-static-BdSGXYgQ-DSA-2DiK.d.mts → mongo-static-DabeBtmV-DILuhcbE.d.mts} +18 -5
  43. package/dist/mongo-static-DabeBtmV-DILuhcbE.d.mts.map +1 -0
  44. package/dist/runtime.d.mts +49 -44
  45. package/dist/runtime.d.mts.map +1 -1
  46. package/dist/runtime.mjs +104 -42
  47. package/dist/runtime.mjs.map +1 -1
  48. package/dist/static.d.mts +24 -2
  49. package/dist/static.d.mts.map +1 -0
  50. package/dist/static.mjs +2 -2
  51. package/dist/target__codec-ids.d.mts +1 -0
  52. package/dist/target__codec-ids.mjs +2 -0
  53. package/dist/target__codecs.d.mts +1 -0
  54. package/dist/target__codecs.mjs +2 -0
  55. package/dist/target__data-types.d.mts +1 -0
  56. package/dist/target__data-types.mjs +2 -0
  57. package/dist/target__server-version.d.mts +1 -0
  58. package/dist/target__server-version.mjs +2 -0
  59. package/dist/utils__guards.d.mts +1 -0
  60. package/dist/utils__guards.mjs +2 -0
  61. package/dist/utils__text.d.mts +1 -0
  62. package/dist/utils__text.mjs +2 -0
  63. package/dist/utils__upgrade-guides.d.mts +1 -0
  64. package/dist/utils__upgrade-guides.mjs +2 -0
  65. package/package.json +37 -13
  66. package/skills/prisma-8/SKILL.md +23 -18
  67. package/skills/prisma-8/references/build-a-target-package.md +117 -0
  68. package/skills/prisma-8/references/build.md +12 -16
  69. package/skills/prisma-8/references/contract.md +181 -75
  70. package/skills/prisma-8/references/debug.md +35 -24
  71. package/skills/prisma-8/references/feedback.md +8 -8
  72. package/skills/prisma-8/references/migration-model.md +23 -14
  73. package/skills/prisma-8/references/migration-review.md +23 -52
  74. package/skills/prisma-8/references/migrations.md +294 -80
  75. package/skills/prisma-8/references/queries-mongo.md +53 -17
  76. package/skills/prisma-8/references/queries-postgres.md +345 -34
  77. package/skills/prisma-8/references/queries.md +44 -25
  78. package/skills/prisma-8/references/quickstart.md +25 -22
  79. package/skills/prisma-8/references/runtime.md +172 -72
  80. package/skills/prisma-8/references/supabase.md +22 -19
  81. package/skills/prisma-8/references/upgrade-app.md +57 -22
  82. package/skills/prisma-8/references/upgrade-extension.md +72 -23
  83. package/skills/prisma-8/upgrading/app/upgrades/0.11-to-0.12/instructions.md +1 -1
  84. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
  85. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +639 -0
  86. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/multifile-psl/add-use-prisma-8-directive.mjs +60 -0
  87. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
  88. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +332 -0
  89. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
  90. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +489 -0
  91. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +1368 -0
  92. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
  93. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +108 -0
  94. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +755 -0
  95. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +973 -0
  96. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/scripts/sql-expression-literals-psl/rewrite-sql-strings.mjs +271 -0
  97. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +1862 -0
  98. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
  99. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
  100. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
  101. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
  102. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
  103. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +513 -0
  104. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
  105. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +803 -0
  106. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +586 -0
  107. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/scripts/value-objects-in-storage/value-objects-in-storage.ts +1184 -0
  108. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +480 -0
  109. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/scripts/mongo-index-names/mongo-index-names.ts +317 -0
  110. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +336 -0
  111. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
  112. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
  113. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1561 -0
  114. package/skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.9-to-8.0.0-rc.10/instructions.md +13 -0
  115. package/skills/prisma-8/upgrading/extension/upgrades/0.11-to-0.12/instructions.md +1 -1
  116. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.10-to-8.0.0-rc.11/instructions.md +34 -0
  117. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/instructions.md +857 -0
  118. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.11-to-8.0.0-rc.12/scripts/psl-verbatim-table-names/add-model-map.mjs +256 -0
  119. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/instructions.md +504 -0
  120. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.12-to-8.0.0-rc.13/scripts/execution-ref-entry-field/rename-execution-ref-keys.ts +193 -0
  121. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.13-to-8.0.0-rc.14/instructions.md +143 -0
  122. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/instructions.md +2168 -0
  123. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.14-to-8.0.0-rc.15/scripts/data-type-in-contract/data-type-in-contract.ts +1492 -0
  124. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.15-to-8.0.0-rc.16/instructions.md +223 -0
  125. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.16-to-8.0.0-rc.17/instructions.md +583 -0
  126. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.17-to-8.0.0-rc.18/instructions.md +1008 -0
  127. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/instructions.md +2186 -0
  128. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/client-takes-contract-value/contract-from-json.ts +597 -0
  129. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/data-type-values/data-type-values.ts +1120 -0
  130. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/default-generators-to-on-create/rewrite-default-generators.mjs +86 -0
  131. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/mongo-field-storage-names/mongo-field-storage-names.ts +304 -0
  132. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.18-to-8.0.0-rc.19/scripts/remove-nocheck/remove-nocheck.ts +2462 -0
  133. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/instructions.md +381 -0
  134. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.19-to-8.0.0-rc.20/scripts/expand-type-aliases/expand-type-aliases.ts +1206 -0
  135. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.20-to-8.0.0-rc.21/instructions.md +570 -0
  136. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md +464 -0
  137. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.22-to-8.0.0-rc.23/instructions.md +410 -0
  138. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/instructions.md +303 -0
  139. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-convenience-date-time-types/rewrite-mongo-date-types.ts +220 -0
  140. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.23-to-8.0.0-rc.24/scripts/mongo-type-helpers/rewrite-mongo-field-types.ts +621 -0
  141. package/skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.24-to-8.0.0-rc.25/instructions.md +1593 -0
  142. package/dist/adapter__codec-ids.d.mts +0 -1
  143. package/dist/adapter__codec-ids.mjs +0 -2
  144. package/dist/adapter__codec-types.d.mts +0 -1
  145. package/dist/adapter__codec-types.mjs +0 -2
  146. package/dist/adapter__codecs.d.mts +0 -1
  147. package/dist/adapter__codecs.mjs +0 -2
  148. package/dist/mongo-static-BdSGXYgQ-DSA-2DiK.d.mts.map +0 -1
  149. package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs +0 -38
  150. package/dist/mongo-static-_wy-fC4P-mXlhePy0.mjs.map +0 -1
@@ -10,7 +10,7 @@ Once the contract is emitted and the DB is up to date, this skill covers everyth
10
10
  - User wants to read, write, update, or delete data.
11
11
  - User wants to include / eager-load relations.
12
12
  - User wants to paginate, sort, filter, project.
13
- - User wants to wrap operations in a transaction (`db.transaction(...)` — Postgres and SQLite).
13
+ - User wants to wrap operations in a transaction (`db.transaction(...)` — Postgres, SQLite and Supabase role-bound clients).
14
14
  - User wants to aggregate (`count`, `sum`, `avg`, …).
15
15
  - User asks about query lanes (ORM vs SQL builder / query builder).
16
16
  - User mentions: *query, select, where, orderBy, limit, offset, take, skip, include, eager load, first, all, count, aggregate, create, update, delete, upsert, returning, drizzle-style, kysely-style, prisma client*.
@@ -28,9 +28,9 @@ Prisma 8 ships **two query lanes per target** on the same `db` value from `src/p
28
28
 
29
29
  | Runtime import in `db.ts` | Load |
30
30
  | --- | --- |
31
- | `@internal/postgres/runtime` | [`queries-postgres.md`](./queries-postgres.md) — `db.orm.<ns>.<Model>` + `db.sql.<ns>.<table>` |
32
- | `@internal/mongo/runtime` | [`queries-mongo.md`](./queries-mongo.md) — `db.orm.<root>` + `db.query.from(...)` |
33
- | `@internal/extension-supabase/runtime` | [`queries-postgres.md`](./queries-postgres.md) — a Supabase `RoleBoundDb` is a Postgres surface (`db.orm.<ns>.<Model>` + `db.sql.<ns>.<table>`); bind a role first via `references/supabase.md` |
31
+ | `@prisma/orm-postgres/runtime` | [`queries-postgres.md`](./queries-postgres.md) — `db.orm.<ns>.<Model>` + `db.sql.<ns>.<table>` |
32
+ | `@prisma/orm-mongo/runtime` | [`queries-mongo.md`](./queries-mongo.md) — `db.orm.<root>` + `db.query.from(...)` |
33
+ | `@prisma/orm-extension-supabase/runtime` | [`queries-postgres.md`](./queries-postgres.md) — a Supabase `RoleBoundDb` is a Postgres surface (`db.orm.<ns>.<Model>` + `db.sql.<ns>.<table>`); bind a role first via `references/supabase.md` |
34
34
 
35
35
  Both targets share the contract and connection on one `db` value. Reach for the ORM first; drop to the lower-level lane when the ORM can't express the shape. Lane choice is local — one query function picks one lane, not the whole app.
36
36
 
@@ -43,7 +43,7 @@ On Postgres, models and tables are **always** addressed by namespace coordinate
43
43
  - **ORM**: `db.orm.<namespace>.<Model>` — e.g. `db.orm.public.User`, `db.orm.auth.User`
44
44
  - **SQL builder**: `db.sql.<namespace>.<table>` — e.g. `db.sql.public.user`, `db.sql.auth.users`
45
45
 
46
- There is no flat `db.orm.User` / `db.sql.user` on the Postgres façade: `db.sql` is one facet per storage namespace and nothing else, and `db.orm` is keyed the same way (`examples/prisma-8-demo` uses `db.orm.public.User` and `db.sql.public.user` throughout). SQLite has no schemas, so its façade exposes the single unbound namespace directly — `db.orm.User` and `db.sql.user` are the SQLite spellings (`examples/prisma-8-demo-sqlite`). Mongo is keyed by collection storage name (`db.orm.users`).
46
+ There is no flat `db.orm.User` / `db.sql.user` on the Postgres package: `db.sql` is one facet per storage namespace and nothing else, and `db.orm` is keyed the same way (`examples/prisma-8-demo` uses `db.orm.public.User` and `db.sql.public.user` throughout). SQLite has no schemas, so its database package exposes the single unbound namespace directly — `db.orm.User` and `db.sql.user` are the SQLite spellings (`examples/prisma-8-demo-sqlite`). Mongo is keyed by collection storage name (`db.orm.users`).
47
47
 
48
48
  See [`queries-postgres.md` § Namespace-aware accessors](./queries-postgres.md#namespace-aware-accessors) for a worked example.
49
49
 
@@ -70,13 +70,13 @@ You do **not** need a `collect()` / `toArray()` helper — `await` is enough. In
70
70
  const rows: Promise<User[]> = db.orm.public.User.select('id', 'email').all().toArray();
71
71
 
72
72
  // Iterate — decode and handle rows one at a time. Whether the raw rows are
73
- // also fetched incrementally depends on the façade; see *Streaming* below.
73
+ // also fetched incrementally depends on the `cursor` option; see *Streaming* below.
74
74
  for await (const user of db.orm.public.User.select('id', 'email').all()) {
75
75
  process(user);
76
76
  }
77
77
  ```
78
78
 
79
- Two single-row shortcuts also exist on the result, in addition to the collection-level `.first()` (which issues `LIMIT 1` on Postgres):
79
+ Two single-row shortcuts also exist on the result, in addition to the collection-level `.first()` and `.firstOrThrow()` (which issue `LIMIT 1` on Postgres):
80
80
 
81
81
  ```typescript
82
82
  const user = await db.orm.public.User.where({ id }).all().first();
@@ -85,7 +85,7 @@ const required = await db.orm.public.User.where({ id }).all().firstOrThrow();
85
85
  // ^? Row ← buffers; throws `RUNTIME.NO_ROWS` if empty.
86
86
  ```
87
87
 
88
- For genuine single-row reads, prefer the *collection*-level `.first()` (which adds `LIMIT 1` to the SQL on Postgres) over `.all().first()` (which fetches all rows and discards the rest). The result-level helpers are for cases where you already need the full result and want the first row without an extra round-trip.
88
+ For genuine single-row reads, prefer the *collection*-level `.first()` or `.firstOrThrow()` (which add `LIMIT 1` to the SQL on Postgres) over `.all().first()` / `.all().firstOrThrow()` (which fetch all rows and discard the rest). Collection-level `.firstOrThrow()` runs the same query as `.first()`, returns the row without `null`, and rejects with `RUNTIME.NO_ROWS` when nothing matches: `await db.orm.public.User.firstOrThrow({ id })` on Postgres, `await db.orm.users.where({ email }).firstOrThrow()` on Mongo (no arguments there). The result-level helpers are for cases where you already need the full result and want the first row without an extra round-trip.
89
89
 
90
90
  **The result is single-consumption.** Each `AsyncIterableResult` instance can be consumed once — by `await`, by `.toArray()`, or by `for await`. Trying to consume it a second time throws **`RUNTIME.ITERATOR_CONSUMED`**. The fix is almost always to store the array in a variable on first consumption and reuse the variable:
91
91
 
@@ -105,7 +105,7 @@ If you've seen `collect(...)` / `toArray(...)` helpers in a codebase wrapping `.
105
105
 
106
106
  ## Running queries from a short script
107
107
 
108
- When the user is running a one-off `tsx my-script.ts` (not a long-lived server), call `await db.close()` at the end so the process exits cleanly — on Postgres the façade-owned pool keeps Node's event loop alive; on Mongo the façade-owned `MongoClient` does the same. See `references/runtime.md` § *Running as a script (teardown)* for the full pattern including `await using`.
108
+ When the user is running a one-off `tsx my-script.ts` (not a long-lived server), call `await db.close()` at the end so the process exits cleanly — on Postgres the pool the database package owns keeps Node's event loop alive; on Mongo the `MongoClient` it owns does the same. See `references/runtime.md` § *Running as a script (teardown)* for the full pattern including `await using`.
109
109
 
110
110
  ```typescript
111
111
  // src/scripts/seed.ts
@@ -125,23 +125,38 @@ console.log('Seeded.');
125
125
  await db.close();
126
126
  ```
127
127
 
128
+ ## Running a plan and printing its SQL (SQL targets)
129
+
130
+ A plan from `db.sql`, `db.raw` or the ORM (`.prepared.all().plan`) runs on the client: `db.query(plan)` returns its rows as an `AsyncIterableResult`, and `db.execute(plan)` resolves `{ affectedRows }` with no rows. Inside a transaction use `tx.query` / `tx.execute`; they have the same types. On Supabase, call them on a role-bound client (`db.asAnon()`, `await db.asUser(jwt)`). `db.query` on an ORM plan yields the database rows, not the result the ORM builds from them. To run a plan, use `db.query` and `db.execute`, not `db.runtime()`. `db.runtime()` remains for runtime-level work: `connection()`, `close()`, `telemetry()`, and as the target of a prepared statement (`ps.query(db.runtime(), params)`).
131
+
132
+ `db.toSql(plan)` returns `{ sql, params }` and needs no database, so a script can import `db.ts` with no `DATABASE_URL` set and print what a query would send. `params` are the plan's values before codecs encode them for the driver. Middleware rewrites (`beforeCompile`) are not applied. A plan with `prepare` bind sites throws `RUNTIME.PREPARE_BIND_ON_ADHOC`. `postgresStatic()` and `sqliteStatic()` have `toSql` too.
133
+
134
+ ```typescript
135
+ import { db } from '../src/prisma/db';
136
+
137
+ const plan = db.orm.public.Post.where({ published: true }).prepared.all().plan;
138
+ console.log(db.toSql(plan));
139
+ ```
140
+
128
141
  ## Streaming
129
142
 
130
- Every read terminal (`.all()`, and `runtime.query(plan)` for a SQL-builder plan) returns an `AsyncIterableResult`, so `for await` is always available. What it buys you depends on the façade:
143
+ Every read terminal (`.all()`, and `db.query(plan)` for a SQL-builder plan) returns an `AsyncIterableResult`, so `for await` is always available. What it buys you depends on the `cursor` option, which `postgres()` and `postgresServerless()` (`@prisma/orm-postgres/serverless`) both accept:
144
+
145
+ - **Default (cursors off), on a client and on a connection:** the full result set is fetched from the server before the first row is yielded; only *decoding* happens per row. `for await` therefore does not bound the memory held by the raw result. For very large sets, paginate (`.limit()` / `.offset()`, or `.orderBy(...).cursor(...)`) instead.
146
+ - **`cursor` set in the options of `postgres()` or `postgresServerless()` (`{ batchSize: 100 }`; `{}` or `{ batchSize: undefined }` for batches of 100; a `batchSize` that is not a positive integer fails the factory call; there is no flag that turns cursors off):** the driver reads through a server-side cursor in batches of that size, so `for await` over `db.orm...all()` or `db.query(plan)` really does stream, and an early `break` stops reading. In a Worker, put the option only on a second serverless client that the streaming paths open their connections from, and keep the serverless client every other path uses without it. On a connection with cursors on, finish or `break` the `for await` loop before sending another query through `db`: the cursor holds the connection's only database connection until the loop ends, so a query inside the loop waits forever. On a client, the same query takes another database connection from the pool. Behind Cloudflare Hyperdrive, reads with cursors on hang, so the streaming paths hang there and the other paths do not.
131
147
 
132
- - **Long-lived `postgres()` façade** (the usual `db.ts`): the driver runs with cursors disabled. The full result set is fetched from the server before the first row is yielded; only *decoding* happens per row. `for await` therefore does not bound the memory held by the raw result. For very large sets, paginate (`.limit()` / `.offset()`, or `.orderBy(...).cursor(...)`) instead.
133
- - **Serverless façade** (`@prisma/orm-postgres/serverless`, one `connect()` per invocation): the driver reads through a server-side cursor in batches of 100 rows by default (`cursor: { batchSize }` on the façade options), so `for await` really does stream.
148
+ There is no `.stream()` method on a client or on a connection.
134
149
 
135
- There is no `.stream()` method on either façade.
150
+ ## Prepared statements (Postgres, SQLite, MySQL, MariaDB, MongoDB)
136
151
 
137
- ## Prepared statements (Postgres, SQLite)
152
+ This section covers the SQL clients. MongoDB's `db.prepare` has the same shape, takes query-builder plans and ORM `.prepared` reads, and runs against `await db.runtime()`; see *Workflow — Prepared statements* in [`queries-mongo.md`](queries-mongo.md).
138
153
 
139
- `db.prepare(declaration, (sql, params) => plan)` builds a statement once and binds it per call. The declaration names each parameter's codec (`{ email: 'pg/text@1' }`); the callback receives the façade's `sql` builder plus typed `params` and returns a plan. A row-returning plan gives a `PreparedStatement` you run with `ps.query(runtime, params)`; a plan whose result is an affected count gives a `PreparedExecution` you run with `ps.execute(runtime, params)`. Declaring a parameter the plan never references throws `RUNTIME.PREPARE_UNUSED_PARAM`. `runtime.prepare(declaration, (params) => plan)` is the same thing on a `Runtime`.
154
+ `db.prepare(declaration, (params) => plan)` builds a statement once and binds it per call. The declaration names each parameter's codec (`{ email: 'pg/text@1' }`); the callback receives typed `params`, builds the plan with `db.sql` (or an ORM `.prepared` description), and returns it. A row-returning plan gives a `PreparedStatement` you run with `ps.query(target, params)`; a plan whose result is an affected count gives a `PreparedExecution` you run with `ps.execute(target, params)`. A prepared statement runs on what it is given: the runtime, a connection, a transaction's `tx`, or a Supabase role-bound client, which runs it under its role. `ps.query(tx, params)` runs inside the transaction. Preparing sends nothing to the database. Inside a transaction, `tx.prepare(...)` prepares without the outer client. Declaring a parameter the plan never references throws `RUNTIME.PREPARE_UNUSED_PARAM`. `runtime.prepare(declaration, (params) => plan)` is the same thing on a `Runtime`.
140
155
 
141
156
  ```typescript
142
157
  // examples/prisma-8-demo/src/queries/get-user-by-email-prepared.ts
143
- const ps = await db.prepare({ email: 'pg/text@1' }, (sql, params) =>
144
- sql.public.user
158
+ const ps = await db.prepare({ email: 'pg/text@1' }, (params) =>
159
+ db.sql.public.user
145
160
  .select('id', 'email', 'displayName', 'createdAt', 'kind')
146
161
  .where((f, fns) => fns.eq(f.email, params.email))
147
162
  .limit(1)
@@ -161,7 +176,7 @@ The model is the whole row plus its relations, and each related model carries it
161
176
  - `Models.<ns>_<Model>` (from `contract.d.ts`) — every scalar field and every relation. On SQLite, which has no schemas, the name is bare: `Models.User` and `typeof models.User`. On Postgres the schema is part of the name: `Models.public_User`, or `typeof models.public.User` by dotted access — a model declared outside any `namespace { }` block is in `public`, so that is also its name. Mongo names its models the same way. A polymorphic base also emits one member per variant and an `Any<Base>` union (`Models.public_AnyTask`).
162
177
  - `Scalars<M>` — the model without relations; what a default fetch returns. Distributes over unions, so `Scalars<Models.public_AnyTask>` is the union of variant rows.
163
178
  - `Shape<M, Spec>` — a data structure derived from the model, for declaring an endpoint's response type once and having the compiler check the body at the `return`. At every level of `Spec`: `'+'` is a union of scalar and relation names to keep (a relation named there comes with all of its scalars and none of its relations; the scalars are narrowed only when `'+'` names a scalar, so `'+': 'posts'` alone is every scalar plus posts); `'-'` is a union of scalar names to drop; `'+'` naming a scalar beside `'-'` is a compile error, while `{ '-': 'passwordHash'; '+': 'posts' }` is every scalar but the hash plus posts; any other key is a relation whose value is a nested spec that narrows the related model. Relations are absent unless asked for; `X[]`, `X | null`, or `X` comes from the model. Wrong names, a relation in `'-'`, a non-object relation value, and a relation both in `'+'` and as a key are compile errors. No `where`/`orderBy`/`limit`; compose extras with TypeScript (`Shape<M> & { postCount: number }`).
164
- - `ResultType<typeof query>` — the row of any ORM collection value (plain, `.include()`, `.select()`, `.variant()`), and of SQL lane plans. Bind the query to a name first; `typeof` needs a value.
179
+ - `ResultType<typeof query>` — the row of any ORM collection value (plain, `.include()`, `.select()`, `.variant()`), and of SQL lane plans. Bind the query to a name first; `typeof` needs a value. `.variant()` takes the variant's discriminator value, not its model name: `db.orm.public.Task.variant('bug')` for `@@base(Task, "bug")`. Call it once, on the base collection; a second `.variant()` on a variant collection is refused.
165
180
 
166
181
  ```ts
167
182
  import type { models, Models } from './prisma/contract';
@@ -193,10 +208,14 @@ async function getUserWithPosts(userId: Models.public_User['id']): Promise<UserR
193
208
  type Bad = Shape<Models.public_User, { nope: {} }>;
194
209
  ```
195
210
 
196
- On Mongo the imports are `@prisma/orm-mongo/family-contract/types` and `@prisma/orm-mongo/components/runtime`; embedded documents are fields, so they stay in `Scalars`. To name a model plus some of its relations, write `Shape<Models.public_User, { '+': 'id' | 'posts' }>`, not `Pick<Models.public_User, 'id' | 'posts'>`: `Pick` demands fully loaded nested posts that no query returns. Input types (`CreateInput<Contract, 'User'>`, `MutationUpdateInput<Contract, 'User'>`, `ShorthandWhereFilter<Contract, 'public', 'User'>`) come from `@prisma/orm-postgres/orm-client`.
211
+ On Mongo the imports are `@prisma/orm-mongo/family-contract` and `@prisma/orm-mongo/components/runtime`; embedded documents are fields, so they stay in `Scalars`. To name a model plus some of its relations, write `Shape<Models.public_User, { '+': 'id' | 'posts' }>`, not `Pick<Models.public_User, 'id' | 'posts'>`: `Pick` demands fully loaded nested posts that no query returns. Input types (`CreateInput<Contract, 'User'>`, `MutationUpdateInput<Contract, 'User'>`, `ShorthandWhereFilter<Contract, 'public', 'User'>`) come from `@prisma/orm-postgres/orm-client`.
197
212
 
198
213
  Coming from Prisma 7: `Prisma.User` → `Models.public_User` (note: now carries relations; the scalars-only row is `Scalars<Models.public_User>`); `Prisma.UserGetPayload<{ include: { posts: true } }>` → `Shape<Models.public_User, { '+': 'posts' }>`; `Prisma.UserGetPayload<{ select: { id: true; posts: { select: { title: true } } } }>` → `Shape<Models.public_User, { '+': 'id'; posts: { '+': 'title' } }>`; `Prisma.UserCreateInput` → `CreateInput<Contract, 'User'>`; `Awaited<ReturnType<typeof fn>>` → `ResultType<typeof query>`.
199
214
 
215
+ ## Ordering by a relation (SQL targets)
216
+
217
+ Inside an ORM `.orderBy(...)`: a to-one relation's field (`(p) => p.author.name.asc()`), a to-many relation's count (`(u) => u.posts.count().desc()`), a filtered count (`(u) => u.posts.count((p) => p.views.gt(10)).desc()`), and null placement on any `.asc()` / `.desc()` (`(u) => u.invitedBy.name.desc({ nulls: 'last' })`). One hop. `cursor()` rejects these orders with `ORM.ARGUMENT_INVALID`. Details in [`queries-postgres.md`](./queries-postgres.md). Mongo's `.orderBy({ field: 1 | -1 })` has neither.
218
+
200
219
  ## Common Pitfalls (cross-target)
201
220
 
202
221
  1. **Using Postgres examples on a Mongo project (or vice versa).** Check `db.ts` and load the correct target guide ([`queries-postgres.md`](./queries-postgres.md) or [`queries-mongo.md`](./queries-mongo.md)).
@@ -207,16 +226,16 @@ Target-specific pitfalls live in the per-target guides.
207
226
 
208
227
  ## What Prisma 8 doesn't do yet
209
228
 
210
- - **Many-to-many relations work through the junction.** `.include('tags', (tag) => tag.select(...))` traverses an N:M relation's `through` table, and nested `create` / `connect` / `disconnect` on an N:M relation write the junction rows for you (`examples/prisma-8-demo/src/orm-client/get-post-tags.ts`, `create-post-with-tags.ts`). The one refusal: a junction with required payload columns the relation API cannot populate throws `ORM.RELATION_MUTATION_UNSUPPORTED` — write that junction directly or use the SQL builder.
229
+ - **Many-to-many relations work through the junction.** `.include('tags', (tag) => tag.select(...))` traverses an N:M relation's `through` table, and nested `create` / `connect` / `disconnect` on an N:M relation write the junction rows for you (`examples/prisma-8-demo/src/orm-client/get-post-tags.ts`, `create-post-with-tags.ts`). The one refusal: a junction with required payload columns the relation API cannot populate throws `ORM.OPERATION_UNSUPPORTED` — write that junction directly or use the SQL builder.
211
230
  - **Ordering grouped aggregates by an aggregate alias (Postgres).** `db.orm.<ns>.<Model>.groupBy(...)` supports `.orderBy(...)` on group keys plus `.limit(...)` / `.offset(...)`, but the grouped collection cannot order by an aggregate alias such as `SUM(amount)`. A "top-N groups by SUM" query therefore falls back to JS-side sort + slice over the full grouped result, which is fine at small cardinalities and bad at scale. Workarounds: (a) drop to `db.sql.<ns>.<table>` and write the `GROUP BY` + `ORDER BY` + `LIMIT` against the aggregated table directly; (b) live with the JS-side sort/slice if the grouped cardinality is bounded. File a feature request via `references/feedback.md` if this is hitting you in production.
231
+ - **Set operations, window functions and `WITH` in the SQL builder.** `db.sql` has no `union` / `intersect` / `except`, no `OVER (...)` and no common table expressions. Write the whole query as raw SQL (next entry). If you want them in the builder, file a feature request via `references/feedback.md`.
212
232
  - **A raw-SQL lane.** This one exists. Write whole-query raw SQL through the client's raw lane: ``db.raw.sql`SELECT ...`.returnsRow({ ... }).build()`` for rows, or `.affectedCount()` for a mutation's row count. Each declared column names the codec that decodes it, so the row stays typed. For an expression fragment inside a builder query, use `fns.raw` in a `.select(...)` callback instead.
213
- - **TypedSQL (`.sql` files compiled into typed callables).** Not implemented. For a repeated query, use `db.prepare(...)` (see *Prepared statements* above) or a function that returns the built plan and `db.runtime().query(plan)` at the call site. If you want a `.sql`-file compile path, file a feature request via `references/feedback.md`.
233
+ - **TypedSQL (`.sql` files compiled into typed callables).** Not implemented. For a repeated query, use `db.prepare(...)` (see *Prepared statements* above) or a function that returns the built plan and `db.query(plan)` at the call site. If you want a `.sql`-file compile path, file a feature request via `references/feedback.md`.
214
234
  - **`EXPLAIN` / query-plan inspection.** Prisma 8 does not expose an `.explain()` method. Workaround: connect a `pg.Pool` you control via the runtime's `pg:` binding (see `references/runtime.md`) and issue `EXPLAIN ANALYZE` through it. If you want a first-class plan-inspection surface, file a feature request via `references/feedback.md`.
215
- - **Cursor-backed streaming on the long-lived façade.** `for await` works everywhere, but on `postgres()` the raw result is fetched in full before iteration (see *Streaming* above); only the serverless façade reads through a cursor. Paginate for very large sets on the long-lived façade. If you want cursor streaming there, file a feature request via `references/feedback.md`.
216
235
  - **Multi-statement batching (Prisma-7-style `db.$transaction([call1, call2])`).** Prisma 8 runs each call sequentially. Workaround: wrap atomically-related work in `db.transaction(async (tx) => { ... })` on Postgres. If you want batch-as-array semantics, file a feature request via `references/feedback.md`.
217
- - **Mongo façade transactions.** `@internal/mongo/runtime` does not expose `db.transaction(...)`. Multi-document atomicity is not yet wrapped in the Prisma 8 Mongo façade. Workaround: use the MongoDB driver's session API directly if you control the client binding (`mongoClient:` option). File a feature request via `references/feedback.md` if you need a first-class façade surface.
236
+ - **Mongo package transactions.** `@prisma/orm-mongo/runtime` does not expose `db.transaction(...)`. Multi-document atomicity is not yet wrapped in the Prisma 8 Mongo package. Workaround: use the MongoDB driver's session API directly if you control the client binding (`mongoClient:` option). File a feature request via `references/feedback.md` if you need a first-class surface in the database package.
218
237
  - **Mongo ORM aggregates.** No `.aggregate(...)` / `.groupBy(...)` on `db.orm.<root>`. Workaround: express aggregations through `db.query.from(...).group(...).build()` and `runtime.query(plan)`.
219
- - **Mongo filter helpers on the façade.** Rich filters (`.in`, ranges, boolean composition) currently import from `@prisma/orm-mongo/query-ast/execution` (`MongoFieldFilter`, etc.) — not re-exported on `@internal/mongo/runtime`. Workaround: use object equality `.where({ field: value })` where possible; import from the internal package only when necessary. Tracked alongside façade-completeness gaps in Linear `TML-2526`.
238
+ - **Mongo filter helpers on the database package.** Rich filters (`.in`, ranges, boolean composition) are filter expressions built with `MongoFieldFilter` and its siblings from `@prisma/orm-mongo/query-ast/execution`, not from `@prisma/orm-mongo/runtime`, and the ORM's `.where(...)` takes no callback. Use object equality `.where({ field: value })` where it is enough.
220
239
  - **Automatic N+1 detection.** Prisma 8 does not warn when an `.include(...)` is missing. Workaround: be deliberate about `.include(...)` in code review; the `lints` middleware (see `references/runtime.md`) catches the more common authoring slips (missing `WHERE` on a `DELETE` / `UPDATE`, missing `LIMIT` on a `SELECT`).
221
240
 
222
241
  ## Reference Files
@@ -232,6 +251,6 @@ This skill is split for selective loading. Target-specific reference paths live
232
251
  - [ ] On Postgres, used `db.orm.<ns>.<Model>` / `db.sql.<ns>.<table>` coordinates (usually `public`) — not a flat `db.orm.User`, which exists only on SQLite.
233
252
  - [ ] Chose the right lane (ORM by default; lower-level builder for shapes the ORM doesn't express).
234
253
  - [ ] Used `.first()` / `.first({ pk })` (Postgres) or `.where({ ... }).first()` (Mongo) for single-row reads — not `.all()`.
235
- - [ ] Consumed `.all()` with plain `await` (not a `collect()` / `toArray()` helper). Used `for await` only when per-row handling is actually wanted — and did not promise it bounds memory on the long-lived façade — and never iterated the same result twice.
254
+ - [ ] Consumed `.all()` with plain `await` (not a `collect()` / `toArray()` helper). Used `for await` only when per-row handling is actually wanted — and did not promise it bounds memory on the long-lived client — and never iterated the same result twice.
236
255
  - [ ] Did NOT use `db.sql` on a Mongo project or `db.query` where the Postgres SQL builder is meant.
237
256
  - [ ] Completed the target-specific checklist in the loaded guide.
@@ -13,28 +13,31 @@ This skill does **not** cover migrating from another ORM (Drizzle, Prisma 6/7, S
13
13
 
14
14
  ## When to Use
15
15
 
16
- - User asks *"what can I do with Prisma 8?"*, *"what can I do next with Prisma?"*, *"where do I start?"*, *"what should I do first?"* — and a PN project already exists on disk. **First-touch orientation** path below.
16
+ - User asks *"what can I do with Prisma 8?"*, *"what can I do next with Prisma?"*, *"where do I start?"*, *"what should I do first?"* — and a Prisma 8 project already exists on disk. **First-touch orientation** path below.
17
17
  - User just ran `createprisma` (or equivalent scaffold tool) and is asking what to do next. **First-touch orientation** path.
18
18
  - User is starting a new project and wants to use Prisma 8. **Greenfield** path.
19
- - User has an existing database (no PN contract) and wants to introduce PN. **Brownfield-DB** path.
20
- - User typed *"prisma orm init"*, *"get started with PN"*, *"set up PN"*, *"how do I scaffold a project"*. **Greenfield** path.
21
- - User says *"I have an existing Postgres/Mongo, how do I start using PN?"*. **Brownfield-DB** path.
19
+ - User has an existing database (no Prisma 8 contract) and wants to introduce Prisma 8. **Brownfield-DB** path.
20
+ - User typed *"prisma orm init"*, *"get started with Prisma 8"*, *"set up Prisma 8"*, *"how do I scaffold a project"*. **Greenfield** path.
21
+ - User says *"I have an existing Postgres/Mongo, how do I start using Prisma 8?"*. **Brownfield-DB** path.
22
22
 
23
23
  ## When Not to Use
24
24
 
25
- - User already has a PN project and wants to add a model → `references/contract.md`.
26
- - User wants to migrate FROM a specific ORM → install `@internal/migrate-from-<orm>-skill` (separate).
25
+ - User already has a Prisma 8 project and wants to add a model → `references/contract.md`.
26
+ - User wants to migrate FROM another ORM → Prisma 8 has no tool for that; see *What Prisma 8 doesn't do yet* below.
27
27
  - User wants to wire `db.ts` in a project that already has a contract → `references/runtime.md`.
28
28
  - User wants to integrate Prisma 8 with a build tool (Vite plugin, Next.js, …) → `references/build.md`.
29
29
 
30
30
  ## Key Concepts
31
31
 
32
32
  - **Contract**: the data model. Authored as `contract.prisma` (PSL, the canonical surface) or `contract.ts` (TypeScript builder). The framework reads it and emits two artefacts: `contract.json` (runtime IR) and `contract.d.ts` (types).
33
- - **Target**: the backing store. Today: `postgres` or `mongodb`. Picked at `init` time; baked into the `@internal/<target>` façade the scaffold imports from.
33
+ - **Target**: the backing store. Today: `postgres` or `mongodb`. Picked at `init` time; baked into the `@prisma/orm-<target>` package the scaffold imports from.
34
34
  - **Authoring mode**: how you write the contract. `psl` (Prisma Schema Language, default) or `typescript` (programmatic builder, optionally paired with the Vite plugin for auto-emit during `vite dev` — see `references/build.md`).
35
- - **Façade packages.** The scaffold installs exactly one façade per target — `@internal/postgres` (or `@internal/mongo`). User code imports from façade subpaths (`@internal/postgres/config`, `@internal/postgres/runtime`, `@internal/postgres/contract-builder`). The façade bakes in the family / target / adapter / driver wiring; never reach past it. See `references/contract.md` for the full list.
35
+ - **Database packages.** The scaffold installs one database package for your target: `@prisma/orm-postgres` or `@prisma/orm-mongo`. User code imports from its subpaths: `@prisma/orm-postgres/config`, `@prisma/orm-postgres/runtime`, `@prisma/orm-postgres/static` and `@prisma/orm-postgres/contract-builder`. The database package already contains the wiring of family, target, adapter and driver, so never import from the platform packages directly. See `references/contract.md` for the full list.
36
+ - **The packages beside it.** The scaffold also installs the platform packages that the database package requires as peer dependencies: `@prisma/orm-framework`, the family, the target and `@prisma/orm-toolchain`. They are from the same release as the database package: one `8.0.0-rc.N` until release 8.0, and from release 8.0 each package's own version in that release. `init` writes these lines for you, together with the other packages the database package requires, such as `temporal-polyfill`. If you install by hand, list every one of them.
37
+ - **Why the application lists them.** The application must have exactly one copy of each. Prisma does not accept a value that another copy of its own code created, and a package manager takes a peer dependency only from the application's own list. A monorepo whose applications are on different Prisma releases can still get two copies under npm workspaces and under Bun's hoisted linker; keep such applications on one release, or use pnpm, Yarn or Bun's isolated linker.
38
+ - **Yarn Plug'n'Play.** `prisma orm init` does not support it. With Yarn, set `nodeLinker: node-modules` in `.yarnrc.yml` first.
36
39
  - **`db.ts`**: the runtime entry point. Lives next to the contract source at `src/prisma/db.ts`. Imports the contract artefacts and exports a `db` value the rest of the app uses.
37
- - **Marker**: a row in the `prisma_contract.marker` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets PN detect drift between contract and live DB. Created by `db init` (greenfield / first-touch orientation) or `db sign` (brownfield).
40
+ - **Marker**: a row in the `prisma_contract.marker` table (Postgres) or a document in the `_prisma_migrations` collection (Mongo) that records the contract hash per contract space. Lets Prisma 8 detect drift between contract and live DB. Created by `db init` (greenfield / first-touch orientation) or `db sign` (brownfield).
38
41
 
39
42
  ### Canonical on-disk layout
40
43
 
@@ -96,9 +99,9 @@ If that prints `[{ id: 1, email: 'alice@example.com' }]`, the project is wired e
96
99
 
97
100
  `db.orm.<ns>.<Model>` is the default ORM lane — model-shaped, fully typed against the contract, lazily connects to the database on first use (it picks up `DATABASE_URL` from `.env` via the runtime's `dotenv/config`-loaded environment). The deeper `references/queries.md` reference covers the rest of the supported surface (filters, joins, transactions, the SQL builder, raw SQL via `db.raw.sql`, prepared statements) when the user is ready — and names the gaps (TypedSQL is not available).
98
101
 
99
- > **SQLite target:** `prisma orm init` scaffolds only `postgres` and `mongodb`; a SQLite project is wired by hand with the `@internal/sqlite` façade (`references/runtime.md` § *Switch between Postgres, SQLite, and Mongo*; `examples/prisma-8-demo-sqlite`). SQLite has no schemas, so that façade exposes the unbound namespace directly — write `db.orm.User` rather than `db.orm.public.User`.
102
+ > **SQLite target:** `prisma orm init` scaffolds only `postgres` and `mongodb`; a SQLite project is wired by hand with the `@prisma/orm-sqlite` package (`references/runtime.md` § *Switch between Postgres, SQLite, and Mongo*; `examples/prisma-8-demo-sqlite`). SQLite has no schemas, so that database package exposes the unbound namespace directly — write `db.orm.User` rather than `db.orm.public.User`.
100
103
  >
101
- > **Mongo target:** the snippet above is SQL-target shape. On `@internal/mongo`, `db.orm` is keyed by the collection's storage name (`@@map(...)`, or the lowercased model name if no `@@map`), so the same arc reads `await db.orm.users.create(...)` / `await db.orm.users.select('id', 'email').all()` — not `db.orm.public.User`. Full rule and rewrite recipe in `references/queries.md` § *MongoDB ORM addressing*.
104
+ > **Mongo target:** the snippet above is SQL-target shape. On `@prisma/orm-mongo`, `db.orm` is keyed by the collection's storage name (`@@map(...)`, or the lowercased model name if no `@@map`), so the same arc reads `await db.orm.users.create(...)` / `await db.orm.users.select('id', 'email').all()` — not `db.orm.public.User`. Full rule and rewrite recipe in `references/queries.md` § *MongoDB ORM addressing*.
102
105
 
103
106
  **Prerequisites for the arc to work.** All three paths leave these in place by the time you reach the arc:
104
107
 
@@ -112,7 +115,7 @@ The three workflows below each describe how their path gets the user to that sta
112
115
 
113
116
  ## Workflow — First-touch orientation
114
117
 
115
- Triggers: *"what can I do with Prisma 8?"*, *"what can I do next with Prisma?"*, *"where do I start?"*, *"I just ran createprisma"*, *"what's next?"*, or any close variant — paired with a PN project already on disk (scaffolded by `createprisma`, by `prisma orm init`, by a teammate, however).
118
+ Triggers: *"what can I do with Prisma 8?"*, *"what can I do next with Prisma?"*, *"where do I start?"*, *"I just ran createprisma"*, *"what's next?"*, or any close variant — paired with a Prisma 8 project already on disk (scaffolded by `createprisma`, by `prisma orm init`, by a teammate, however).
116
119
 
117
120
  The user's high-level intent is *"I want to be running an application against my database, against this thing called Prisma 8."* The job of this workflow is to anchor them on the contract, get one round-trip working, and let further commands surface organically as their next move requires them. **It is orientation, not a tour, not a feature inventory, not a syllabus.**
118
121
 
@@ -186,7 +189,7 @@ pnpm dlx prisma@latest orm init --yes --target postgres --authoring psl
186
189
 
187
190
  The flags `init` accepts (run `prisma orm init --help` for the source of truth):
188
191
 
189
- - `--target <db>` — `postgres` or `mongodb`.
192
+ - `--target <package>` — `postgres`, `mongodb`, or the name of another database package, such as `@prisma/orm-sqlite`.
190
193
  - `--authoring <style>` — `psl` or `typescript`.
191
194
  - `--schema-path <path>` — where to write the starter schema. Defaults to `src/prisma/contract.prisma` (or `src/prisma/contract.ts` with `--authoring typescript`), the canonical layout above. The extension must agree with `--authoring` (`CLI.INIT_AUTHORING_SCHEMA_PATH_MISMATCH` otherwise).
192
195
  - `--confirm <directory name>` — grant the reinit consent non-interactively. Re-running init in a scaffolded directory asks you to type the directory name back before it overwrites; non-interactive runs pass the name with this flag instead (`--yes` does not grant it).
@@ -194,7 +197,7 @@ The flags `init` accepts (run `prisma orm init --help` for the source of truth):
194
197
  - `--probe-db` — connect to `DATABASE_URL` once and check the server version against the target's minimum.
195
198
  - `--strict-probe` — fail init if the probe fails (errors without `--probe-db`).
196
199
  - `--skip-install` — skip dependency install + initial contract emit.
197
- - `--keep-previous-facade` — when re-running init to switch targets, keep the previous target package in `package.json`.
200
+ - `--keep-previous-facade` — when re-running init to switch targets, keep the previous database package in `package.json`.
198
201
 
199
202
  `init` does not install agent skills and has no `--skip-skills` flag: the `prisma-8` skill ships inside the `@prisma/orm-*` package the project installs, and the family-level `prisma init` / `prisma skills sync` commands copy it into the agent harness directories.
200
203
 
@@ -219,7 +222,7 @@ Then run the snippet from *Your first arc* above against the `User` model. When
219
222
 
220
223
  ## Workflow — Brownfield-DB (existing database, no contract)
221
224
 
222
- The concept: against an existing database with no PN contract, `contract infer` walks the live schema (tables, columns, indexes — including expression and partial ones — constraints, and RLS enablement + policies) and writes a PSL contract that describes it. Where authoring would generate a CHECK constraint the database does not carry (the element-non-null check on a list column), infer emits `@noCheck(elementNotNull)` on that field, so the contract declares exactly what the database enforces. The reverse gap is closed too: a hand-written CHECK constraint the database enforces that authoring would never have generated comes back as `@@check(expression: <reprint>, map: "<name>")`, so it is a declared object from the first pull instead of an invisible extra a later destructive plan could drop. That inferred check warns (`PN_EXACT_NAME_BODY_COMPARISON`) the next time you run `contract emit` — expected, not a defect: the warning fires on any `map:` body regardless of who wrote it, and the comparison stays sound because both sides are Postgres's own reprint. The result is a *starting point*, not the final contract — review and clean it up, then `db sign` to record the current contract hash as the marker (instead of letting `db init` try to recreate the schema from scratch). By default `db sign` also sets the `db` ref and stores the contract snapshot, so the next `migration plan` chains from the adopted schema — even when the database is named with `--db`. `--advance-ref <name>` writes another ref instead and `--no-advance-ref` writes none; in either case the next plan needs `--from` or a `db` ref you set yourself.
225
+ The concept: against an existing database with no Prisma 8 contract, `contract infer` walks the live schema (tables, columns, indexes — including expression and partial ones — constraints, and RLS enablement + policies) and writes a PSL contract that describes it. Where authoring would generate a CHECK constraint the database does not carry (the element-non-null check on a list column), infer writes the list with nullable elements (`String?[]`), which derives no such check, so the contract declares exactly what the database enforces. The reverse gap is closed too: a hand-written CHECK constraint the database enforces that authoring would never have generated comes back as `@@check(expression: <reprint>, map: "<name>")`, so it is a declared object from the first pull instead of an invisible extra a later destructive plan could drop. That inferred check warns (`PN_EXACT_NAME_BODY_COMPARISON`) the next time you run `contract emit` — expected, not a defect: the warning fires on any `map:` body regardless of who wrote it, and the comparison stays sound because both sides are Postgres's own reprint. Columns come back as the convenience types with their defaults, and only the arguments that differ: `int2` as `Int(storage: int2)`, `numeric(10,2)` as `Decimal(precision: 10, scale: 2)`, `varchar(12)` as `String(storage: varchar, length: 12)`, `json` as `Json`, `jsonb` as `Json(storage: jsonb)`, `timestamptz(3)` as `DateTime` (a JavaScript `Date`), a `timestamptz` with no declared precision as `DateTime(precision: 6)`, `timestamp(3)` as `DateTime(storage: timestamp)`, `date` as `Date`, `time` as `Time` and `interval` as `Duration` (ISO strings). A `Date` holds milliseconds, so a timestamp column whose values use microseconds reads with them dropped: change such a field to `DateTime(as: temporal)` or `DateTime(as: string)` to keep them. The result is a *starting point*, not the final contract — review and clean it up, then `db sign` to record the current contract hash as the marker (instead of letting `db init` try to recreate the schema from scratch). By default `db sign` also sets the `db` ref and stores the contract snapshot, so the next `migration plan` chains from the adopted schema — even when the database is named with `--db`. `--advance-ref <name>` writes another ref instead and `--no-advance-ref` writes none; in either case the next plan needs `--from` or a `db` ref you set yourself.
223
226
 
224
227
  ```bash
225
228
  mkdir my-app && cd my-app
@@ -238,9 +241,9 @@ pnpm prisma contract infer --db "$DATABASE_URL" --output src/prisma/contract.pri
238
241
 
239
242
  The agent should pause here and read the inferred PSL. Symptoms a re-author pass is needed:
240
243
 
241
- - Tables PN couldn't categorise (e.g. legacy linking tables you could express as relations).
242
- - Columns where PN's type guess is wrong (e.g. `String` where you want an extension type like `pgvector.Vector(length: 1536)`).
243
- - Missing `@unique` / `@index` hints PN couldn't see.
244
+ - Tables Prisma 8 couldn't categorise (e.g. legacy linking tables you could express as relations).
245
+ - Columns where Prisma 8's type guess is wrong (e.g. `String` where you want an extension type like `pgvector.Vector(length: 1536)`).
246
+ - Missing `@unique` / `@index` hints Prisma 8 couldn't see.
244
247
  - Field names you'd prefer to alias.
245
248
 
246
249
  Then re-emit and sign:
@@ -261,12 +264,12 @@ A reference table — not a script to recite at the user. Commands surface in th
261
264
  |---|---|---|
262
265
  | Apply the current contract to the DB the first time | `prisma db init` | this skill |
263
266
  | Re-emit `contract.json` + `contract.d.ts` after editing the contract source | `prisma contract emit` | `references/contract.md` |
264
- | Quick dev-only schema sync (no migration history kept) | `prisma db update` | `references/migrations.md` |
267
+ | Move a database whose history does not need to be kept to the contract (no migration written) | `prisma db update` | `references/migrations.md` |
265
268
  | Plan a migration from a contract diff | `prisma migration plan --name <slug>` | `references/migrations.md` |
266
269
  | Apply pending migrations | `prisma db migrate` | `references/migrations.md` |
267
270
  | Inspect the live database | `prisma db schema` | `references/debug.md` |
268
271
  | Confirm the DB matches the contract (drift check) | `prisma db verify` | `references/debug.md` |
269
- | Bring an existing DB into a PN contract | `prisma contract infer --db "$DATABASE_URL"` | this skill (brownfield) |
272
+ | Bring an existing DB into a Prisma 8 contract | `prisma contract infer --db "$DATABASE_URL"` | this skill (brownfield) |
270
273
  | Decode a structured error envelope | (read the `code` / `why` / `fix` fields) | `references/debug.md` |
271
274
  | Report a bug or request a feature | (file via the feedback skill) | `references/feedback.md` |
272
275
 
@@ -289,8 +292,8 @@ Switch authoring later by re-running `prisma orm init` in the same directory. Th
289
292
 
290
293
  ## What Prisma 8 doesn't do yet
291
294
 
292
- - **Migration from another ORM.** Prisma 8 doesn't migrate your schema *from* Drizzle / Prisma 6/7 / Sequelize / TypeORM / Kysely / Knex / a raw driver. Workaround: install the matching `@internal/migrate-from-<orm>-skill` if one exists for your source, or treat the source as a brownfield database and `contract infer` from it. If you need a guided migration flow built-in, file a feature request via the `references/feedback.md` skill.
293
- - **`prisma db push`-style production sync.** `db update` is the quick development path; for production, use migrations (`migration plan` + `db migrate`). PN deliberately does not offer a "push-to-prod-without-a-migration" surface — see `references/migrations.md`.
295
+ - **Migration from another ORM.** Prisma 8 doesn't migrate your schema *from* Drizzle / Sequelize / TypeORM / Kysely / Knex / a raw driver. A Prisma 6 MongoDB schema and a Prisma 7 Postgres schema are the exception: they can be the contract source as they are (`prisma6Schema` / `prisma7Schema`, see `references/contract.md`). For the others, treat the source as a brownfield database. On Postgres, `contract infer` writes a contract from it. Only the Postgres target implements inference: on SQLite, MySQL and MongoDB, `contract infer` fails with `CONTRACT.INFER_UNSUPPORTED`, so write the contract by hand. If you need a guided migration flow built-in, file a feature request via the `references/feedback.md` skill.
296
+ - **`prisma db push`-style production sync.** `db update` is for databases whose migration history does not need to be kept (local, development, staging, preview); for production, use migrations (`migration plan` + `db migrate`). Prisma 8 deliberately does not offer a "push-to-prod-without-a-migration" surface — see `references/migrations.md`.
294
297
  - **Studio / GUI database browser.** Use `prisma db schema` for a CLI tree-style summary of the live DB. If you need an interactive UI, file a feature request via the `references/feedback.md` skill.
295
298
 
296
299
  ## Reference Files