time-wasting-thread-memorial/web/src/Main.hs

37 lines
929 B
Haskell
Raw Normal View History

2015-07-28 05:03:13 +00:00
{-# LANGUAGE OverloadedStrings #-}
module Main where
2015-07-28 05:54:37 +00:00
import Control.Applicative
2015-07-28 05:03:13 +00:00
import Data.Monoid
2015-07-28 05:54:37 +00:00
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
2015-07-28 05:03:13 +00:00
main :: IO ()
2015-07-28 05:54:37 +00:00
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 ->
2015-07-28 05:03:13 +00:00
text ("Hello " <> name <> "!")