1. Luke Plant
  2. haskellblog

Commits

Luke Plant  committed 7cbd001

Only use one DB connection

  • Participants
  • Parent commits ccbf534
  • Branches default

Comments (0)

Files changed (3)

File src/Blog/Forms.hs

View file
  • Ignore whitespace
 
 -- | extract the posted data from a POST request and build
 -- a Comment from it, returning a Comment and a list of validation errors
-validateComment creds postedData blogpost =
+validateComment cn creds postedData blogpost =
     do
     -- TODO - nicer mechanism for validation
 
     --    this will catch most humans using a browser
 
       ts <- getTimestamp
-      spamwords <- getSpamWords
+      spamwords <- getSpamWords cn
       let text = postedData "message" `captureOrDefault` ""
       let name = strip (postedData "name" `captureOrDefault` "")
       let email = postedData "email" `captureOrDefault` ""

File src/Blog/Model.hs

View file
  • Ignore whitespace
                      )
   return ()
 
-getSpamWords :: IO [String]
-getSpamWords = do
+getSpamWords :: (IConnection conn) => conn -> IO [String]
+getSpamWords cn = do
   cn <- DB.connect
   res <- quickQuery' cn getSpamWordsQuery []
   return [fromSql $ row !! 0 | row <- res]

File src/Blog/Views.hs

View file
  • Ignore whitespace
         case requestMethod req of
           "POST" -> do
             creds <- getCredentials req
-            (commentData, commentErrors, commentExtra) <- validateComment creds (getPOST req) post
+            (commentData, commentErrors, commentExtra) <- validateComment cn creds (getPOST req) post
             if null commentErrors
                then if isJust (getPOST req "submit")
                     then do