Getting data out of rawQuery using Conduits
I admit I do not really understand Conduits very well given my limited
Haskell knowledge. So appreciate if someone can guide me on how to
accomplish this task: I would like to take the output of a rawQuery action
and store it in a variable that I can then use again in my Hamlet file.
For example:
let sql = "SELECT sum(value) as total, category FROM person GROUP BY
category ORDER BY total desc;"
--- ?? how to store this runDB output in a variable?
runDB $ rawQuery sql [] $$ CL.map (convertFromPersistent)
where
convertFromPersistent [] = Nothing
convertFromPersistent [PersistInt64 sum,PersistInt64 category] = Just
(sum,category)
convertFromPersistent _ = Nothing
When I do
runDB $ rawQuery sql [] $$ CL.mapM_ (liftIO. print. convertFromPersistent)
I see the output in the log file. However, I would like to pipe the output
to an array of tuples so I can work with it in my Hamlet file. Appreciate
your help!
Thanks,
No comments:
Post a Comment