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

35 lines
850 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 {
2015-07-28 06:12:13 +00:00
postID :: Int
, postOID :: Text
, postBody :: Text
, postMarkdown :: Text
, postAuthor :: Text
, postPage :: Int
2015-07-28 05:54:37 +00:00
} 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 $
2015-07-28 06:12:13 +00:00
text $ postBody h