0
希望您能帮助我解决这个问题。Yesod Single RawSql并将其作为JSON格式返回
我有一个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
我的问题是: 做我的代码在处理器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
希望大家帮帮我。
预先感谢您
什么应该是正确的? –
我试过你的想法,但它是一样的,它有一个错误。 。 。 。 。 –