Skip to content

feat: replace LockForUpdate with ClaimForUpdate, add Upsert#42

Open
klaidliadon wants to merge 2 commits intomasterfrom
feat/claim-for-update-and-upsert
Open

feat: replace LockForUpdate with ClaimForUpdate, add Upsert#42
klaidliadon wants to merge 2 commits intomasterfrom
feat/claim-for-update-and-upsert

Conversation

@klaidliadon
Copy link
Copy Markdown
Contributor

Summary

  • ClaimForUpdate / ClaimOneForUpdate replace LockForUpdate / LockForUpdates with a cleaner API: per-record mutateFn returns error (enabling rollback on failure), and the method returns claimed records after commit for processing outside the transaction.
  • Upsert adds INSERT ... ON CONFLICT support — DO NOTHING or DO UPDATE SET with column name validation against Map() output and batch chunking.

Breaking changes

  • LockForUpdate, LockForUpdates, lockForUpdatesWithTx removed — replaced by ClaimForUpdate and ClaimOneForUpdate.

Test plan

  • TestClaimForUpdate/concurrent_dequeue — 10 goroutines × 10 reviews, 100 unique claimed
  • TestClaimForUpdate/mutateFn_error_rolls_back — error on 3rd record, all still pending
  • TestClaimForUpdate/empty_result_returns_nil_slice
  • TestClaimForUpdate/ClaimOneForUpdate_no_match_returns_ErrNoRows
  • TestUpsert/insert_new_record
  • TestUpsert/DO_NOTHING_on_conflict
  • TestUpsert/DO_UPDATE_on_conflict
  • TestUpsert/concurrent_upserts_no_duplicates
  • TestUpsert/invalid_conflict_column and invalid_update_column
  • Full test suite passes (37 tests), go vet clean

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.
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