2014-03-29 12 views
1

Yesod 1.2中的runDB如何與Esqueleto一起使用?Haskell:Yesod和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設置不同於耶索德腳手架是怎麼做的。 https://github.com/yesodweb/yesod/wiki/Multi-select-field-populated-from-database-(using-esqueleto)

回答

2

這是一個依賴性問題。必須使用最新版本的persistent和persistent-sqlite編譯Esqueleto。