haskell - 使用 Yesod 和 Persistent 的类型不匹配

标签 haskell yesod persistent

我正在尝试在 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/

相关文章:

javascript - 简单的 JavaScript 函数来持续改变按钮 onclick 的状态?

java - Apache HttpClient 4 每个代理而不是每个路由的持久连接

Kubernetes:自定义 Pod 调度和 Volume 调度

haskell - comonad 是否适合为 Wumpus 世界建模?

OCaml 格式库的 Haskell 等效项

haskell - 使用 SIGUSR1 重新加载 yesod 网站的内容

haskell - 结合持久化和 IO

haskell - 为什么 `let foo = (fmap . const)` 失败并显示 "No instance for (Functor f0) arising from a use of ` fmap'"?

haskell - 为什么 MC Haskell 函数会导致堆栈溢出

haskell - 将authRoute直接指向google auth