2

This morning I started setting up Esqueleto in a Yesod app. I'm really trying to do a LeftOuterJoin, but I've simplified the query down quite a bit in order to get the basics working. I can't even get that. To be sure there are no conflicts with Database.Persist.Query, I've followed some advice from a Github issue to extract my query into separate file that doesn't import Yesod. Is there something I'm missing in configuring Esqueleto?

FWIW, I'm using Yesod 1.4.0, Persistent 2.1 & Esqueleto 2.1.

This is the error I'm experiencing:

Queries.hs:9:15:
    No instance for (Database.Esqueleto.Internal.Sql.SqlSelect
                       (SqlExpr (Entity UrlEntry), SqlExpr (Entity UrlEntryData))
                       (Entity UrlEntry))
      arising from a use of ‘select’
    In the expression: select
    In the expression:
      select
      $ from
        $ \ (entry `InnerJoin` entryData)
            -> do { on
                    $ entry ^. UrlEntryId ==. entryData ^. UrlEntryDataUrlEntryId;
                    return (entry, entryData) }
    In an equation for ‘findEntries’:
        findEntries
          = select
            $ from
              $ \ (entry `InnerJoin` entryData)
                  -> do { on
                          $ entry ^. UrlEntryId ==. entryData ^. UrlEntryDataUrlEntryId;
                          .... }

Here are my models:

UrlEntry
    url String
    shortCode String
    ShortCode shortCode
    visits Int default=0
    userId UserId Eq
    deriving Eq Show
UrlEntryData
    screenshot String Maybe
    title String Maybe
    favicon String Maybe
    contentType String
    urlEntryId UrlEntryId Eq
    deriving Eq Show
User
    email Text
    password Text Maybe
    verkey Text Maybe
    verified Bool
    UniqueUser email
    deriving Eq Show Typeable

And here is my query:

findEntries :: SqlPersistT Handler [Entity UrlEntry]
findEntries = select $ from $ \(entry `InnerJoin` entryData) -> do
      on $ entry ^. UrlEntryId ==. entryData ^. UrlEntryDataUrlEntryId
      -- where_ (entry ?. UrlEntryUserId  ==. valkey authId)
      return (entry, entryData)
Joe Fiorini
  • 641
  • 5
  • 15
  • dunno if it will help, but I'm using esquelito in my toy learn-yesod project, here: https://github.com/bburdette/hackstarter/blob/master/Handler/Project.hs I think its using esquelito 1.4 or something (compiling on nixos so may be a little wierd with package versions). – Bzzt Oct 21 '14 at 16:09

1 Answers1

1

You need to change function signature.

findEntries :: SqlPersistT Handler [(Entity UrlEntry, Entity UrlEntryData)]
Daishi Nakajima
  • 1,932
  • 18
  • 26