on dev help sign in
@ ~> `
commitae60c7bfa852dc4397ba1a7dcbdbb05c9fb1ceb0 authorEitan Chatav <eitan.chatav@gmail.com> dateMon 19 Mar 2018, 15:09 (9 years ago) parent9481aff
2 files changed+30−30
README.md+15−15 squeal-postgresql/README.md+15−15
README.md+15−15
@@ -42,12 +42,12 @@ We'll use generics to easily convert between Haskell and PostgreSQL values.
4242```
4343
4444The first step is to define the schema of our database. This is where
45−we use @DataKinds@ and @TypeOperators@. The schema consists of a type-level
45+we use `DataKinds` and `TypeOperators`. The schema consists of a type-level
4646list of tables, a `:::` pairing of a type level string or
47−@Symbol@ and a list a columns, itself a `:::` pairing of a
48−@Symbol@ and a `ColumnType`. The `ColumnType` describes the
47+`Symbol` and a list a columns, itself a `:::` pairing of a
48+`Symbol` and a `ColumnType`. The `ColumnType` describes the
4949PostgreSQL type of the column as well as whether or not it may contain
50−@NULL@ and whether or not inserts and updates can use a @DEFAULT@. For our
50+`NULL` and whether or not inserts and updates can use a `DEFAULT`. For our
5151schema, we'll define two tables, a users table and an emails table.
5252
5353```haskell
@@ -103,7 +103,7 @@ We can easily see the generated SQL is unsuprising looking.
103103"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);"
104104```
105105
106−Notice that @setup@ starts with an empty schema @'[]@ and produces @Schema@.
106+Notice that `setup` starts with an empty schema `'[]` and produces `Schema`.
107107In our `createTable` commands we included `TableConstraint`s to define
108108primary and foreign keys, making them somewhat complex. Our tear down
109109`Definition` is simpler.
@@ -122,8 +122,8 @@ Next, we'll write `Manipulation`s to insert data into our two tables.
122122A `Manipulation` is a `insertInto`, `update` or `deleteFrom` command and
123123has three type parameters, the schema it refers to, a list of parameters
124124it can take as input, and a list of columns it produces as output. When
125−we insert into the users table, we will need a parameter for the @name@
126−field but not for the @id@ field. Since it's optional, we can use a default
125+we insert into the users table, we will need a parameter for the `name`
126+field but not for the `id` field. Since it's optional, we can use a default
127127value. However, since the emails table refers to the users table, we will
128128need to retrieve the user id that the insert generates and insert it into
129129the emails table. Take a careful look at the type and definition of both
@@ -135,7 +135,7 @@ let
135135 insertUser :: Manipulation Schema '[ 'NotNull 'PGtext ]
136136 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
137137 insertUser = insertRow #users
138− (Default `As` #id :* Set (param @1) `As` #name :* Nil)
138+ (Default `As` #id :* Set (param `1) `As` #name :* Nil)
139139 OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
140140:}
141141>>> :{
@@ -143,8 +143,8 @@ let
143143 insertEmail :: Manipulation Schema '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
144144 insertEmail = insertRow #emails
145145 ( Default `As` #id :*
146− Set (param @1) `As` #user_id :*
147− Set (param @2) `As` #email :* Nil )
146+ Set (param `1) `As` #user_id :*
147+ Set (param `2) `As` #email :* Nil )
148148 OnConflictDoNothing (Returning Nil)
149149:}
150150>>> renderManipulation insertUser
@@ -176,8 +176,8 @@ let
176176Now that we've defined the SQL side of things, we'll need a Haskell type
177177for users. We give the type `Generics.SOP.Generic` and
178178`Generics.SOP.HasDatatypeInfo` instances so that we can decode the rows
179−we receive when we run @getUsers@. Notice that the record fields of the
180−@User@ type match the column names of @getUsers@.
179+we receive when we run `getUsers`. Notice that the record fields of the
180+`User` type match the column names of `getUsers`.
181181
182182```haskell
183183>>> data User = User { userName :: Text, userEmail :: Maybe Text } deriving (Show, .Generic)
@@ -192,9 +192,9 @@ Let's also create some users to add to the database.
192192let
193193 users :: [User]
194194 users =
195− [ User "Alice" (Just "alice@gmail.com")
195+ [ User "Alice" (Just "alice`gmail.com")
196196 , User "Bob" Nothing
197− , User "Carole" (Just "carole@hotmail.com")
197+ , User "Carole" (Just "carole`hotmail.com")
198198 ]
199199:}
200200```
@@ -225,5 +225,5 @@ void . withConnection "host=localhost port=5432 dbname=exampledb" $
225225 & pqThen session
226226 & thenDefine teardown
227227:}
228−[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"}]
229229```
squeal-postgresql/README.md+15−15
@@ -42,12 +42,12 @@ We'll use generics to easily convert between Haskell and PostgreSQL values.
4242```
4343
4444The first step is to define the schema of our database. This is where
45−we use @DataKinds@ and @TypeOperators@. The schema consists of a type-level
45+we use `DataKinds` and `TypeOperators`. The schema consists of a type-level
4646list of tables, a `:::` pairing of a type level string or
47−@Symbol@ and a list a columns, itself a `:::` pairing of a
48−@Symbol@ and a `ColumnType`. The `ColumnType` describes the
47+`Symbol` and a list a columns, itself a `:::` pairing of a
48+`Symbol` and a `ColumnType`. The `ColumnType` describes the
4949PostgreSQL type of the column as well as whether or not it may contain
50−@NULL@ and whether or not inserts and updates can use a @DEFAULT@. For our
50+`NULL` and whether or not inserts and updates can use a `DEFAULT`. For our
5151schema, we'll define two tables, a users table and an emails table.
5252
5353```haskell
@@ -103,7 +103,7 @@ We can easily see the generated SQL is unsuprising looking.
103103"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);"
104104```
105105
106−Notice that @setup@ starts with an empty schema @'[]@ and produces @Schema@.
106+Notice that `setup` starts with an empty schema `'[]` and produces `Schema`.
107107In our `createTable` commands we included `TableConstraint`s to define
108108primary and foreign keys, making them somewhat complex. Our tear down
109109`Definition` is simpler.
@@ -122,8 +122,8 @@ Next, we'll write `Manipulation`s to insert data into our two tables.
122122A `Manipulation` is a `insertInto`, `update` or `deleteFrom` command and
123123has three type parameters, the schema it refers to, a list of parameters
124124it can take as input, and a list of columns it produces as output. When
125−we insert into the users table, we will need a parameter for the @name@
126−field but not for the @id@ field. Since it's optional, we can use a default
125+we insert into the users table, we will need a parameter for the `name`
126+field but not for the `id` field. Since it's optional, we can use a default
127127value. However, since the emails table refers to the users table, we will
128128need to retrieve the user id that the insert generates and insert it into
129129the emails table. Take a careful look at the type and definition of both
@@ -135,7 +135,7 @@ let
135135 insertUser :: Manipulation Schema '[ 'NotNull 'PGtext ]
136136 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
137137 insertUser = insertRow #users
138− (Default `As` #id :* Set (param @1) `As` #name :* Nil)
138+ (Default `As` #id :* Set (param `1) `As` #name :* Nil)
139139 OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
140140:}
141141>>> :{
@@ -143,8 +143,8 @@ let
143143 insertEmail :: Manipulation Schema '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
144144 insertEmail = insertRow #emails
145145 ( Default `As` #id :*
146− Set (param @1) `As` #user_id :*
147− Set (param @2) `As` #email :* Nil )
146+ Set (param `1) `As` #user_id :*
147+ Set (param `2) `As` #email :* Nil )
148148 OnConflictDoNothing (Returning Nil)
149149:}
150150>>> renderManipulation insertUser
@@ -176,8 +176,8 @@ let
176176Now that we've defined the SQL side of things, we'll need a Haskell type
177177for users. We give the type `Generics.SOP.Generic` and
178178`Generics.SOP.HasDatatypeInfo` instances so that we can decode the rows
179−we receive when we run @getUsers@. Notice that the record fields of the
180−@User@ type match the column names of @getUsers@.
179+we receive when we run `getUsers`. Notice that the record fields of the
180+`User` type match the column names of `getUsers`.
181181
182182```haskell
183183>>> data User = User { userName :: Text, userEmail :: Maybe Text } deriving (Show, .Generic)
@@ -192,9 +192,9 @@ Let's also create some users to add to the database.
192192let
193193 users :: [User]
194194 users =
195− [ User "Alice" (Just "alice@gmail.com")
195+ [ User "Alice" (Just "alice`gmail.com")
196196 , User "Bob" Nothing
197− , User "Carole" (Just "carole@hotmail.com")
197+ , User "Carole" (Just "carole`hotmail.com")
198198 ]
199199:}
200200```
@@ -225,5 +225,5 @@ void . withConnection "host=localhost port=5432 dbname=exampledb" $
225225 & pqThen session
226226 & thenDefine teardown
227227:}
228−[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"}]
229229```