Permalink
Browse files

Introducing 'withConn' function, similar to withFile

  • Loading branch information...
adomokos committed Dec 5, 2017
1 parent be7a55f commit 841959b7da65baf8b5a351d2e06d5ae0525b511d
Showing with 13 additions and 5 deletions.
  1. +13 −5 app/Main.hs
View
@@ -27,20 +27,28 @@ getConn = do
mysqlUnixSocket = "/tmp/mysql.sock"
}
insertClient :: String -> String -> IO ()
insertClient name subdomain = do
withConn :: (Connection -> IO b) -> IO b
withConn f = do
conn <- getConn
clientId <- insertClientSQL name subdomain conn
result <- f conn
H.commit conn
H.disconnect conn
return result
insertClient :: String -> String -> IO ()
insertClient name subdomain = do
clientId <-
withConn (\conn -> do
insertClientSQL name subdomain conn
)
putStrLn $ "New client's id is " ++ show clientId
countClient :: IO ()
countClient = do
conn <- getConn
Just (clientCount) <- countClientSQL conn
H.commit conn
H.disconnect conn
H.commit conn -- added line
H.disconnect conn -- added line
putStrLn $ "There are " ++ show clientCount ++ " records."
main :: IO ()

0 comments on commit 841959b

Please sign in to comment.