On Thursday, September 26, 2019 at 1:57:23 PM UTC-7, Alon wrote:
>
> What's the best way to implement an atomic insert/update in Rails? A  good 
> analogy for the problem I'm trying to solve is that I have two tables and 
> I'm  running API request and wrap the request with transaction using  
> Sequel::Model.db.transaction I want to write record to one of the table 
> regardless   if rollback_transaction is occurred
>

I'm sorry, but I don't understand actually what you want.  I'm going to try 
to guess, but I may be wrong.

In general when using the term atomic insert/update, if you were updating 
multiple tables in one transaction, you would want either all tables 
updated (on commit) or no tables updated (on rollback).  So it sounds like 
you don't want atomic insert/update, or you want separate atomic 
insert/update per table.

If you want one table updated and not the other table, then you probably 
want two separate transactions (or savepoints inside the same 
transaction).  I guess if you are wrapping entire API requests in 
transactions, when handling the inserts/updates to the two tables, use two 
separate savepoints (using Database#transaction with the :savepoint 
option).  That way if one fails, the other can still proceed.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/c2070bd7-aec7-4abd-886a-d8999e8a60fc%40googlegroups.com.

Reply via email to