0

希望你能帮我解决这个问题。

我有一个rawSql:

latestPrice :: Handler [(Single PricesId, Single PersistValue, Single    PersistValue, Single PersistValue, Single PersistValue, Single PersistValue)]
latestPrice = do
  runDB $ rawSql qryStr []
        where qryStr = " SELECT prices.id,\
                            \CONCAT(cities.name, '(', states.code, '), ', countries.name) as city, \
                            \prices.s_id, \
                            \prices.s_name, \
                            \prices.quality, \
                            \AVG(prices.amount) as amount \
                    \FROM prices \
                    \INNER JOIN cities ON cities.id = prices.city_id \
                    \INNER JOIN states ON states.id = cities.state_id \
                    \INNER JOIN countries ON countries.id = states.country_id \
                    \WHERE prices.city_id > 0 \
                    \GROUP BY prices.id, city, prices.strain_id, prices.strain_name, prices.quality, prices.quality;";

我有一个调用该函数的处理程序,应该返回一个 JSON 格式:

getLatestPriceSubmissionR:: Handler (Value)
getLatestPriceSubmissionR  = do
    results <- latestPrice
    return map (
     \(Single id, Single city, Single s_name, Single strain_id, Single quality, Single amount) -> [ "id" .= id,"city" .=  city,"s_id" .=  s_id,"s_name" .=  s_name, "quality" .= quality,"amount" .= amount ]
   ) results

我的问题是:我在 Handler 中的代码getLatestPriceSubmissionR是否正确?它确实只给了我一条警告消息而不是一条错误消息:

Couldn't match type [[aeson-0.8.0.0:Data.Aeson.Types.Internal.Pair]]
          with Value
Expected type: HandlerT App IO Value
Actual type: HandlerT
             App IO [[aeson-0.8.0.0:Data.Aeson.Types.Internal.Pair]] …

No instance for (ToTypedContent [Value])
arising from a use of yesodRunner

希望你能帮助我。

先感谢您

4

1 回答 1

1

线

return map (\(...) -> [ ... ]) results

看起来不对,你可能是说

return $ map (\(...) -> [ ... ]) results

此外,这会返回一个列表列表,这Value与类型签名中的不同。

此外,这是一个错误,而不是警告:

Couldn't match type [[aeson-0.8.0.0:Data.Aeson.Types.Internal.Pair]]
          with Value
Expected type: HandlerT App IO Value
Actual type: HandlerT
             App IO [[aeson-0.8.0.0:Data.Aeson.Types.Internal.Pair]] …
于 2015-05-08T07:40:25.883 回答