Skip to content

TML-3544: ORM queries search a weighted full-text index by naming it - #30676

Merged
wmadden merged 28 commits into
mainfrom
tml-3544-orm-queries-name-an-index
Oct 12, 2026
Merged

wmadden merged 28 commits into
mainfrom
tml-3544-orm-queries-name-an-index

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
model Post {
  id    Int     @id
  title String
  body  String?

  @@fullTextIndex([[title], body], name: "post_search")
}
const q = websearchToTsquery(input.search);

const posts = await db.Post
  .where((p, { fns, indexes }) => fns.fullTextMatches(indexes.post_search, q))
  .orderBy((p, { fns, indexes }) => fns.fullTextRank(indexes.post_search, q).desc())
  .limit(20)
  .all();

An ORM query can now search a weighted full-text index over several fields by naming the index. Until now the ORM could search one field at a time (p.title.fullTextMatches(q)), and a weighted search over the title and the body could only be written in the SQL query builder.

The decision

Every ORM callback that builds a condition or an order receives a second argument, { fns, indexes } (ADR 270):

  • fns is the SQL query builder's function surface for the contract: the built-in functions (eq, and, or, raw, …) and every operation the target and extensions register, such as Postgres's fullTextMatches and fullTextRank. ORM fields are accepted as arguments. A condition goes to where and composes with and, or and not; a value gets asc() and desc() for orderBy, and keeps its own methods.
  • indexes is the model's table's indexes, keyed by the name the schema gave each. Each is an index reference: the index's columns bound to the table as the query reads it, its type and its options. The Postgres search operations read the weights and language from it, so the query renders the same search document the index was built over, and Postgres uses the index.

The second argument reaches every site: where and orderBy (including arrays of order callbacks), the filters of first and firstOrThrow, this in a custom collection class, fragments for one model, include refinements and relation filters (some, every, none, count). Inside an include refinement or a relation filter, an index's columns are bound to the related table's alias. The body of a fragment for any model (db.orm.fragment(fields, body)) gets fns and an indexes with no members, because it does not know its model.

Existing callbacks that take one argument keep working, and no upgrade action is needed.

How it is built

  • Shared code. The function surface and the index reference move from sql-builder into @internal/sql-relational-core, under the new entry points ./functions and ./index-reference, so both query lanes build them the same way. sql-builder's public exports and behaviour are unchanged.
  • ORM client. A new callback-tools.ts builds the argument; ModelCallbackTools, OrmFunctions, ModelIndexReferences, Condition and related types are exported so applications can type a reusable condition. OrmOperation keeps up to four overloads of an operation; a fifth would be dropped, which the parity test and ADR 270 record.
  • Raw SQL. fns.raw needs a codec inferer for interpolated values. ExecutionContext gains an optional rawCodecInferer, which createExecutionContext takes from the execution stack's adapter, so every client built from a facade's context, including orm({ runtime, context: db.context, collections }), has it. A context built by hand without it gets a clear error naming the fix.
  • Conditions combine both ways. The package's and, or and not, and fns.and and fns.or, accept both ORM conditions (p.title.ilike(...)) and fns conditions.

Evidence

  • Integration test (test/integration/test/sql-orm-client/weighted-full-text-index-usage.test.ts, against Postgres): whole-shape results through a root collection, a fragment, a custom collection method, and a relation filter with an include in the same statement; a title match ranks above a body match; EXPLAIN with sequential scans disabled shows the index used, and a query that restates different weight groups does not use it.
  • Type tests at every site, including compile errors for a misspelled index, a non-full-text index, and language passed with an index. A parity test checks that every operation registered by Postgres, pgvector, ParadeDB and PostGIS has the same signature in the ORM as in the SQL query builder.
  • Clients with custom collection classes: fns.raw with an interpolated value works in a client built with orm({ runtime, context, collections }), tested in the package and through the demo's own client.
  • Run-time refusals through the ORM: a non-full-text index (RUNTIME.ARGUMENT_INVALID) and an index name two indexes share (ORM.ARGUMENT_INVALID).
  • Demo. Post gains an optional body and a weighted post_search index (migration 20261009T1354_add_post_body_search, made with migration plan and the regen script), and a new ORM search, src/orm-client/search-posts.ts, with a test that a title match comes first.
  • Type-checking cost (TypeScript 5.9.3, recorded in ADR 270 with the commits and command): the demo is 0.6% cheaper when unused, and ten uses add 0.17%.
  • Checks: build, root typecheck, typecheck, lint, tests and coverage of every touched package, demo typecheck, lint and tests (including declaration emit), fixtures:check, the lint suite, check:upgrade-coverage, and seven integration files run one at a time. The planner goldens were regenerated with PLANNER_GOLDEN_WRITE=1 for the new fixture indexes.
  • Reviewed with /drive-code-review (system design and code) and a verification pass; every finding is fixed.

