Skip to content

Commit

Permalink
Insert a Client record
Browse files Browse the repository at this point in the history
  • Loading branch information
adomokos committed Dec 4, 2017
1 parent 78a597e commit dbdbcc3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/Main.hs
Expand Up @@ -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
Expand All @@ -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.