haskell - yesod respond plain text -
haskell - yesod respond plain text -
as i'm new haskell, kindly force me right direction of solving next problem...?
i started yesod's scaffolding application. serving html generated database content works fine, there elegant way create plain text responses iterating on database tables? simple plain text using handler like
gettestr = homecoming . repplain . tocontent ...
works too, i'd serve:
config/models:
file path text conf key text val text file fileid
as plaintext in sql query:
select path, key, val file, conf order path, key;
as hamlet generating html, think must generate response (iterate on database contents) exclusively in haskell?
how convert between database entity , text (or int, if row of type int), how convert , database column id?
with plain text template!! ''#{expr}'' admits text, string, int32 or int64 expressions instances of text.shakespeare.text.totext
{-# language overloadedstrings, constraintkinds #-} module handler.plain import import import qualified data.list list import database.persist.sqlite import qualified data.text text import control.monad.logger (monadlogger) import control.monad.trans.resource (monadresourcebase) import text.shakespeare.text -- plain text template stmt :: text stmt = "select ??, ?? file, conf on conf.file = file.id order file.path, conf.key" getqryresult :: (persistquery sqlpersist m, monadlogger m, monadresourcebase m) => () -> sqlpersist m [(text, text, text)] getqryresult () = result <- rawsql stmt [] homecoming $ list.map getmydata (result :: [(entity file, entity conf)]) getmydata (entity _ file, entity _ conf) = (filepath file, confkey conf, confval conf) getplainr :: handler repplain getplainr = result <- rundb $ getqryresult () homecoming $ repplain $ tocontent $ text.unlines $ list.map formatmydata result -- formatmydata (a, b, c) = text.intercalate ", " [a,b,c] -- plain text template: formatmydata (a, b, c) = [st| #{a}, #{b}, #{c} |]
haskell yesod
Comments
Post a Comment