Haskell Esqueleto 3表联接

Haskell Esqueleto 3表联接,haskell,join,esqueleto,haskell-persistent,Haskell,Join,Esqueleto,Haskell Persistent,以下是我尝试从三个表中进行选择的步骤。但是它们没有编译,我也不理解错误(我不知道为什么它需要一个元组(Entity Issue,b0),而不是我认为代码试图获取的三元组) 尝试1: {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE MultiP

以下是我尝试从三个表中进行选择的步骤。但是它们没有编译,我也不理解错误(我不知道为什么它需要一个元组
(Entity Issue,b0)
,而不是我认为代码试图获取的三元组)

尝试1:

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}

module Handler.Support where

import           Import hiding ((==.))
import qualified Database.Esqueleto as E
import           Database.Esqueleto      ((^.), (==.), (&&.))
import           Data.Traversable

getSupportR :: CustomerId -> Handler Html
getSupportR customerId = do
  customer_issues_followUps_list <- runDB $
    E.select $
    E.from $ \(i, f, c) -> do
    E.where_ (i ^. IssueCustomerId ==. E.val customerId &&. i ^. IssueId ==. f ^. FollowUpIssueId &&. i ^. IssueCustomerId ==. c ^. CustomerId)
    return (i, f, c)
  let issues = map listToMaybe . group . sort . fst . unzip $ customer_issues_followUps_list
  defaultLayout $ do
    setTitle "Your Licenses"
    $(widgetFile "support-display")
正如您可能看到的,两次尝试中的错误是相同的:它期望一个元组而不是三元组


任何帮助都将不胜感激:)

罪犯在
let
声明中:

let issues = map listToMaybe . group . sort . fst . unzip $ customer_issues_followUps_list
fst
unzip
使用元组,因此编译器暗示
customer\u issues\u followup\u list
是元组

要解决此问题,只需在package.yml依赖项(或cabal文件)中添加“-extra”,并在
let
语句中将
fst
unzip
替换为
fst3
unzip3
,如下所示:

let issues = map listToMaybe . group . sort . fst3 . unzip3 $ customer_issues_followUps_list

您的查询看起来不错,但随后您将结果通过
解压
,这需要一个包含两个元组的列表。请尝试取消ZIP3?是的!确切地非常感谢。
/home/hhefesto/dev/laurus-nobilis/src/Handler/Support.hs:40:5: error:
    • Couldn't match type ‘(ra, rb, rc)’ with ‘(Entity Issue, b0)’
        arising from a functional dependency between:
          constraint ‘Database.Esqueleto.Internal.Sql.SqlSelect
                        (E.SqlExpr (Entity Issue), E.SqlExpr (Entity FollowUp),
                         E.SqlExpr (Entity Customer))
                        (Entity Issue, b0)’
            arising from a use of ‘E.select’
          instance ‘Database.Esqueleto.Internal.Sql.SqlSelect
                      (a2, b2, c) (ra2, rb2, rc2)’
            at <no location info>
    • In the second argument of ‘($)’, namely
        ‘E.select
           $ E.from
               $ \ (i `E.InnerJoin` f `E.InnerJoin` c)
                   -> do E.on (c ^. CustomerId ==. i ^. IssueCustomerId)
                         E.on (i ^. IssueId ==. f ^. FollowUpIssueId)
                         ....’
      In a stmt of a 'do' block:
        customer_issues_followUps_list <- runDB
                                            $ E.select
                                                $ E.from
                                                    $ \ (i `E.InnerJoin` f `E.InnerJoin` c)
                                                        -> do E.on
                                                                (c ^. CustomerId
                                                                   ==. i ^. IssueCustomerId)
                                                              E.on
                                                                (i ^. IssueId
                                                                   ==. f ^. FollowUpIssueId)
                                                              ....
      In the expression:
        do customer_issues_followUps_list <- runDB
                                               $ E.select
                                                   $ E.from
                                                       $ \ (i `E.InnerJoin` f `E.InnerJoin` c)
                                                           -> do ...
           let issues
                 = map listToMaybe . group . sort . fst . unzip
                     $ customer_issues_followUps_list
           defaultLayout
             $ do setTitle "Your Licenses"
                  (do ...)
   |
40 |     E.select $
   |     ^^^^^^^^^^...
Customer
    email Text
    password Text
    firstName Text
    lastName Text
    address1 Text
    address2 Text
    city Text
    state Text
    zipCode Text
    country Text
    phone Text
    organization Text
    UniqueCustomer email
    deriving Typeable
    deriving Show
    deriving Eq
    deriving Ord
License
    licenseAlias Text
    expirationDate UTCTime
    assignedTo CustomerId
    customerId CustomerId
    deriving Show
    deriving Eq
    deriving Ord
Issue
    customerId CustomerId
    issueSummary Text
    issueDetails Text
    issueState Int
    issueDate UTCTime
    deriving Show
    deriving Eq
    deriving Ord
FollowUp
    issueId IssueId
    followUpDate UTCTime
    followUpAuthor CustomerId
    followUpText Text
    deriving Show
    deriving Eq
    deriving Ord


-- Soon to be deleted:
Email
    email Text
    customerId CustomerId Maybe
    verkey Text Maybe
    UniqueEmail email
Comment json -- Adding "json" causes ToJSON and FromJSON instances to be derived.
    message Text
    customerId CustomerId Maybe
    deriving Eq
    deriving Show
let issues = map listToMaybe . group . sort . fst . unzip $ customer_issues_followUps_list
let issues = map listToMaybe . group . sort . fst3 . unzip3 $ customer_issues_followUps_list