From b5f1a707e2b096ad17a64618bb15b1cd5f032433 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 27 Jul 2015 22:54:37 -0700 Subject: [PATCH] Show a single post on / --- web/src/Main.hs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/web/src/Main.hs b/web/src/Main.hs index e31d69d..bea14e4 100644 --- a/web/src/Main.hs +++ b/web/src/Main.hs @@ -1,13 +1,36 @@ {-# LANGUAGE OverloadedStrings #-} module Main where +import Control.Applicative import Data.Monoid -import Web.Spock.Safe +import Data.Text hiding (head) +import Database.SQLite.Simple +import Database.SQLite.Simple.FromRow +import Web.Spock.Safe hiding (head) + +data Post = Post { + postID :: Int + , postOID :: String + , postBody :: String + , postMarkdown :: String + , postAuthor :: String + , postPage :: Int +} deriving (Show, Eq) + +instance FromRow Post where + fromRow = Post <$> field <*> field <*> field <*> field <*> field <*> field main :: IO () -main = - runSpock 5000 $ spockT id $ - do get root $ - text "Hello World!" - get ("hello" var) $ \name -> +main = do + conn <- open "../db/posts.db" + + -- Simple tests to prove we're reading from SQLite + r <- query_ conn "SELECT * FROM Posts WHERE page=1" :: IO [Post] + let h = head r + + -- Set up the URL router + runSpock 5000 $ spockT id $ do + get root $ + text $ pack $ postBody h + get ("hello" var) $ \name -> text ("Hello " <> name <> "!")