Skip to content

Add update() and deleteFrom() for Postgres and ClickHouse - #15

Merged
Makisuo merged 2 commits into
fix/insert-reviewfrom
feat/update-delete
Oct 4, 2026
Merged

Makisuo merged 2 commits into
fix/insert-reviewfrom
feat/update-delete

Conversation

@Makisuo

@Makisuo Makisuo commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

The largest Maple blocker from design/gap-review.md: UPDATE (~120 sites) and DELETE (~79). Stacked on #14.

CH.update(Tickets)
	.set(($) => ({ seats: $.seats.add(1) }))
	.where(($) => [$.org.eq(CH.param.string("org")), $.seats.lt(5)])
	.returning("id", "seats")

CH.deleteFrom(Tickets).where(($) => [$.id.eq(CH.param.int("id"))])

What changes

  • Builders. update(table) returns CHUpdateStart (set only); after set come where / allRows, returning, and settings. deleteFrom(table) has where / allRows, returning, and settings.
  • Shared with inserts. Value encoding, the SET record, RETURNING and settings are shared, now factored into helpers that onConflictDoUpdate also uses. Inserts compile byte-for-byte as before.
  • Safety. No where() is a defect unless allRows() is called. A where() whose conditions all came out undefined (every optional filter absent) is a typed failure, not a silent full-table write.
  • ClickHouse.
    • update compiles to an ALTER TABLE ... UPDATE mutation, the only form every supported server takes; deleteFrom compiles to a lightweight DELETE.
    • allRows() writes WHERE 1, and settings go last, such as mutations_sync.
    • The docs explain that a mutation is asynchronous without mutations_sync.
    • returning is refused on ClickHouse, and settings on Postgres.
  • Tenant scope is derived from the WHERE as for a query. An update that moves rows to another tenant is cross-tenant.
  • Running. CompiledQuery.kind gains update and delete, and Database.run sends any write without RETURNING through command.
  • Rename. DialectClauses.insertSettings (unreleased) is renamed writeSettings; alterTableUpdate is 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 typecheck and bun run test: 521 unit tests and the doc checks pass.
  • New src/ch/update.test.ts (SQL on both dialects, allRows, tenant scope, every refusal) and type tests.
  • PGlite: update with an expression and an array value, returning, a no-RETURNING update, delete returning, and allRows.
  • Live ClickHouse suite (250 tests) on 26.2.19.43 and 26.8.2.7, including a mutation with mutations_sync and a lightweight delete.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

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>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2b13850e-81b2-4a4f-a35f-c7892d52100e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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>
@Makisuo
Makisuo merged commit 4a5eb05 into fix/insert-review Oct 4, 2026
3 checks passed
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.

1 participant