on dev help sign in
Update squeal-presentation-2018-09-12.md
9432302Eitan Chatav
squeal-presentation-2018-09-12.md+29−35
@@ -63,16 +63,13 @@ type Schema = '[ "mp" ::: 'Table MemberOfParliament
63 , "groupp" ::: 'Table ParliamentGroup ]
63 , "groupp" ::: 'Table ParliamentGroup ]
64```
64```
65
65
66−--
66+---
67
67
68−.note[*
69−We need the `DataKinds` extension to be able to express heterogenous lists containing
68+> _note_ We need the `DataKinds` extension to be able to express heterogenous lists containing
70−specific types like this one.
69+> specific types like this one.
71
70
72−*
73−You can perfectly call your table "group" and not "groupp" even though it is a
71+> You can perfectly call your table "group" and not "groupp" even though it is a
74−keyword in SQL - Squeal queries will be properly escaped.
72+> keyword in SQL - Squeal queries will be properly escaped.
75−]
76
73
77---
74---
78
75
@@ -95,11 +92,10 @@ type ParliamentaryGroup =
95
92
96- Let's split constraints and column to study the syntax a bit more.
93- Let's split constraints and column to study the syntax a bit more.
97
94
98−--
95+---
99
96
100−.note[*
101−We are using `:::` and `:=>` to quickly express associations when writing
97+> _note_ We are using `:::` and `:=>` to quickly express associations when writing
102−our schema. We need the `TypeOperators` extension.]
98+> our schema. We need the `TypeOperators` extension.]
103
99
104---
100---
105
101
@@ -148,10 +144,10 @@ type MpCols =
148
144
149 * the type (obviously).
145 * the type (obviously).
150
146
151−--
147+---
152
148
153−.note[*
149+> _note_ GHC is already helping. If I named the "mp_id" column differently,
154−GHC is already helping. If I named the "mp_id" column differently, GHC would yell because I promised a primary key constraint on a column named `mp_id`, so there must be one.]
150+> GHC would yell because I promised a primary key constraint on a column named `mp_id`, so there must be one.]
155
151
156---
152---
157
153
@@ -161,7 +157,7 @@ GHC is already helping. If I named the "mp_id" column differently, GHC would yel
161
157
162- But before we play with this schema, we need to implement it.
158- But before we play with this schema, we need to implement it.
163
159
164−--
160+---
165
161
166```haskell
162```haskell
167setup :: Definition '[] Schema
163setup :: Definition '[] Schema
@@ -193,15 +189,14 @@ setup =
193
189
194- You use `>>>` to compose table creation.
190- You use `>>>` to compose table creation.
195
191
196−- Note that the compiler will catch any mistype between Schema and
192+> _note_ The compiler will catch any mistype between Schema and
197−definition; wrong nullability, wrong type, wrong name, etc.
193+> definition; wrong nullability, wrong type, wrong name, etc.
198
194
199−--
195+---
200
196
201−.note[*
202−You'll also need `OverloadedLabels`, for naming stuff.
197+> _note_ You'll also need `OverloadedLabels`, for naming stuff.
203−This is mostly to avoid having to write manual proxies all
198+> This is mostly to avoid having to write manual proxies all
204−the time and for convenience.]
199+> the time and for convenience.
205
200
206---
201---
207
202
@@ -236,8 +231,8 @@ tearDown :: Definition Schema '[]
236tearDown = dropTable #mp >>> dropTable #groupp
231tearDown = dropTable #mp >>> dropTable #groupp
237```
232```
238
233
239−- Note that GHC will also detect the _proper_ order of what you typed in
234+> _note_ GHC will also detect the _proper_ order of what you typed in
240− downgrade and upgrade should there be any conflict (with foreign keys).
235+> downgrade and upgrade should there be any conflict (with foreign keys).
241
236
242```haskell
237```haskell
243initDB :: Migration IO '[] Schema
238initDB :: Migration IO '[] Schema
@@ -316,9 +311,8 @@ data MemberOfParliament =
316 , lastName :: Text }
311 , lastName :: Text }
317```
312```
318
313
319−- You'll note that we didn't use anything from Squeal.
314+> _note_ We didn't use anything from Squeal.
320−
321−- The model can be entirely separated from the persistence layer.
315+> The model can be entirely separated from the persistence layer.
322
316
323---
317---
324
318
@@ -333,7 +327,7 @@ type GroupInsertionParams = '[ 'NotNull 'PGuuid
333
327
334- Params are not named, but they are indexed. You just need nullability and type.
328- Params are not named, but they are indexed. You just need nullability and type.
335
329
336−--
330+---
337
331
338```haskell
332```haskell
339groupInsertion :: Manipulation Schema GroupInsertionParams '[]
333groupInsertion :: Manipulation Schema GroupInsertionParams '[]
@@ -342,7 +336,7 @@ groupInsertion =
342 :* Set (param @2) `as` #name )
336 :* Set (param @2) `as` #name )
343```
337```
344
338
345−--
339+---
346
340
347- `TypeApplication` lets us use the index of parameters (counting from 1).
341- `TypeApplication` lets us use the index of parameters (counting from 1).
348
342
@@ -357,19 +351,19 @@ _Inserting a Member of Parliament_
357
351
358- We could create a naive query that takes MP uuid, first name, last name and group uuid...
352- We could create a naive query that takes MP uuid, first name, last name and group uuid...
359
353
360−--
354+---
361
355
362- But that's boring. So let's use the `INSERT INTO ... SELECT`.
356- But that's boring. So let's use the `INSERT INTO ... SELECT`.
363
357
364−--
358+---
365
359
366- We will build a query that will return as constants our MP's uuid, first name and last name...
360- We will build a query that will return as constants our MP's uuid, first name and last name...
367
361
368−--
362+---
369
363
370- ... and fetch the uuid of a group given the name of the group.
364- ... and fetch the uuid of a group given the name of the group.
371
365
372−--
366+---
373
367
374- There's a `insertQuery` utility function for that. All we have to do is write the `select` !
368- There's a `insertQuery` utility function for that. All we have to do is write the `select` !
375
369
@@ -595,7 +589,7 @@ type BaseParliamentSelection =
595 , "m" ::: TableToRow MpCols ]
589 , "m" ::: TableToRow MpCols ]
596```
590```
597
591
598−- Note that we've also put everything with table aliases: "g" and "m".
592+> _note_ We've also put everything with table aliases: "g" and "m".
599
593
600---
594---
601
595