我正在尝试在 Yesod 应用程序中进行持久查询:
userDetails :: UserId -> HandlerT app IO (Maybe UserDetail)
userDetails uid = do
profile <- getBy $ UniqueUser uid
return $ undefined -- the rest of this type checks
我在 getBy 行收到类型错误:
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
因此,检查 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))
但是,问题是,我将 Profile 定义为:
Profile
name Text
email Text
user UserId
UniqueUser user
UniqueEmail email
在我的“配置/模型”文件中。发生了什么事以及如何解决它?
最佳答案
您需要在持久调用周围使用 runDB。
关于haskell - 使用 Yesod 和 Persistent 的类型不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23378895/