Skip to content

Commit

Permalink
Save a User along with Client
Browse files Browse the repository at this point in the history
  • Loading branch information
adomokos committed Jan 25, 2018
1 parent be20905 commit 63c976e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Hashmir/Data.hs
Expand Up @@ -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
Expand All @@ -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
4 changes: 4 additions & 0 deletions test/Hashmir/DataSpec.hs
Expand Up @@ -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.