Daniel Buckmaster
Daniel Buckmaster

Reputation: 7186

Getting the updated record after a Persistent update

At the moment, if I try to do this inside a handler:

newPerson <- runDB $ update personId [PersonAge =. 27]

newPerson will have the type (). It seems that update doesn't yield any value, so if I want to get the updated entity, I need to do this:

newPerson <- runDB $ do
    update personId [PersonAge =. 27]
    get personId

Which results in newPerson having type Maybe Person, and some additional code to handle the Nothing case (or using fromJust). Is there a way to bypass the issue? Should there be? To me it makes sense for update to return the updated record, but should it really?

Upvotes: 0

Views: 560

Answers (1)

Nikita Volkov
Nikita Volkov

Reputation: 43310

update returns (), use updateGet.

Upvotes: 2

Related Questions