【问题标题】:Type mismatch using Yesod and Persistent使用 Yesod 和 Persistent 类型不匹配
【发布时间】:2014-04-30 02:57:25
【问题描述】:

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

在我的“配置/模型”文件中。发生了什么,我该如何解决?

【问题讨论】:

    标签: haskell yesod persistent


    【解决方案1】:

    您需要在持久调用周围使用 runDB。

    【讨论】:

    • 啊,谢谢。我一定把 getBy404 的类似 Handler 的语义与 getBy 混淆了。
    猜你喜欢
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    相关资源
    最近更新 更多