How to update all fields of a row in Persistent

8 views
Skip to first unread message

kees Bleijenberg

unread,
Oct 12, 2021, 8:28:37 AM10/12/21
to Yesod Web Framework
A  client post a person and it's persistent key as json to the Yesod server. I decode the json to a Haskell Person and it's id. Now I want to update this Person in the database. Update in persist wants a list of fields and values. There is no (?) function to update the Person without calculating all the fields and values. Any idea's

Kees

Ideal Learning

unread,
Oct 13, 2021, 3:51:53 AM10/13/21
to Yesod Web Framework
Hi!

I do it this way in my put handler. (Notice that cid is not used for anything). Document type needs to be defined explicitly as in :: Handler Document.  Replace shall replace the record: 

putDocumentR :: CompanyId-> DocumentId -> Handler Value
putDocumentR cid id  = do
    document <- (requireJsonBody :: Handler Document)
    runDB $ replace id document
    sendResponseStatus status200 ("UPDATED" :: Text)


Regards

Juuso

Reply all
Reply to author
Forward
0 new messages