Created
April 13, 2016 03:47
-
-
Save justindthomas/c4b6d891d948f42ad9cefe87d0927b62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main :: IO () | |
main = do | |
putStrLn "Starting Server..." | |
S.scotty 3000 $ do | |
S.get "/" $ S.html "Hello World!" | |
S.get "/articles" $ do | |
articles <- inHandlerDb $ selectList [] [] | |
S.html ("Articles!" <> (T.pack $ show $ length (articles :: [Entity Article]))) | |
S.get "/articles/:id" $ do | |
articleId <- S.param "id" | |
findArticle <- inHandlerDb $ get (toSqlKey (read articleId)) | |
S.html $ (markdownToHtml $ show (findArticle :: Maybe Article)) | |
inHandlerDb = liftIO . dbFunction | |
dbFunction query = runStderrLoggingT $ | |
withPostgresqlPool connStr 10 $ | |
\pool -> liftIO $ runSqlPersistMPool query pool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment