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.
Recent versions of persistent
support upsert
:
upsert :: (MonadIO m, PersistEntityBackend val ~ backend, PersistEntity val)
=> val -> [Update val] -> ReaderT backend m (Entity val)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With