Permalink
Browse files

Pass Sqlite3 connection to controllers

  • Loading branch information...
1 parent c4774c8 commit a3723185e1632427636f6bd3cafae7d6837c9213 @singpolyma committed Mar 20, 2013
Showing with 11 additions and 8 deletions.
  1. +2 −2 Application.hs
  2. +7 −4 Main.hs
  3. +2 −2 Makefile
View
@@ -34,7 +34,7 @@ responseTextBuilder s h = ResponseBuilder s h . Blaze.fromLazyText . TL.toLazyTe
on404 :: Application
on404 _ = string notFound404 [] "Not Found"
-reportFor :: RippleAddress -> Application
-reportFor adr req = return $ responseTextBuilder ok200 headers (viewReport htmlEscape $ Report adr)
+reportFor :: Connection -> RippleAddress -> Application
+reportFor db adr req = return $ responseTextBuilder ok200 headers (viewReport htmlEscape $ Report adr)
where
Just headers = stringHeaders [("Content-Type", "text/html; charset=utf8")]
View
11 Main.hs
@@ -1,18 +1,21 @@
module Main (main) where
+import Control.Monad (void)
+
import Network.Wai.Handler.Warp (run)
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Network.Wai.Middleware.Autohead (autohead)
import Network.Wai.Middleware.Jsonp (jsonp)
import Network.Wai.Middleware.AcceptOverride (acceptOverride)
+import Database.SQLite.Simple (withConnection)
+
import Network.Wai.Dispatch
import Routes
import Application
main :: IO ()
-main = do
- putStrLn "Running..."
- run 3000 $
+main = void $ withConnection "./dev.db"
+ (\db -> run 3000 $
logStdoutDev $ autohead $ acceptOverride $ jsonp $ -- Middleware
- dispatch on404 $ routes -- Do routing
+ dispatch on404 $ routes db) -- Do routing
View
@@ -2,10 +2,10 @@ Main: Main.hs Application.hs Routes.hs MustacheTemplates.hs
ghc -Wall -fno-warn-name-shadowing Main.hs
Routes.hs: routes
- routeGenerator -r -m Application -n 0 $< > $@
+ routeGenerator -r -m Application -n 1 $< > $@
PathHelpers.hs: routes
- routeGenerator -p -n 0 $< > $@
+ routeGenerator -p -n 1 $< > $@
MustacheTemplates.hs: Records.hs view/report.mustache
mustache2hs -m Records.hs view/report.mustache Report > $@

0 comments on commit a372318

Please sign in to comment.