Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upsert in persistent

How to do an atomic upsert in persistent?

Haven't managed to find a way to do an upsert, insert or update, operation using the persistent API. Something like update after insertBy seems to be the closest thing. But if I haven't understood something wrong, this won't be atomic and is thus prone to race conditions.

like image 232
rahcola Avatar asked Oct 02 '22 04:10

rahcola


1 Answers

Recent versions of persistent support upsert:

upsert :: (MonadIO m, PersistEntityBackend val ~ backend, PersistEntity val)     
       => val -> [Update val] -> ReaderT backend m (Entity val) 
like image 107
Cactus Avatar answered Oct 13 '22 10:10

Cactus