You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(sql-orm): retire stale includeMany references; align include docs with correlated lowering
`includeMany` is no longer a method on any surface — the ORM exposes
`.include(...)` and the SQL builder has no include method. Clean up the
references this leaves behind, and align the adapter docs with the
correlated-only include lowering this branch introduces:
- Delete the obsolete `include-many-patterns.mdc` rulecard (it documented
a removed `SelectBuilderImpl.includeMany()` API) and its index entry.
- Remove the dead `HasIncludeManyCapabilities` type (zero usages; it
encoded the now-defunct lateral+jsonAgg include gate).
- Postgres README: includes now lower to a correlated subquery, not
`LEFT JOIN LATERAL`; note LATERAL emission is retained only for the
public `lateralJoin()` DSL.
- SQLite README: rename includeMany -> include; correlated is the
strategy, not a fallback.
- AGENTS.md (capability-gating example), the queries skill gotcha, and a
stale e2e describe label: includeMany -> include / a real capability.
- Remove the broken `### Queries with includeMany` SQL-builder example
from query-patterns.md (it called a nonexistent `.includeMany()`).
ADRs and the Query Lanes subsystem doc are left as-is (historical /
architecture docs handled separately).
Refs: TML-2729
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
Copy file name to clipboardExpand all lines: AGENTS.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,7 +92,7 @@ pnpm fixtures:check # Use this rather than ad-hoc emit-and-diff
92
92
-**ExecutionContext**: Encapsulates contract, codecs, operations, and types. Pass to `schema()`, `sql()`, `orm()`.
93
93
-**Interface + factory pattern for stateful services**: Stateful services (registries, runtimes, adapters, drivers) are exposed through an interface plus a `createX()` factory; the implementing class stays package-private. Consumers depend on the interface, never the implementation. Pattern reference: [`docs/architecture docs/patterns/interface-plus-factory.md`](docs/architecture%20docs/patterns/interface-plus-factory.md).
94
94
-**Three-layer polymorphic IR for AST/IR class hierarchies**: AST/IR nodes (Contract IR, Schema IR, migration ops) are organised as framework interface → family abstract base → target concrete classes. Concrete classes are publicly exported as the target's IR alphabet; `freezeNode(this)` is called in the constructor. Target packs contribute new entity kinds via `AuthoringContributions.entities` (see [`docs/reference/typescript-patterns.md`](docs/reference/typescript-patterns.md) § "AST/IR class hierarchies"). Pattern references: [`three-layer-polymorphic-ir.md`](docs/architecture%20docs/patterns/three-layer-polymorphic-ir.md), [`frozen-class-ast.md`](docs/architecture%20docs/patterns/frozen-class-ast.md), [`json-canonical-class-in-memory.md`](docs/architecture%20docs/patterns/json-canonical-class-in-memory.md).
95
-
-**Capability Gating**: Features like `includeMany` and `returning()` require capabilities in the contract; gating is enforced at authoring time.
95
+
-**Capability Gating**: Features like `returning()` require capabilities in the contract; gating is enforced at authoring time.
96
96
-**Builder chaining**: Methods return new instances — always chain calls.
97
97
-**Column access**: Use `table.columns.fieldName` to avoid conflicts with table properties.
@@ -205,31 +205,30 @@ The capabilities on the descriptor must match the capabilities in code. If they
205
205
206
206
See `docs/reference/capabilities.md` and `docs/architecture docs/subsystems/5. Adapters & Targets.md` for details.
207
207
208
-
## includeMany Support
208
+
## Include Support
209
209
210
-
The adapter supports `includeMany` for nested array includes using PostgreSQL's `LATERAL` joins and`json_agg`:
210
+
The adapter lowers `.include(...)` for nested array includes to a correlated subquery in the SELECT list, using`json_agg`:
211
211
212
212
**Lowering Strategy:**
213
-
- Renders `includeMany` as `LEFT JOIN LATERAL` with a subquery that uses `json_agg(json_build_object(...))` to aggregate child rows into a JSON array
214
-
- The ON condition from the include is moved into the WHERE clause of the lateral subquery
215
-
- When both `ORDER BY` and `LIMIT` are present, wraps the query in an inner SELECT that projects individual columns with aliases, then uses `json_agg(row_to_json(sub.*))` on the result
216
-
- Uses different aliases for the table (`{alias}_lateral`) and column (`{alias}`) to avoid ambiguity
213
+
- Renders each `.include(...)` as a correlated subquery that uses `json_agg(json_build_object(...))` to aggregate child rows into a JSON array
214
+
- The ON condition from the include becomes the WHERE clause of the correlated subquery, referencing the outer row
215
+
- When both `ORDER BY` and `LIMIT` are present, wraps the child query in an inner SELECT that projects individual columns with aliases, then uses `json_agg(row_to_json(sub.*))` on the result
217
216
218
217
**Capabilities Required:**
219
-
-`lateral: true` - Enables LATERAL join support
220
218
-`jsonAgg: true` - Enables `json_agg` function support
> LATERAL emission is retained in the renderer (and the `lateral` capability stays advertised) for the public SQL-builder `lateralJoin()` DSL; the ORM include path no longer uses it.
231
+
233
232
## DML Operations with RETURNING
234
233
235
234
The adapter supports RETURNING clauses for DML operations (INSERT, UPDATE, DELETE), allowing you to return affected rows:
Copy file name to clipboardExpand all lines: skills/prisma-next-queries/postgres.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -314,7 +314,7 @@ The callback's return value passes through `db.transaction(...)`. Capture insert
314
314
5.**Importing `and` / `or` / `not` from a Postgres façade subpath.** The combinators currently live in `@prisma-next/sql-orm-client` — an internal package. See *What Prisma Next doesn't do yet* in [`SKILL.md`](./SKILL.md).
315
315
6.**Trying to `db.sql.from(tables.user)`.** That surface does not exist. The builder is table-shaped: `db.sql.<tableName>.select(...)`. There is no `db.schema.tables` either.
316
316
7.**Trying to `db.execute(plan)` directly.** Plans execute through the runtime: `db.runtime().execute(plan)`. Inside a transaction, use `tx.execute(plan)`.
317
-
8.**Setting `capabilities: { includeMany: true }` in `prisma-next.config.ts`.**`defineConfig` does not take `capabilities`. Capabilities are declared by the active adapter and become part of the emitted contract; the Postgres adapter advertises `lateral`, `jsonAgg`, and `returning` out of the box. Enable extension capabilities through `extensions: [...]` in the config (see `prisma-next-contract`).
317
+
8.**Setting `capabilities: { lateral: true }` in `prisma-next.config.ts`.**`defineConfig` does not take `capabilities`. Capabilities are declared by the active adapter and become part of the emitted contract; the Postgres adapter advertises `lateral`, `jsonAgg`, and `returning` out of the box. Enable extension capabilities through `extensions: [...]` in the config (see `prisma-next-contract`).
318
318
9.**Confabulating a `db.sql.raw(...)`, TypedSQL, or `.stream()` surface.** None of those exist today. See *What Prisma Next doesn't do yet* in [`SKILL.md`](./SKILL.md).
319
319
10.**Mixing the ORM mutation return with `runtime.execute(plan)`.** ORM terminals issue the query themselves and return rows. `runtime.execute` is for SQL-builder plans.
320
320
11.**Top-N grouped queries written as `groupBy(...).aggregate(...).sort().slice()` in JS.** That's a fallback because the grouped collection doesn't expose `.orderBy(...)` / `.take(...)`. Fine at small cardinalities; for large grouped result sets, drop to `db.sql.<table>`.
0 commit comments