Permalink
Browse files

Insert a Client record

  • Loading branch information...
adomokos committed Dec 4, 2017
1 parent 78a597e commit dbdbcc3d41bf84f7230ef0ff98f78f6752c115ab
Showing with 17 additions and 1 deletion.
  1. +17 −1 app/Main.hs
View
@@ -4,11 +4,17 @@
module Main where
import Database.YeshQL
import qualified Database.HDBC as H
import Database.HDBC.MySQL
[yesh|
-- name:countClientSQL :: (Int)
SELECT count(id) FROM clients;
;;;
-- name:insertClientSQL
-- :client_name :: String
-- :subdomain :: String
INSERT INTO clients (name, subdomain) VALUES (:client_name, :subdomain);
|]
getConn :: IO Connection
@@ -21,11 +27,21 @@ getConn = do
mysqlUnixSocket = "/tmp/mysql.sock"
}
insertClient :: String -> String -> IO ()
insertClient name subdomain = do
conn <- getConn
clientId <- insertClientSQL name subdomain conn
H.commit conn
H.disconnect conn
putStrLn $ "New client's id is " ++ show clientId
countClient :: IO ()
countClient = do
conn <- getConn
Just (clientCount) <- countClientSQL conn
putStrLn $ "There are " ++ show clientCount ++ " records."
main :: IO ()
main = countClient
main = do
insertClient "TestClient" "testclient"
countClient

0 comments on commit dbdbcc3

Please sign in to comment.