Question

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?

Was it helpful?

Solution

You need to use runDB around your persistent call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top