【发布时间】:2014-05-02 22:01:53
【问题描述】:
在 ghci 中加载脚手架站点后获得 runDB 返回的正确实例是什么?例如,在运行这句话时:
runDB $ selectList [UserName ==. "Renny"] []
错误是:
Couldn't match type `PersistMonadBackend
(YesodPersistBackend site0 (HandlerT site0 IO))'
with `persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend'
The type variable `site0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Expected type: PersistMonadBackend
(YesodPersistBackend site0 (HandlerT site0 IO))
Actual type: PersistEntityBackend User
In the second argument of `($)', namely
`selectList [UserName ==. "Renny"] []'
In the expression: runDB $ selectList [UserName ==. "Renny"] []
In an equation for `it':
it = runDB $ selectList [UserName ==. "Renny"] []
提前致谢
编辑:
我忘记了 Yesod Scaffold 的 runDB 返回一个处理程序,这导致我采用了这种解决方法(尽管我确信这是一个更好的解决方案):
xs <- runSqlite "MyProject.sqlite3" (selectList [UserName ==. "Renny"] [])
"MyProject.sqlite3" 是 Sqlite 数据库的名称。
这不是一个通用的解决方案。根据文档,正如 post 所说,其他后端略有不同。
【问题讨论】:
-
如果用
:set -XNoMonomorphismRestriction关闭monomorphism restriction 会发生什么? -
这是个好问题。我什至没有想过使用 GHCi 作为持久化的前端。
-
@nomen 感谢您的回复。我想我找到了一个解决方案(请参阅问题的最后编辑版本)。再见
标签: haskell yesod persistent ghci