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
希望大家幫幫我。
預先感謝您
什麼應該是正確的? –
我試過你的想法,但它是一樣的,它有一個錯誤。 。 。 。 。 –