今天早上我开始在 Yesod 应用程序中设置 Esqueleto。我真的在尝试做一个 LeftOuterJoin,但我已经将查询简化了很多,以便让基础工作正常。我什至无法理解。为了确保与 Database.Persist.Query 没有冲突,我遵循了 Github 问题中的一些建议,将我的查询提取到不导入 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)