Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save justindthomas/cde3f0cf8036050f04e69a8197658867 to your computer and use it in GitHub Desktop.
Save justindthomas/cde3f0cf8036050f04e69a8197658867 to your computer and use it in GitHub Desktop.
data Article = Article
{ articleId :: Int
, title :: T.Text
, content :: T.Text
, created_at :: LocalTime
}
splice :: (HasPostgres n, Monad n) => C.Splice n
splice = do
C.manyWithSplices C.runChildren articleSplices $
lift $ query_ "SELECT * FROM article"
where
articleSplices = do
mapV (C.pureSplice . C.textSplice) $ do
"articleId" ## T.pack . show . articleId
"articleTitle" ## title
"articleContent" ## markdownToHtml . content
"articleCreation" ## presentTime created_at
markdownToHtml :: T.Text -> T.Text
markdownToHtml = T.pack . L.unpack . X.renderHtml . MD.markdown MD.def . L.fromStrict
presentTime :: LocalTime -> T.Text
presentTime l = do
tz <- getCurrentTimeZone
T.pack . show . utctDay $ localTimeToUTC tz l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment