Repository navigation
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 23 minutes. View limit details
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 |
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.
A sync upsert usually copies the new row over the old one. Today each column must be written twice in
onConflictDoUpdate'ssetcallback (name: excluded.name, rent: excluded.rent, ...).Closes #81.
Part of #52.
Changes
excluded(columns): asetvalue that writesSET col = EXCLUDED.colfor each named column.excludedAll(except?): asetvalue that copies every column the insert writes (the rows' keys, or the SELECT's aliases), except the named columns and the conflict target's columns. A column the rows leave out keeps its old value, because itsEXCLUDEDvalue is the default.QueryBuilderErrorInvalidArguments; anexcludedAllthat leaves no column fails with "sets no columns", as an emptysetdoes.col = excluded.colon the tenant column now keeps the rows' tenant scope. Before, it made the insertcross-tenant, soexcludedAllon a tenant table would fail underrequireTenantScope. This also holds for the callback form (($, excluded) => ({ org: excluded.org })).proposedRowAccessorinsrc/ch/compile.ts), the same one the callback gets.docs/inserts.md("Set from the proposed row"),docs/reference.md,design/writes.md§6,design/gap-review.md(P1 item marked built). Oneminorchangeset.How SQLite and MySQL plug in later
excluded."col"text and the sameON CONFLICT (target)clause. The helpers work as they are once the dialect setsclauses.onConflict: true.proposedRowAccessor, to writeVALUES(col)(ornew.colwith a row alias on 8.0.19+), and rendersON DUPLICATE KEY UPDATE. It refuses an explicittarget, because MySQL uses all unique keys. ThenexcludedAllcannot skip the target's columns fromtarget, so it would skip the primary key instead. The helpers' public shape does not change.Left out
excludedAllplusupdatedAt: now()). The callback form does this today; the docs show it. A later option can add it if you want it.Dialectfor the proposed-row SQL. It has no second user yet, so I kept it a private function.Validation
bun run build: pass.bun run typecheck: pass (includes the newinsert.test-d.tscases).bunx vitest run --testTimeout=60000 --hookTimeout=60000with live ClickHouse 26.8.2.7: 60 files passed, 1039 tests passed, 0 skipped. New tests: 5 compile tests insrc/ch/insert.test.ts, 1 PGlite run test insrc/database/database.test.ts.node scripts/check-doc-citations.mjs,node scripts/check-exports-documented.mjs,node scripts/check-doc-examples.mjs: pass.bun scripts/check-package.ts: pass.Need help on this PR? Tag
@codesmith-botwith what you need.