今天早上我开始在Yesod应用程序中设置Esqueleto。我真的想要做一个LeftOuterJoin,但为了让基础工作起作用,我已经将查询简化了很多。我甚至无法做到这一点。为了确保与Database.Persist.Query没有冲突,我跟着一些advice from a Github issue将我的查询提取到不导入Yesod的单独文件中。在配置Esqueleto时是否有一些我缺少的东西?
FWIW,我正在使用Yesod 1.4.0,Persistent 2.1& Esqueleto 2.1。
这是我遇到的错误:
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;
.... }
以下是我的模特:
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
这是我的疑问:
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)
答案 0 :(得分:1)
您需要更改功能签名。
findEntries :: SqlPersistT Handler [(Entity UrlEntry, Entity UrlEntryData)]