Repository navigation
fix(query-builder): keep every where condition in deletes and updates - #56
Merged
Merged
Conversation
delete(), update() and updateFrom() rebuilt their where clause through the Prisma-like schema shape, which only represents comparisons, groups and negations. Raw, JSON, relation, exists, column-comparison, date/time, full-text and expression conditions were silently dropped, widening the write to every row the remaining constraints matched. Writes now build from the same structured condition reads use. update() only takes the primary-key path when the whole condition is a primary-key equality, and combining an unconvertible object where with structured constraints throws instead of losing one of them.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Problem
delete(),update()andupdateFrom()built their where clause throughbuildWhere(), which converts the structured condition back to the Prisma-like schema shape viatoQuerySchemaWhere. That shape only represents comparisons, groups and negations; every other condition type converts toundefinedand is filtered out of its group.So raw, JSON, relation (
whereHas), exists, column-comparison, date/time, full-text and expression conditions were silently dropped from writes, and the write hit every row the remaining constraints matched:Reads were unaffected because they compile from the structured condition directly.
Two query-building paths could also lose constraints (affecting reads too): combining an object
wherethat cannot be converted to a structured condition with raw/JSON/expression constraints dropped one side, depending on order.Fix
delete(),update()andupdateFrom()build frombuildQueryWhereCondition(), the same condition reads use, through a newbuildWriteCondition(). The "requires a where clause" and "could not be compiled" errors are unchanged.update()takes the direct primary-key path only when the whole condition is a primary-key equality. Previouslywhere({ id }).whereRaw(...)looked unique and the raw clause was ignored.appendQueryConditionflushes a legacy where into the structured condition before appending, and throwsUnsupportedAdapterFeatureExceptionwhen it cannot be converted.addLogicalWherethrows instead of converting constraints the schema shape cannot represent.isUniqueWhereis replaced byuniqueWhereFor(condition).Behaviour change
A query that silently lost a condition now either applies it or throws. Writes that were too broad now affect fewer rows.
Tests
New PostgreSQL tests in
tests/postgres/kysely-adapter.spec.tscoverdelete,updateFrom,update(first match and primary key) with raw clauses, and the combination guard. All fail onmainand pass here.pnpm test: 413 passed, 2 skippedpnpm test:postgres: 159 passedtsc --noEmitandpnpm lintclean