Show a single post on /

This commit is contained in:
Christine Dodrill 2015-07-27 22:54:37 -07:00
parent ab1a278660
commit b5f1a707e2
1 changed files with 29 additions and 6 deletions

View File

@ -1,13 +1,36 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Main where module Main where
import Control.Applicative
import Data.Monoid 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 :: IO ()
main = main = do
runSpock 5000 $ spockT id $ conn <- open "../db/posts.db"
do get root $
text "Hello World!" -- 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 -> get ("hello" <//> var) $ \name ->
text ("Hello " <> name <> "!") text ("Hello " <> name <> "!")