@@ -100,8 +100,6 @@ We can easily see the generated SQL is unsuprising looking.
101```haskell
101```haskell
102>>> renderDefinition setup
102>>> renderDefinition setup
105"CREATE TABLE users (id serial, name text NOT NULL, CONSTRAINT pk_users PRIMARY KEY (id)); CREATE TABLE emails (id serial, user_id int NOT NULL, email text, CONSTRAINT pk_emails PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES rs (id) ON DELETE CASCADE ON UPDATE CASCADE);"
103"CREATE TABLE users (id serial, name text NOT NULL, CONSTRAINT pk_users PRIMARY KEY (id)); CREATE TABLE emails (id serial, user_id int NOT NULL, email text, CONSTRAINT pk_emails PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES rs (id) ON DELETE CASCADE ON UPDATE CASCADE);"
@@ -117,8 +115,6 @@ let
117 teardown = dropTable #emails >>> dropTable #users
115 teardown = dropTable #emails >>> dropTable #users
119>>> renderDefinition teardown
117>>> renderDefinition teardown
122"DROP TABLE emails; DROP TABLE users;"
118"DROP TABLE emails; DROP TABLE users;"
@@ -154,8 +150,6 @@ let
154>>> renderManipulation insertUser
150>>> renderManipulation insertUser
155"INSERT INTO users (id, name) VALUES (DEFAULT, ($1 :: text)) ON CONFLICT DO NOTHING URNING id AS fromOnly;"
151"INSERT INTO users (id, name) VALUES (DEFAULT, ($1 :: text)) ON CONFLICT DO NOTHING URNING id AS fromOnly;"
156>>> renderManipulation insertEmail
152>>> renderManipulation insertEmail
159"INSERT INTO emails (id, user_id, email) VALUES (DEFAULT, ($1 :: int4), ($2 :: text)N CONFLICT DO NOTHING;"
153"INSERT INTO emails (id, user_id, email) VALUES (DEFAULT, ($1 :: int4), ($2 :: text)N CONFLICT DO NOTHING;"
@@ -177,8 +171,6 @@ let
177 (#u ! #id .== #e ! #user_id)) )
171 (#u ! #id .== #e ! #user_id)) )
179>>> renderQuery getUsers
173>>> renderQuery getUsers
182"SELECT u.name AS userName, e.email AS userEmail FROM users AS u INNER JOIN emails e ON (u.id = e.user_id)"
174"SELECT u.name AS userName, e.email AS userEmail FROM users AS u INNER JOIN emails e ON (u.id = e.user_id)"
184Now that we've defined the SQL side of things, we'll need a Haskell type
176Now that we've defined the SQL side of things, we'll need a Haskell type
@@ -233,7 +225,5 @@ void . withConnection "host=localhost port=5432 dbname=exampledb" $
233 & pqThen session
225 & pqThen session
234 & thenDefine teardown
226 & thenDefine teardown
238[User {userName = "Alice", userEmail = Just "alice@gmail.com"},User {userName = "Bob", userEmail = Nothing},User {userName = "Carole", userEmail = Just role@hotmail.com"}]
228[User {userName = "Alice", userEmail = Just "alice@gmail.com"},User {userName = "Bob", userEmail = Nothing},User {userName = "Carole", userEmail = Just role@hotmail.com"}]