Skip to content

feat(prisma): add sqlcommenter-prisma package#13

Open
ChrisHarris2012 wants to merge 5 commits into
masterfrom
feat/sqlcommenter-prisma
Open

feat(prisma): add sqlcommenter-prisma package#13
ChrisHarris2012 wants to merge 5 commits into
masterfrom
feat/sqlcommenter-prisma

Conversation

@ChrisHarris2012

Copy link
Copy Markdown

Summary

  • Adds @query-doctor/sqlcommenter-prisma — SQLCommenter integration for Prisma ORM
  • Automatically appends query metadata (db_driver, route, method, file) as SQL comments to all Prisma queries via driver adapter wrapping
  • Supports Prisma 6+ SqlDriverAdapterFactory pattern (wrapAdapterFactory) and the legacy SqlDriverAdapter pattern (wrapAdapter)
  • Bridges AsyncLocalStorage context across Prisma's WASM engine boundary so request context and call-site info survive to the adapter layer
  • Includes unit tests for adapter wrapping, tag serialization, transactions, and path resolution

Key design decisions

  • In-place monkey-patching over Object.create() — Prisma's LibraryEngine tracks adapter errors by object identity; a new wrapper object breaks the error registry
  • WASM context bridge — Prisma's Rust/WASM query engine does not preserve Node.js AsyncLocalStorage context when calling back into JS. The extension snapshots ALS stores into module-level variables before the WASM call; the adapter reads them as a fallback
  • withRequestContext returns the inner promise — callers can properly await the result and errors propagate correctly

Test plan

  • npm test passes in packages/sqlcommenter-prisma
  • Verify with demo app: queries show db_driver, route, method, file annotations
  • Test wrapAdapterFactory with PrismaPg on Prisma 6.x
  • Test wrapAdapter with direct SqlDriverAdapter (Prisma 5.x compat)

🤖 Generated with Claude Code

ChrisHarris2012 and others added 2 commits June 16, 2026 18:08
SQLCommenter integration for Prisma ORM via driver adapter wrapping.
Automatically appends query metadata (db_driver, route, method, file)
as SQL comments to all Prisma queries.

Key design decisions:
- wrapAdapter patches the adapter in-place (not Object.create) to
  preserve Prisma's error registry object identity
- wrapAdapterFactory supports Prisma 6+ SqlDriverAdapterFactory
  pattern where PrismaPg.connect() returns the SqlDriverAdapter
- Bridges ALS context across Prisma's WASM engine boundary via
  module-level variables, since AsyncLocalStorage is lost when
  the Rust engine calls back into JS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prisma's PrismaPromise defers execution via .then(), so by the time
$allOperations fires, the user code is no longer on the call stack.
The first non-filtered frame was node:internal/process/task_queues,
producing a misleading file tag. Filter node:internal and
node:async_hooks frames so the file tag is omitted rather than wrong.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@veksen veksen force-pushed the feat/sqlcommenter-prisma branch from d603f01 to 84d2ad5 Compare June 16, 2026 22:10
veksen and others added 3 commits June 16, 2026 18:13
…88-4f7v-96qf)

Matches the floor already applied to the drizzle/typeorm/mikroorm packages.
The loose >=1.0.0 range let consumers resolve a vulnerable @opentelemetry/core
(<2.8.0, unbounded memory allocation in W3C Baggage propagation); the advisory
has no 1.x backport, so 2.8.0 is the floor. tracing.ts uses W3CTraceContextPropagator,
which is unchanged and compatible in 2.8.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Documents installation, the wrapAdapter/wrapAdapterFactory + sqlcommenterExtension
usage, and framework request-context middleware, mirroring the drizzle/typeorm/mikroorm
READMEs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Runs build + tests on changes to sqlcommenter-prisma, matching the existing
per-package nodejs test workflows.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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