Later decision

The ORM offering each search index as a scope on the model's collection, db.Post.scopes.search.fulltext(q).where(...), so the application writes no query. It builds on this change and is recorded in ADR 270 under "Later decision".

Alternatives considered

  • A helper exported by the Postgres package, fulltextSearchScopes(db.Post).post_search(q). It needs a generic builder in the ORM and one helper per package; naming the index in an ordinary query needs neither.
  • Methods on the index reference, indexes.post_search.matches(q). It needs packages to attach operations to index types, which belongs to collection scopes.
  • Restating the weight groups in the query. Any difference from the index silently turns the search into a sequential scan.
  • indexes and fns as members of the model accessor. They would collide with fields of the same names.

Linear: TML-3544. Design: #30428.

Agent: daedalus-71

Summary by CodeRabbit

  • New Features
    • ORM query callbacks now provide SQL functions and model index references for filtering, sorting, relation queries, and reusable fragments, including full-text matching and ranking.
    • Added a Prisma demo of weighted full-text search across post titles and bodies, ranked by relevance.
    • Relational query functions and index references are available through public package exports.
  • Documentation
    • Expanded guidance and examples for using named full-text indexes through the ORM and SQL builder.

Functions, BuiltinFunctions, BooleanCodecType, Subquery, createFunctions and ExpressionImpl move from @internal/sql-builder to @internal/sql-relational-core/functions. IndexReference, the table index reference type and the code that builds index references move to @internal/sql-relational-core/index-reference. The SQL builder imports them from there and its public exports are unchanged.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…indexes

Copied from the collection scopes design branch. Status stays Proposed until the slice lands.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The build regenerates the export maps of the public SQL packages for @internal/sql-relational-core/functions and /index-reference.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Every ORM callback that builds a condition or an order now receives a second argument { fns, indexes }: where and orderBy on a collection, the filter of first and firstOrThrow, include refinements, fragment bodies and relation filters. fns is the SQL query builder's function surface for the contract; a value it returns has asc() and desc(), and a condition it returns goes to where and to and, or and not. indexes holds the indexes of the model's table, bound to the table reference the query uses, so a relation filter or an include refinement on a self-relation searches the aliased table. The body of a fragment for any model gets fns and no index.

orm() takes the adapter's raw codec inferer for fns.raw, and the Postgres, SQLite and Supabase clients pass it. The ORM test fixture's users table gains a weighted full-text index, users_search, over name and email.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Only a condition from fns is an expression to unwrap. A field operation such as fullTextMatches returns an AST node of a kind the where-expression check does not list, and the callback result is now unwrapped only when it is an expression.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The test names documents_search in where and orderBy on the root collection, in a fragment, in a custom collection method, and in a relation filter and an include refinement on the documents self-relation, which read the table under an alias. It checks the rows, that a title match ranks above a body match, and that EXPLAIN uses the index with sequential scans disabled, with a negative control that restates the fields in one group. The fixture's Document model gains parentId and the parent and children relations.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…name-an-index

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

# Conflicts:
#	docs/architecture docs/ADR-INDEX.md
…n index

Post gains an optional body and a weighted full-text index, post_search, over the title (weight A) and the body (weight B), with a migration planned by migration plan. src/orm-client/search-posts.ts names the index in where and orderBy, the repositories test checks that a title match comes before a body match, and the declaration-emit fixtures cover the second callback argument in a fragment and a custom collection method.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Regenerated with PLANNER_GOLDEN_WRITE=1 after the demo's post gained a body and the post_search index.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The ORM client README describes the second callback argument. The Postgres query reference leads with naming the index, in the ORM first. ADR 236 says both query lanes hand a query the index.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The examples match the shipped API: a search method builds its tsquery from a string, and the second argument's type is ModelCallbackTools with OrmFunctions. A type test checks the ADR's fragment inside an include refinement.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The change is additive: one-parameter callbacks keep compiling, and orm() takes the raw codec inferer as an optional option.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…nd one type maps a storage column to a scope field

