on dev help sign in
Update squeal-presentation-2018-09-12.md
commit94323023a63d52def1567774edd326a111e0f9a1 authorEitan Chatav <eitan.chatav@gmail.com> dateTue 4 Dec 2018, 09:18 (8 years ago) parentcef72e1
1 file changed+29−35
squeal-presentation-2018-09-12.md+29−35
squeal-presentation-2018-09-12.md+29−35
@@ -63,16 +63,13 @@ type Schema = '[ "mp" ::: 'Table MemberOfParliament
6363 , "groupp" ::: 'Table ParliamentGroup ]
6464```
6565
66−--
66+---
6767
68−.note[*
69−We need the `DataKinds` extension to be able to express heterogenous lists containing
70−specific types like this one.
68+> _note_ We need the `DataKinds` extension to be able to express heterogenous lists containing
69+> specific types like this one.
7170
72−*
73−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.
75−]
71+> You can perfectly call your table "group" and not "groupp" even though it is a
72+> keyword in SQL - Squeal queries will be properly escaped.
7673
7774---
7875
@@ -95,11 +92,10 @@ type ParliamentaryGroup =
9592
9693- Let's split constraints and column to study the syntax a bit more.
9794
98−--
95+---
9996
100−.note[*
101−We are using `:::` and `:=>` to quickly express associations when writing
102−our schema. We need the `TypeOperators` extension.]
97+> _note_ We are using `:::` and `:=>` to quickly express associations when writing
98+> our schema. We need the `TypeOperators` extension.]
10399
104100---
105101
@@ -148,10 +144,10 @@ type MpCols =
148144
149145 * the type (obviously).
150146
151−--
147+---
152148
153−.note[*
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.]
149+> _note_ GHC is already helping. If I named the "mp_id" column differently,
150+> GHC would yell because I promised a primary key constraint on a column named `mp_id`, so there must be one.]
155151
156152---
157153
@@ -161,7 +157,7 @@ GHC is already helping. If I named the "mp_id" column differently, GHC would yel
161157
162158- But before we play with this schema, we need to implement it.
163159
164−--
160+---
165161
166162```haskell
167163setup :: Definition '[] Schema
@@ -193,15 +189,14 @@ setup =
193189
194190- You use `>>>` to compose table creation.
195191
196−- Note that the compiler will catch any mistype between Schema and
197−definition; wrong nullability, wrong type, wrong name, etc.
192+> _note_ The compiler will catch any mistype between Schema and
193+> definition; wrong nullability, wrong type, wrong name, etc.
198194
199−--
195+---
200196
201−.note[*
202−You'll also need `OverloadedLabels`, for naming stuff.
203−This is mostly to avoid having to write manual proxies all
204−the time and for convenience.]
197+> _note_ You'll also need `OverloadedLabels`, for naming stuff.
198+> This is mostly to avoid having to write manual proxies all
199+> the time and for convenience.
205200
206201---
207202
@@ -236,8 +231,8 @@ tearDown :: Definition Schema '[]
236231tearDown = dropTable #mp >>> dropTable #groupp
237232```
238233
239−- Note that GHC will also detect the _proper_ order of what you typed in
240− downgrade and upgrade should there be any conflict (with foreign keys).
234+> _note_ GHC will also detect the _proper_ order of what you typed in
235+> downgrade and upgrade should there be any conflict (with foreign keys).
241236
242237```haskell
243238initDB :: Migration IO '[] Schema
@@ -316,9 +311,8 @@ data MemberOfParliament =
316311 , lastName :: Text }
317312```
318313
319−- You'll note that we didn't use anything from Squeal.
320−
321−- The model can be entirely separated from the persistence layer.
314+> _note_ We didn't use anything from Squeal.
315+> The model can be entirely separated from the persistence layer.
322316
323317---
324318
@@ -333,7 +327,7 @@ type GroupInsertionParams = '[ 'NotNull 'PGuuid
333327
334328- Params are not named, but they are indexed. You just need nullability and type.
335329
336−--
330+---
337331
338332```haskell
339333groupInsertion :: Manipulation Schema GroupInsertionParams '[]
@@ -342,7 +336,7 @@ groupInsertion =
342336 :* Set (param @2) `as` #name )
343337```
344338
345−--
339+---
346340
347341- `TypeApplication` lets us use the index of parameters (counting from 1).
348342
@@ -357,19 +351,19 @@ _Inserting a Member of Parliament_
357351
358352- We could create a naive query that takes MP uuid, first name, last name and group uuid...
359353
360−--
354+---
361355
362356- But that's boring. So let's use the `INSERT INTO ... SELECT`.
363357
364−--
358+---
365359
366360- We will build a query that will return as constants our MP's uuid, first name and last name...
367361
368−--
362+---
369363
370364- ... and fetch the uuid of a group given the name of the group.
371365
372−--
366+---
373367
374368- There's a `insertQuery` utility function for that. All we have to do is write the `select` !
375369
@@ -595,7 +589,7 @@ type BaseParliamentSelection =
595589 , "m" ::: TableToRow MpCols ]
596590```
597591
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".
599593
600594---
601595