Repository navigation
Add update() and deleteFrom() for Postgres and ClickHouse - #15
Merged
Merged
Conversation
update(table).set(...).where(...) and deleteFrom(table).where(...), with returning on Postgres and settings on ClickHouse. They share the insert's value encoding, SET record, RETURNING and settings, now factored into valueCells, setAssignments, returningOf and writeSettingsClause. A write with no where() is a defect unless allRows() says so; a where() whose conditions all came out undefined fails, since that comes from data and would widen a filtered write to every row. ClickHouse compiles UPDATE to an ALTER TABLE ... UPDATE mutation and DELETE to a lightweight DELETE, both with WHERE 1 for allRows() and settings last; checked on 26.2 and 26.8. Tenant scope is derived from the WHERE, and an update that moves rows to another tenant is cross-tenant. CompiledQuery.kind gains update and delete, and Database.run sends any write without RETURNING through command. DialectClauses.insertSettings (unreleased) becomes writeSettings; alterTableUpdate is new. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
A subquery in an UPDATE or DELETE's SET or WHERE, or in an insert's VALUES or onConflictDoUpdate, was compiled for its SQL and its scope dropped, so a pinned write that read every tenant through a subquery reported single-tenant, and a write into an untenanted table reported untenanted. Writes now record each subquery's scope (a string subquery is cross-tenant) and combine it with their own, as queries do. A where() condition that renders to nothing no longer leaves a dangling WHERE, and does not count as a filter: a write left with none fails unless allRows() says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The largest Maple blocker from
design/gap-review.md: UPDATE (~120 sites) and DELETE (~79). Stacked on #14.What changes
update(table)returnsCHUpdateStart(setonly); aftersetcomewhere/allRows,returning, andsettings.deleteFrom(table)haswhere/allRows,returning, andsettings.onConflictDoUpdatealso uses. Inserts compile byte-for-byte as before.where()is a defect unlessallRows()is called. Awhere()whose conditions all came outundefined(every optional filter absent) is a typed failure, not a silent full-table write.updatecompiles to anALTER TABLE ... UPDATEmutation, the only form every supported server takes;deleteFromcompiles to a lightweightDELETE.allRows()writesWHERE 1, and settings go last, such asmutations_sync.mutations_sync.returningis refused on ClickHouse, andsettingson Postgres.CompiledQuery.kindgainsupdateanddelete, andDatabase.runsends any write without RETURNING throughcommand.DialectClauses.insertSettings(unreleased) is renamedwriteSettings;alterTableUpdateis new.Not built
UPDATE ... FROM / joins, DELETE USING, and a VALUES source for bulk updates. These are tracked in the gap review.
Testing
bun run typecheckandbun run test: 521 unit tests and the doc checks pass.src/ch/update.test.ts(SQL on both dialects,allRows, tenant scope, every refusal) and type tests.allRows.mutations_syncand a lightweight delete.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.