feat: replace LockForUpdate with ClaimForUpdate, add Upsert#42
Open
klaidliadon wants to merge 2 commits intomasterfrom
Open
feat: replace LockForUpdate with ClaimForUpdate, add Upsert#42klaidliadon wants to merge 2 commits intomasterfrom
klaidliadon wants to merge 2 commits intomasterfrom
Conversation
ClaimForUpdate/ClaimOneForUpdate replace LockForUpdate/LockForUpdates with a cleaner API: per-record mutateFn that returns error (enabling rollback), and returns claimed records after commit for processing outside the transaction. Upsert adds INSERT ... ON CONFLICT support with DO NOTHING or DO UPDATE SET, column name validation, and batch chunking.
- ClaimForUpdate: fix docstring to accurately describe the existing-tx path — records are returned within the tx scope, caller must commit. - Upsert: auto-include updated_at in DO UPDATE SET when the record implements HasSetUpdatedAt, consistent with Save/Update behavior. - Add test assertion for updated_at bump on conflict.
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.
Summary
LockForUpdate/LockForUpdateswith a cleaner API: per-recordmutateFnreturnserror(enabling rollback on failure), and the method returns claimed records after commit for processing outside the transaction.INSERT ... ON CONFLICTsupport —DO NOTHINGorDO UPDATE SETwith column name validation againstMap()output and batch chunking.Breaking changes
LockForUpdate,LockForUpdates,lockForUpdatesWithTxremoved — replaced byClaimForUpdateandClaimOneForUpdate.Test plan
TestClaimForUpdate/concurrent_dequeue— 10 goroutines × 10 reviews, 100 unique claimedTestClaimForUpdate/mutateFn_error_rolls_back— error on 3rd record, all still pendingTestClaimForUpdate/empty_result_returns_nil_sliceTestClaimForUpdate/ClaimOneForUpdate_no_match_returns_ErrNoRowsTestUpsert/insert_new_recordTestUpsert/DO_NOTHING_on_conflictTestUpsert/DO_UPDATE_on_conflictTestUpsert/concurrent_upserts_no_duplicatesTestUpsert/invalid_conflict_columnandinvalid_update_columngo vetclean