ExpressionImpl moves from @internal/sql-relational-core/functions to /expression, where the other expression types live. StorageColumnScopeField in /expression is the one mapping from a storage column to { codecId, nullable, many }; the SQL query builder's StorageTableToScopeTable and the shared index reference type both use it.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…del gets no indexes at run time

A value from fns is now the operation's own result with asc() and desc() added, so ParadeDB's proximity chain keeps within(). The result of fns.raw also has asc() and desc(). The ORM maps up to four overloads of an operation; a type test in the integration package checks that the ORM's fns keeps the SQL query builder's signature for every operation the Postgres target, pgvector, ParadeDB and PostGIS register, and records that a generic operation keeps its parameters at their constraints.

The body of a fragment for any model now receives an indexes with no members at run time, as its type says. One FunctionCondition and Condition type and one converter in filters.ts serve where, and, or, not and relation predicates. The raw codec inferer rides on the model accessor scope instead of a parameter on six functions. ModelCallbackTools, OrmFunctions, OrmFunctionsOf, ModelIndexReferences and the condition types are exported.

New tests cover a refused non-full-text index and a refused shared index name through the ORM, the base table's indexes on a collection narrowed by variant, a reusable condition typed with ModelCallbackTools, and the whole SQL of the include-refinement alias. The ORM fixture's users table gains an index that shares its name with a foreign key's backing index.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… comment describes each search command

The declaration-emit fixtures write a condition whose second parameter is ModelCallbackTools from @prisma/orm-postgres/orm-client. test/callback-tools-uses.types.test-d.ts holds ten uses of the second argument, one per site; ADR 270's cost figures use it.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Moved to test/integration/test/sql-orm-client; it still uses the SQL query builder's fixture and setup.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
ADR 270's cost figures for the client package use it.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… the limit for generic operations

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
An assertion over the ten collections cost more to check than the uses themselves, which would inflate the measured cost of the feature.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The paragraph names the two commits, the command, the TypeScript version, the probe files and the source state of each run.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…erloads in one step

The value proxy returns the result's own properties as they are and binds only inherited methods, so a frozen operation result no longer throws when buildAst is read. OrmOperation matches four signatures once and keeps a single signature as one; the parity test covers one to four overloads and records that an operation with five keeps only its last four, as ADR 270 now says. The fragment body's list of chain methods is typed from DeclaredFieldsFragmentCollection, and the relational-core README says ExpressionImpl comes from the expression entry.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner October 9, 2026 15:22
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: prisma/orm/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6ad06d57-7232-48ef-8da5-62187f7d75bd

📥 Commits

Reviewing files that changed from the base of the PR and between efc1e7e and b3a3cb8.


