Guest User

Untitled

a guest
Aug 7th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. {-# LANGUAGE OverloadedStrings #-}
  2. import Network.Wai
  3. import Network.HTTP.Types
  4. import Network.Wai.Handler.Warp (run)
  5. import Database.MySQL.Simple
  6. import Data.Pool (Pool, createPool, withResource)
  7.  
  8. newConn = connect defaultConnectInfo
  9. { connectHost = "db"
  10. , connectUser = "root"
  11. , connectPassword = "secret"
  12. , connectDatabase = "test" }
  13.  
  14. getPool = createPool newConn close 1 10 5
  15.  
  16. app :: Pool Connection -> Application
  17. app pool _ respond = do
  18. withResource pool $ c -> query_ c "SELECT 1" :: IO [Only Int]
  19. respond $ responseLBS
  20. status200
  21. [("Content-Type", "text/plain")]
  22. "Hello, Web!"
  23.  
  24. main :: IO ()
  25. main = do
  26. putStrLn $ "http://localhost:8080/"
  27. pool <- getPool
  28. run 8080 $ app $ pool
Add Comment
Please, Sign In to add comment