如何让 Yesod 1.2 中的 runDB 与 Esqueleto 一起工作?
import Database.Esqueleto as E
getMainR :: Handler Html
getMainR = do
leases <- runDB $ E.select $
E.from $ \l -> do
E.where_ (l E.^. LeaseId E.==. E.val 1)
return l
defaultLayout $ do
setTitle "Main"
这是错误输出:
Handler/Main.hs:41:27:
Couldn't match type `persistent-1.3.0.6:Database.Persist.Sql.Types.SqlPersistT'
with `SqlPersistT'
Expected type: YesodDB App [E.Entity val0]
Actual type: SqlPersistT (HandlerT App IO) [E.Entity val0]
In the second argument of `($)', namely
`select
$ from
$ \ l
-> do { where_ (l ^. LeaseId ==. val 1);
return l }'
In a stmt of a 'do' block:
leases <- runDB
$ select
$ from
$ \ l
-> do { where_ (l ^. LeaseId ==. val 1);
return l }
In the expression:
do { leases <- runDB $ select $ from $ \ l -> do { ... };
defaultLayout $ do { setTitle "Tenants" } }
Handler/Main.hs:42:41:
Couldn't match expected type `E.EntityField val0 typ0'
with actual type `Import.EntityField
Lease
(Import.KeyBackend
persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend
Lease)'
In the second argument of `(^.)', namely `LeaseId'
In the first argument of `(==.)', namely `l ^. LeaseId'
In the first argument of `where_', namely
`(l ^. LeaseId ==. val 1)'
我试图按照本教程进行操作,但似乎他们的 runDB 设置与 Yesod 脚手架的设置方式不同。https://github.com/yesodweb/yesod/wiki/Multi-select-field-populated-from-database-(using-esqueleto)