From 63c976e618fe9e9b9ca1c833ad052f62a7d3486b Mon Sep 17 00:00:00 2001 From: Attila Domokos Date: Wed, 24 Jan 2018 18:24:41 -0600 Subject: [PATCH] Save a User along with Client --- Makefile | 1 - src/Hashmir/Data.hs | 12 ++++++++++++ test/Hashmir/DataSpec.hs | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e62080c..cef41bd 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,6 @@ create-db-user: ## Creates a DB user with the root MySQL user mysql -u root --host $(HOST) -e "GRANT ALL PRIVILEGES ON `$(DBNAME)`.* TO '$(DBUSER)'@'$(HOST)';" > /dev/null 2>&1 build-db: ## Builds the DB - @echo "Dropping and rebuilding database $(DBNAME)" @mysql -u $(DBUSER) --password='$(DBPASSWD)' --host $(HOST) -e "DROP DATABASE IF EXISTS $(DBNAME);" > /dev/null 2>&1 @mysql -u $(DBUSER) --password='$(DBPASSWD)' --host $(HOST) -e "CREATE DATABASE $(DBNAME);" > /dev/null 2>&1 @mysql -u $(DBUSER) --password='$(DBPASSWD)' --host $(HOST) $(DBNAME) < resources/schema.sql > /dev/null 2>&1 diff --git a/src/Hashmir/Data.hs b/src/Hashmir/Data.hs index 8a47033..6782826 100644 --- a/src/Hashmir/Data.hs +++ b/src/Hashmir/Data.hs @@ -15,6 +15,14 @@ import Database.HDBC.MySQL -- :client_name :: String -- :subdomain :: String INSERT INTO clients (name, subdomain) VALUES (:client_name, :subdomain); + ;;; + -- name:insertUserSQL + -- :client_id :: Integer + -- :login :: String + -- :email :: String + -- :password :: String + INSERT INTO users (client_id, login, email, password) + VALUES (:client_id, :login, :email, :password); |] getConn :: IO Connection @@ -41,3 +49,7 @@ insertClient name subdomain = countClient :: IO (Maybe Int) countClient = withConn countClientSQL + +insertUser :: Integer -> String -> String -> String -> IO Integer +insertUser clientId login email password = + withConn $ insertUserSQL clientId login email password diff --git a/test/Hashmir/DataSpec.hs b/test/Hashmir/DataSpec.hs index edd6550..93c1f07 100644 --- a/test/Hashmir/DataSpec.hs +++ b/test/Hashmir/DataSpec.hs @@ -16,3 +16,7 @@ spec = before resetDB $ do it "creates a Client record" $ do clientId <- D.insertClient "TestClient" "testclient" clientId `shouldBe` 1 + it "creates a Client and a User record" $ do + clientId <- D.insertClient "TestClient" "testclient" + userId <- D.insertUser clientId "joe" "joe@example.com" "password1" + userId `shouldBe` 1