Upsert in persistent

957 Views Asked by At

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.

1

There are 1 best solutions below

0
On

Recent versions of persistent support upsert:

upsert :: (MonadIO m, PersistEntityBackend val ~ backend, PersistEntity val)     
       => val -> [Update val] -> ReaderT backend m (Entity val)