rahcola
rahcola

Reputation: 71

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.

Upvotes: 7

Views: 962

Answers (1)

Cactus
Cactus

Reputation: 27626

Recent versions of persistent support upsert:

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

Upvotes: 5

Related Questions