这是我模特的一个子集:
ServerWebsite
desc Text
url Text
text Text
username Text
password Password
serverDatabaseId ServerDatabaseId Maybe
groupName Text Maybe
serverId ServerId
deriving Show Typeable
ServerDatabase
desc Text
name Text
text Text
username Text
password Password
groupName Text Maybe
serverId ServerId
deriving Show Typeable
我无法进行此查询构建:
filterServerWebsites :: SqlExpr (Value Text) -> SqlPersistM [Entity ServerWebsite]
filterServerWebsites query = select $ from $ \(w `LeftOuterJoin` db) -> do
on (w ^. ServerWebsiteServerDatabaseId ==. db ?. ServerDatabaseId)
where_ ((w ^. ServerWebsiteDesc `like` query)
||. (w ^. ServerWebsiteUrl `like` query)
||. (w ^. ServerWebsiteText `like` query)
||. (db ?. ServerDatabaseDesc `like` just query))
return w
我不了解构建错误:
• Couldn't match expected type ‘SqlQuery a1’
with actual type ‘(a0 -> b0) -> a0 -> a0 -> c0’
• Probable cause: ‘on’ is applied to too few arguments
In a stmt of a 'do' block:
on (w ^. ServerWebsiteServerDatabaseId ==. db ?. ServerDatabaseId)
和
• Couldn't match expected type ‘b0 -> b0 -> c0’
with actual type ‘SqlExpr (Value Bool)’
• Possible cause: ‘(==.)’ is applied to too many arguments
In the first argument of ‘on’, namely
‘(w ^. ServerWebsiteServerDatabaseId ==. db ?. ServerDatabaseId)’
我不明白我哪里出错了?
修改 我从这段代码开始,它可以工作:
filterServerWebsites :: SqlExpr (Value Text) -> SqlPersistM [Entity ServerWebsite]
filterServerWebsites query = select $ from $ \w -> do
where_ ((w ^. ServerWebsiteDesc `like` query)
||. (w ^. ServerWebsiteUrl `like` query)
||. (w ^. ServerWebsiteText `like` query))
return w
答案 0 :(得分:1)
右。所以真的是我自己的愚蠢。我应该制作一个样本项目来重现这个问题,然后我会发现这个问题。
问题是我在文件顶部...
import Database.Esqueleto hiding (on)
import Data.Function
...因为我正在使用on
中该文件Data.Function
中的其他位置。
我把它改为......
import Database.Esqueleto
import qualified Data.Function as F
现在一切正常......