下面是我的模型的一个子集:
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)’我不明白我哪里出了问题?
编辑i是从这段代码开始的,它可以工作:
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发布于 2018-01-16 18:53:56
正确的。所以真的是我的愚蠢。我应该做一个样本项目来重现这个问题,然后我就会发现这个问题。
问题是我在文件的顶端..。
import Database.Esqueleto hiding (on)
import Data.Function..。因为我在文件on中使用了来自Data.Function的其他地方。
我把它改成..。
import Database.Esqueleto
import qualified Data.Function as F现在一切正常..。
https://stackoverflow.com/questions/48282779
复制相似问题