这是我的模型的一个子集:
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