fix(parse): check the write target when nothing else does - #346
Merged
Conversation
StrictQuery<DB, 'insert into ghosts (name) values ($1)'> // was Record<string, never>[]
StrictQuery<DB, 'delete from ghosts'> // same
StrictQuery<DB, 'update ghosts set name = $1'> // same
Table existence was only ever verified as a side effect of resolving some
column, in RETURNING or in WHERE. Add `returning id` and the expected
`unknown table: ghosts` appeared; write the statement the way people
normally write it and nothing looked the table up at all. The README's
limitations section says strict mode turns an unknown table into a
QueryTypeError, and a mistyped INSERT target is about the most common write
mistake there is.
The EmptyRow path - a write that projects nothing - now resolves its sources
against the schema in strict mode, reusing the same AllKnownTables and
FirstUnknownTable that StarRow reports with, so the message reads the same
way it does everywhere else. Loose mode is untouched.
Fixes #271
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/271-unknown-write-target
branch
from
August 2, 2026 13:04
32544e5 to
b029c98
Compare
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.
Fixes #271.
The bug
Add
returning idand the expectedQueryTypeError<'unknown table: ghosts'>appears. Add a WHERE to the DELETE and it also errors. So the hole sits exactly on the everyday INSERT — and a mistyped write target is about the most common write mistake there is. The README's limitations section says strict mode turns unknown tables into aQueryTypeError.The fix
Table existence was only ever verified as a side effect of resolving some column, in RETURNING or in WHERE/ON. The
EmptyRowpath inInferRowWithCheckednever resolvedSourcesagainst the schema at all.It now does, in strict mode, reusing the
AllKnownTables/FirstUnknownTablepairStarRowalready reports with — so the message is identical to the one every other path produces. Loose mode still returns the empty row.Verification
tests/unknown-write-target.test-d.ts, ten cases. Four red on master:StrictRowandStrictQueryControls: a real target with no RETURNING and no WHERE still projects nothing (all three write shapes, plus
update ... from orders), and loose mode is unchanged.tsc --noEmitclean, 192 runtime tests pass, budget 193,122 (+636).