feat: MERGE and EXPLAIN can be run - #196
Merged
Merged
Conversation
`db.mergeInto(...)` was a public entry point producing a query nobody could run. The builder carried no executor, so there was no `.run()`, no `.many()`, and a compiled MERGE rejected — callers had to take the SQL and drive the connection themselves, which is the one thing the rest of the API does for them. `.explain()` was the same: a plan you could compile and not read, which is the only reason to ask for one. Both now carry the instance they were built from. MERGE gets `.run()`, and its RETURNING form gets `.many()` / `.first()` / `.run()`; EXPLAIN gets `.many()`, returning whatever the engine prints as `Record<string, unknown>[]` rather than a shape that would only be right for one dialect. Result plugins are deliberately not applied to a plan — it is not a row of your table. `every-builder-compiles.test.ts` grows a second check: no builder that emits SQL may be unable to run. Like the first, it reads `src/builder` rather than a list, because the hole appears when somebody adds a builder. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAwiBVhLmNhWjC9Ro6UMpb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two public entry points produced queries nobody could run.
db.mergeInto(...)built a query with no executor behind it — no.run(), no.many(), and a compiled MERGE rejected. Callers had to take the SQL and drive the connection themselves, which is the one thing the rest of the API does for them..explain()was the same: a plan you could compile and not read, which is the only reason to ask for one.What they get
MERGE gets
.run(), and its RETURNING form gets.many()/.first()/.run().EXPLAIN gets
.many(), returning what the engine prints asRecord<string, unknown>[]rather than a shape that would only be right for one dialect. Result plugins are deliberately not applied — a query plan is not a row of your table.Both are tested against pglite, including the compiled MERGE running and updating the row.
The check
every-builder-compiles.test.tsgrows a second assertion: no builder that emits SQL may be unable to run. Like the first, it readssrc/builderrather than a list, because the hole appears when somebody adds a builder, not when they add a test.Audited before and after:
pnpm testgreen: 3322 tests, lint clean, types clean.