Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save justindthomas/c4b6d891d948f42ad9cefe87d0927b62 to your computer and use it in GitHub Desktop.
Save justindthomas/c4b6d891d948f42ad9cefe87d0927b62 to your computer and use it in GitHub Desktop.
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