You need to use runDB around your persistent call.
Type mismatch using Yesod and Persistent
-
12-07-2023 - |
Pergunta
I'm trying to make a Persistent query in a Yesod app:
userDetails :: UserId -> HandlerT app IO (Maybe UserDetail)
userDetails uid = do
profile <- getBy $ UniqueUser uid
return $ undefined -- the rest of this type checks
and I am getting a type error on the getBy line:
Couldn't match type `PersistMonadBackend (HandlerT App IO)'
with `persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend'
Expected type: PersistMonadBackend (HandlerT App IO)
Actual type: PersistEntityBackend Profile
So, checking the type in ghci:
:t getBy (UniqueUser undefined)
getBy (UniqueUser undefined)
:: ( PersistUnique m,
, PersistMonadBackend m ~ persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend
) => m (Data.Maybe.Maybe (Entity Profile))
But, the thing is, I defined Profile as:
Profile
name Text
email Text
user UserId
UniqueUser user
UniqueEmail email
in my 'config/model' file. What's going on and how do I fix it?
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow