Permalink
Browse files

Save a User along with Client

  • Loading branch information...
adomokos committed Jan 25, 2018
1 parent be20905 commit 63c976e618fe9e9b9ca1c833ad052f62a7d3486b
Showing with 16 additions and 1 deletion.
  1. +0 −1 Makefile
  2. +12 −0 src/Hashmir/Data.hs
  3. +4 −0 test/Hashmir/DataSpec.hs
@@ -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
@@ -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
@@ -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

0 comments on commit 63c976e

Please sign in to comment.