dynamoid icon indicating copy to clipboard operation
dynamoid copied to clipboard

Support incrementing values and set operations in transactions

Open ckhsponge opened this issue 1 year ago • 3 comments

@andrykonchin Congrats on getting transactions released!

Here's an initial idea for supporting incrementing values and set operations in transactions that we decided wouldn't make the cut for v1 of transactions. https://github.com/Dynamoid/dynamoid/pull/846

Incrementing values is exceptionally useful in transactions. A record can be created and a counter incremented in a transaction to guarantee an accurate count. For accounting a debit and credit could be done in a transaction to ensure consistency.

I put this in an update() method which seems consistent with other code. If we want to go this direction I can put the specs back in for this as well.

We previously also had block support on upserts. This is useful because a counter can be incremented without checking it's been created first but perhaps supporting this now is not needed.

ckhsponge avatar Jan 13 '25 17:01 ckhsponge

Sorry, for some reason I thought 3.11 had already been released. I jumped the gun.

ckhsponge avatar Jan 14 '25 07:01 ckhsponge

Hello. Thank you!

Regarding incrementing values. Yes, it indeed makes sense to support these add/set/delete low-level operations in transactions. And using interface of the update method is a proper way to do so IMHO. Will leave comments in the PR #846.

Just for the record - there are methods increment/decrement in Dynamoid that work similarly to their Rails' counterparts and update integer attributes in atomic way. They also finally will be supported in transactions.

There are also several other ActiveRecord's methods similar to them (decrement_counter, increment_counter, reset_counters, update_counters) that I am planning to add as well.

andrykonchin avatar Jan 14 '25 20:01 andrykonchin

Sorry, for some reason I thought 3.11 had already been released. I jumped the gun.

The v3.11.0 version was indeed released a couple of days ago.

andrykonchin avatar Jan 14 '25 20:01 andrykonchin

The changes were made in #846. So close this issue as completed.

andrykonchin avatar Aug 21 '25 20:08 andrykonchin