Вопрос

How do you get runDB in Yesod 1.2 to work with 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"

Here is the error output:

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)'

I was trying to follow along this tutorial but it seems they have runDB set up differently than how the Yesod scaffolding does it. https://github.com/yesodweb/yesod/wiki/Multi-select-field-populated-from-database-(using-esqueleto)

Это было полезно?

Решение

It was a dependency issue. Esqueleto had to be compiled with the latest version of persistent and persistent-sqlite.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top