Reputation: 482
I am trying to understand what the correct typeclass constraint to use for a function that wants to put code into a db with persistent in Yesod. To make things concrete, I have a function like:
addToDbReturnJson obj = do
runDB $ insert obj
returnJson obj
and I am trying to figure out what its type signature should be. I am pretty sure it should be something like
addToDBReturnJson :: (ToJSON val, SomethingPersist val) => val -> Handler Value
What should the SomethingPersist
be? I am happy to be pointed at documentation that explains the types in Persistent, but I have not been able to figure it out from the Yesod book.
Upvotes: 1
Views: 80
Reputation: 12070
This works for me-
addToDbReturnJson::(ToJSON val, PersistEntity val,
(PersistEntityBackend val ~ PersistMonadBackend (YesodDB App)))=>val->Handler Value
Not very intuitive, but it looks to me like the in the last part you have to specify that the database that the input value connects to is the same database that the handler uses (.... OK, that makes sense I guess).
Upvotes: 1