Skip to content

POC: recursively scope relational with configs#1

Draft
benvinegar wants to merge 1 commit into
mainfrom
poc/relational-with-scoping
Draft

POC: recursively scope relational with configs#1
benvinegar wants to merge 1 commit into
mainfrom
poc/relational-with-scoping

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Summary

This is a proof of concept for making Drizzle relational with safer.

It adds:

  • relationalWithMode: "root-only" | "scope" | "forbid"
  • relations maps on scoped table rules / scopeByColumn options
  • recursive scoping for mapped relational with entries in "scope" mode
  • fail-closed behavior for unmapped relations in "scope" mode
  • fail-closed behavior for any with config in "forbid" mode
  • tests documenting root-only default, recursive scope mode, existing nested where preservation, unmapped failures, and forbid mode

Important POC caveats

This proves the wrapper can rewrite nested relation configs, but I would not merge this as-is before validating against real Drizzle relational queries for each relation shape. In particular:

  • Drizzle may not support where on every nested relation shape, especially one-to-one relations.
  • The API shape may want a more explicit relation map separate from table rules.
  • Strict-mode semantics for nested relations need a product decision: this POC injects nested scope predicates without requiring callers to repeat them.
  • We should add real Drizzle integration tests, not only the fake query harness.

Validation

  • pnpm format:check
  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm coverage — 100% statements/branches/functions/lines
  • pnpm build

This PR description was generated by Pi using OpenAI GPT-5

@benvinegar benvinegar force-pushed the poc/relational-with-scoping branch from 22e7285 to 874d3cf Compare June 23, 2026 23:18
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.

1 participant