⛔ Files ignored due to path filters (6)
  • packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.json is excluded by !**/generated/**
  • test/integration/test/sql-builder/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • test/integration/test/sql-builder/fixtures/generated/contract.json is excluded by !**/generated/**
  • test/integration/test/sql-orm-client/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • test/integration/test/sql-orm-client/fixtures/generated/contract.json is excluded by !**/generated/**

📒 Files selected for processing (2)
  • test/integration/test/planner-golden/manifest.json
  • test/integration/test/psl-print/every-postgres-contract-roundtrip.integration.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

ORM callbacks now receive SQL functions and model index references. Shared relational-core implementations support callback functions and index lookup. The Prisma 8 demo adds weighted full-text search over post titles and bodies.

Changes

ORM Callback Tools and Named Indexes

Layer / File(s) Summary
Shared SQL functions and index references
packages/2-sql/4-lanes/relational-core/*, packages/2-sql/4-lanes/sql-builder/*
Relational core adds shared SQL function and index-reference implementations. SQL builder uses these shared implementations.
ORM callback tools and API coverage
packages/3-extensions/sql-orm-client/*, packages/2-sql/5-runtime/src/sql-context.ts, packages/9-public/@prisma/*/package.json
ORM where, orderBy, relation, and fragment callbacks receive query functions and model index references. Raw SQL callback values use the execution context’s codec inferer when available.
Weighted full-text search demo and integration coverage
examples/prisma-8-demo/*, test/integration/test/sql-orm-client/*, test/integration/test/sql-builder/*, test/integration/test/planner-golden/manifest.json, test/integration/test/psl-print/*, skills/prisma-8/references/queries-postgres.md, docs/architecture docs/*, upgrade-instructions/pending/*
The demo adds an optional Post.body field and a weighted title-and-body index, with a migration, generated contracts, search function, CLI command, and tests. Integration tests cover weighted index use, callback typing, and related fixtures. Documentation describes the callback API and named-index query paths.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CollectionBase
  participant ORMCallback
  participant IndexReferences
  participant SQLBuilder
  CollectionBase->>ORMCallback: Pass model accessor and callback tools
  ORMCallback->>IndexReferences: Read named index reference
  IndexReferences-->>ORMCallback: Return index columns bound to query table
  ORMCallback->>SQLBuilder: Return filter or ordering expression
Loading

Suggested reviewers: aqrln


Merge Risk | ⚪ Minimal · up to b3a3c

Merge Risk: ⚪ Minimal · up to b3a3c

No actionable regression is established in the reviewed changes. The planner hash comparison remains unverified, but there is no evidence that the recorded values are wrong.

Security Architecture Review

Security architecture risk: 🔵 Low · up to b3a3c

The new query tools broaden what application-authored ORM queries can express. Inspected controls preserve parameter handling and bind named indexes to the appropriate model and query alias. No introduced security bypass was established, but deployment privileges and applications that construct query code dynamically remain outside the reviewed scope.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed capability applies to applications using ORM callbacks, not just the demo. Authored raw expressions can describe SQL beyond the callback model, so potential data exposure depends on application code and the database connection's privileges; model index binding is not a database authorization sandbox.

Trust Boundaries and Controls

  • observed — Raw SQL separates template fragments from scalar values: supported scalar interpolations become codec-tagged parameters, while template fragments remain SQL. Missing codec inference is explicitly refused for bare values. This protects value interpolation, not dynamically authored SQL fragments.
  • observed — Named-index references come from the model's contract table, and each referenced column builds its AST through the current table binding. Related-query tests cover alias binding, while edge-case tests cover rejection of duplicate names and unsuitable index types.

Resilience and Maintainability Implications

  • observed — The migration runner explicitly separates transaction-owned execute from unwrapped executeOnConnection. Both existed before this PR in the checked comparison. Normal execution surrounds schema operations and completion records with transaction control; direct consumers of the unwrapped method must supply that lifecycle.

Hardening Proposals

  • proposed — Document that ORM raw SQL fragments and callback code are application-authority inputs, not suitable for direct construction from untrusted request text. Distinguish safe scalar interpolation from dynamic SQL construction and recommend least-privilege database roles for consumers.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 26.19% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 60 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: enabling ORM queries to search a weighted full-text index by name.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Docstring Coverage

Explanation

Docstring coverage is 26.19% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 60 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30676

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30676

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30676

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30676

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30676

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30676

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30676

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30676

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30676

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30676

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30676

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30676

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30676

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30676

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30676

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30676

commit: b3a3cb8

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 241.84 KB (+0.41% 🔺)
postgres / emit 213.41 KB (+0.45% 🔺)
mongo / no-emit 199.35 KB (0%)
mongo / emit 177.2 KB (0%)
cf-worker / no-emit 301.68 KB (+0.41% 🔺)
cf-worker / emit 270.06 KB (+0.47% 🔺)

…demo's Post has two

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… values in fns.raw

The execution context now carries the adapter's raw codec inferer: createExecutionContext sets it from the execution stack, and ExecutionContext declares it as optional, so hand-built contexts keep compiling and fall back to a refusal. The ORM reads it from the context, so the client the README and the demo build, with db.context, has it. The orm() option and the facades' arguments for it are gone; the option was never released.

fns.and and fns.or in the ORM also take ORM conditions such as p.title.ilike(...). The README says how conditions combine in both directions, and that a registered collection class's methods are not typed inside an include refinement, where a fragment applied with with does the job.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden enabled auto-merge October 9, 2026 15:50
…al-core

createFunctions moved to @internal/sql-relational-core, but its tests stayed in sql-builder and reached it through the built package, so relational-core's coverage counted none of them. The createFunctions cases move to relational-core/test/functions.test.ts with local column expressions; sql-builder keeps the aggregate cases. New cases cover ne with a null left operand, a boolean literal in and, an unknown function name, and an expression index's empty columns.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@wmadden-electric
wmadden-electric added this pull request to the merge queue Oct 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 12, 2026
… without a foreign key in the SQL builder fixture

The fixture declares its relations without foreign keys on purpose. Its new self-relation Document.parent sorts before Post.author, so contract print refuses it first.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden added this pull request to the merge queue Oct 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 12, 2026
@wmadden
wmadden enabled auto-merge October 12, 2026 12:36
@wmadden
wmadden added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit df2e55c Oct 12, 2026
24 checks passed
@wmadden
wmadden deleted the tml-3544-orm-queries-name-an-index branch October 12, 2026 13:11
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-prisma__orm that referenced this pull request Oct 16, 2026
… the project files removed (prisma#30739)

```ts
// examples/prisma-8-demo/src/orm-client/get-filtered-posts.ts
db.Post
  .with((posts) => (input.userId !== undefined ? posts.where({ userId: input.userId }) : posts))
  .with((posts) => (input.before !== undefined ? posts.where(createdBefore(input.before)) : posts))
```

This closes the collection scopes project. The demo gains its last two
examples: a list query whose filters apply only when the request gives
them, written with `with`, and `createdBefore`, a row fragment for any
model with a `createdAt` timestamp, typed with `CodecField`. The
project's spike notes leave main, and its retro lessons land in
`drive/retro/README.md`.

## What changes

- **Demo:** `ormClientGetFilteredPosts` and the command `repo-list-posts
[userId|-] [before|-] [limit]`; `createdBefore` in
`src/orm-client/fragments.ts`; an integration test covering each
combination of inputs, the exclusive `before` bound and the limit; type
tests that `createdBefore` is accepted on `User` and `Post` and refused
on `Tag`; README text.
- **ADR 259:** two sentences that pointed at the project's records now
state the limitation directly, and `CodecField` is described as checking
values against the codec's input type, which is what the code does (the
ORM client README had the same error).
- **Removed:** `projects/collection-scopes/` (three spike notes).
Nothing else on main linked to it.
- **Retro:** the final retro entry in `drive/retro/README.md`.

## Project Definition of Done

| Item | Status | Evidence |
| --- | --- | --- |
| ADRs 259, 265, 270 Accepted and matching what shipped | Met | All
Accepted on main; ADR 272 also Accepted |
| Chaining keeps a custom class (TML-3403) | Met | Done; type tests in
the ORM client |
| A ternary cannot unlock `deleteAll` (TML-3397) | Met | Done; test in
the ORM client |
| Lock methods keep the class; `fragment` refuses a narrowed receiver
(TML-3543) | Met | prisma#30673, Done |
| Demo chains custom methods, sorts by a request field, searches by
naming the index | Met | On main |
| Demo has a conditional list query written with `with` and a shared
filter typed with `CodecField` | Met | This PR |
| An ORM query that names a weighted full-text index works at every
site, title above body, `EXPLAIN` uses the index | Met |
prisma#30676 integration tests |
| Built packages type chaining, fragments and the callback tools | Met |
`examples/prisma-8-demo/test/declaration-emit.test.ts`, through the
published facade |
| A model with a full-text index offers `using.<index name>(q)` with no
application code, at every site, `EXPLAIN` uses the index | Met |
prisma#30717 |
| A second, test-only contribution adds its own method with no ORM
client change | Met, changed form | Under ADR 272 contributions read the
whole model, so the proof is two test-only contributions, one from a
field's type and one with a name of its own, instead of a test-only
index type |
| No type arguments in the application; demo type-checking cost within
ADR 272 | Met | +1.17% unused, recorded in ADR 272 |

## Deferred work

Every open item on the project's deferred list is a Linear ticket:
TML-3587, TML-3588, TML-3589, TML-3590, TML-3591, TML-3592, TML-3593,
TML-3594, and the existing TML-3449.

## Project files

Everything the project wrote was coordination material: specs, plans,
reviews, handover and spikes. The lasting decisions are in ADRs 259,
265, 270 and 272 and in `docs/architecture
docs/patterns/declaration-merging-registries.md`, all already on main.
The project's working files were never merged; they stay on the branch
`model-scopes-design` until this PR merges, then the branch is deleted.

## Checks

Demo typecheck, lint and tests; root typecheck; `lint:docs`;
`lint:deps`; `fixtures:check`; build. Reviewed with `/drive-code-review`
(system design and code); every finding is fixed.

Agent: daedalus-71


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* The Prisma 8 demo adds a command to list posts, optionally filtered by
author and creation time.
* Results are ordered from newest to oldest, with a default limit of 10.
The command also supports limiting the number of results.

* **Documentation**
  * Added usage examples for the filtered-post command.
* Clarified that fragment comparisons use a codec’s input type and
distinguished fragments used to filter rows from those used to extend
query context.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants