@@ -9,17 +9,13 @@ Squeal data manipulation language.
99-}
1010
1111{-# LANGUAGE
12− DataKinds
13− , DeriveDataTypeable
14− , DeriveGeneric
12+ DeriveGeneric
1513 , FlexibleContexts
1614 , GADTs
1715 , GeneralizedNewtypeDeriving
18− , KindSignatures
1916 , LambdaCase
2017 , OverloadedStrings
2118 , RankNTypes
22− , StandaloneDeriving
2319 , TypeInType
2420 , TypeOperators
2521#-}
@@ -203,32 +199,32 @@ queryStatement q = UnsafeManipulation $ renderQuery q <> ";"
203199INSERT statements
204200-----------------------------------------}
205201
206−-- | Insert multiple rows.
202+-- | Insert multiple rws.
207203--
208204-- When a table is created, it contains no data. The first thing to do
209205-- before a database can be of much use is to insert data. Data is
210−-- conceptually inserted one row at a time. Of course you can also insert
211−-- more than one row, but there is no way to insert less than one row.
212−-- Even if you know only some column values, a complete row must be created.
206+-- conceptually inserted one rw at a time. Of course you can also insert
207+-- more than one rw, but there is no way to insert less than one rw.
208+-- Even if you know only some column values, a complete rw must be created.
213209insertRows
214210 :: ( SOP.SListI columns
215211 , SOP.SListI results
216212 , Has tab schema ('Table table)
217213 , columns ~ TableToColumns table )
218214 => Alias tab -- ^ table to insert into
219− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
220− -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rows to insert
215+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
216+ -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rws to insert
221217 -> ConflictClause columns params
222218 -- ^ what to do in case of constraint conflict
223219 -> ReturningClause columns params results -- ^ results to return
224220 -> Manipulation schema params results
225−insertRows tab row rows conflict returning = UnsafeManipulation $
221+insertRows tab rw rws conflict returning = UnsafeManipulation $
226222 "INSERT" <+> "INTO" <+> renderAlias tab
227− <+> parenthesized (renderCommaSeparated renderAliasPart row)
223+ <+> parenthesized (renderCommaSeparated renderAliasPart rw)
228224 <+> "VALUES"
229225 <+> commaSeparated
230226 ( parenthesized
231− . renderCommaSeparated renderColumnValuePart <$> row:rows )
227+ . renderCommaSeparated renderColumnValuePart <$> rw:rws )
232228 <> renderConflictClause conflict
233229 <> renderReturningClause returning
234230 where
@@ -239,41 +235,41 @@ insertRows tab row rows conflict returning = UnsafeManipulation $
239235 Default -> "DEFAULT"
240236 Set expression -> renderExpression expression
241237
242−-- | Insert a single row.
238+-- | Insert a single rw.
243239insertRow
244240 :: ( SOP.SListI columns
245241 , SOP.SListI results
246242 , Has tab schema ('Table table)
247243 , columns ~ TableToColumns table )
248244 => Alias tab -- ^ table to insert into
249− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
245+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
250246 -> ConflictClause columns params
251247 -- ^ what to do in case of constraint conflict
252248 -> ReturningClause columns params results -- ^ results to return
253249 -> Manipulation schema params results
254−insertRow tab row = insertRows tab row []
250+insertRow tab rw = insertRows tab rw []
255251
256−-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
252+-- | Insert multiple rws returning `Nil` and raising an error on conflicts.
257253insertRows_
258254 :: ( SOP.SListI columns
259255 , Has tab schema ('Table table)
260256 , columns ~ TableToColumns table )
261257 => Alias tab -- ^ table to insert into
262− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
263− -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rows to insert
258+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
259+ -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rws to insert
264260 -> Manipulation schema params '[]
265−insertRows_ tab row rows =
266− insertRows tab row rows OnConflictDoRaise (Returning Nil)
261+insertRows_ tab rw rws =
262+ insertRows tab rw rws OnConflictDoRaise (Returning Nil)
267263
268−-- | Insert a single row returning `Nil` and raising an error on conflicts.
264+-- | Insert a single rw returning `Nil` and raising an error on conflicts.
269265insertRow_
270266 :: ( SOP.SListI columns
271267 , Has tab schema ('Table table)
272268 , columns ~ TableToColumns table )
273269 => Alias tab -- ^ table to insert into
274− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
270+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
275271 -> Manipulation schema params '[]
276−insertRow_ tab row = insertRow tab row OnConflictDoRaise (Returning Nil)
272+insertRow_ tab rw = insertRow tab rw OnConflictDoRaise (Returning Nil)
277273
278274-- | Insert a `Query`.
279275insertQuery
@@ -304,11 +300,11 @@ insertQuery_
304300insertQuery_ tab query =
305301 insertQuery tab query OnConflictDoRaise (Returning Nil)
306302
307−-- | `ColumnValue`s are values to insert or update in a row
303+-- | `ColumnValue`s are values to insert or update in a rw
308304-- `Same` updates with the same value.
309305-- `Default` inserts or updates with the @DEFAULT@ value
310306-- `Set` a value to be an `Expression`, relative to the given
311−-- row for an update, and closed for an insert.
307+-- rw for an update, and closed for an insert.
312308data ColumnValue
313309 (columns :: RelationType)
314310 (params :: [NullityType])
@@ -321,14 +317,14 @@ data ColumnValue
321317 -> ColumnValue columns params (constraint :=> ty)
322318
323319-- | A `ReturningClause` computes and return value(s) based
324−-- on each row actually inserted, updated or deleted. This is primarily
320+-- on each rw actually inserted, updated or deleted. This is primarily
325321-- useful for obtaining values that were supplied by defaults, such as a
326322-- serial sequence number. However, any expression using the table's columns
327−-- is allowed. Only rows that were successfully inserted or updated or
328−-- deleted will be returned. For example, if a row was locked
323+-- is allowed. Only rws that were successfully inserted or updated or
324+-- deleted will be returned. For example, if a rw was locked
329325-- but not updated because an `OnConflictDoUpdate` condition was not satisfied,
330−-- the row will not be returned. `ReturningStar` will return all columns
331−-- in the row. Use @Returning Nil@ in the common case where no return
326+-- the rw will not be returned. `ReturningStar` will return all columns
327+-- in the rw. Use @Returning Nil@ in the common case where no return
332328-- values are desired.
333329data ReturningClause
334330 (columns :: ColumnsType)
@@ -356,8 +352,8 @@ renderReturningClause = \case
356352
357353-- | A `ConflictClause` specifies an action to perform upon a constraint
358354-- violation. `OnConflictDoRaise` will raise an error.
359−-- `OnConflictDoNothing` simply avoids inserting a row.
360−-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
355+-- `OnConflictDoNothing` simply avoids inserting a rw.
356+-- `OnConflictDoUpdate` updates the existing rw that conflicts with the rw
361357-- proposed for insertion.
362358data ConflictClause (columns :: ColumnsType) params where
363359 OnConflictDoRaise :: ConflictClause columns params
@@ -397,7 +393,7 @@ UPDATE statements
397393-----------------------------------------}
398394
399395-- | An `update` command changes the values of the specified columns
400−-- in all rows that satisfy the condition.
396+-- in all rws that satisfy the condition.
401397update
402398 :: ( SOP.SListI columns
403399 , SOP.SListI results
@@ -407,7 +403,7 @@ update
407403 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
408404 -- ^ modified values to replace old values
409405 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
410− -- ^ condition under which to perform update on a row
406+ -- ^ condition under which to perform update on a rw
411407 -> ReturningClause columns params results -- ^ results to return
412408 -> Manipulation schema params results
413409update tab columns wh returning = UnsafeManipulation $
@@ -428,7 +424,7 @@ update tab columns wh returning = UnsafeManipulation $
428424 Set expression `As` column -> Just $
429425 renderAlias column <+> "=" <+> renderExpression expression
430426
431−-- | Update a row returning `Nil`.
427+-- | Update a rw returning `Nil`.
432428update_
433429 :: ( SOP.SListI columns
434430 , Has tab schema ('Table table)
@@ -437,7 +433,7 @@ update_
437433 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
438434 -- ^ modified values to replace old values
439435 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
440− -- ^ condition under which to perform update on a row
436+ -- ^ condition under which to perform update on a rw
441437 -> Manipulation schema params '[]
442438update_ tab columns wh = update tab columns wh (Returning Nil)
443439
@@ -445,14 +441,14 @@ update_ tab columns wh = update tab columns wh (Returning Nil)
445441DELETE statements
446442-----------------------------------------}
447443
448−-- | Delete rows of a table.
444+-- | Delete rws of a table.
449445deleteFrom
450446 :: ( SOP.SListI results
451447 , Has tab schema ('Table table)
452448 , columns ~ TableToColumns table )
453449 => Alias tab -- ^ table to delete from
454450 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
455− -- ^ condition under which to delete a row
451+ -- ^ condition under which to delete a rw
456452 -> ReturningClause columns params results -- ^ results to return
457453 -> Manipulation schema params results
458454deleteFrom tab wh returning = UnsafeManipulation $
@@ -460,13 +456,13 @@ deleteFrom tab wh returning = UnsafeManipulation $
460456 <+> "WHERE" <+> renderExpression wh
461457 <> renderReturningClause returning
462458
463−-- | Delete rows returning `Nil`.
459+-- | Delete rws returning `Nil`.
464460deleteFrom_
465461 :: ( Has tab schema ('Table table)
466462 , columns ~ TableToColumns table )
467463 => Alias tab -- ^ table to delete from
468464 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
469− -- ^ condition under which to delete a row
465+ -- ^ condition under which to delete a rw
470466 -> Manipulation schema params '[]
471467deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
472468
@@ -484,11 +480,11 @@ WITH statements
484480-- let
485481-- manipulation :: Manipulation '["products" ::: 'Table ProductsTable, "products_deleted" ::: 'Table ProductsTable] '[ 'NotNull 'PGdate] '[]
486482-- manipulation = with
487−-- (deleteFrom #products (#date .< param @1) ReturningStar `As` #deleted_rows :* Nil)
488−-- (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rows `As` #t)))))
483+-- (deleteFrom #products (#date .< param @1) ReturningStar `As` #deleted_rws :* Nil)
484+-- (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rws `As` #t)))))
489485-- in renderManipulation manipulation
490486-- :}
491−-- "WITH \"deleted_rows\" AS (DELETE FROM \"products\" WHERE (\"date\" < ($1 :: date)) RETURNING *) INSERT INTO \"products_deleted\" SELECT * FROM \"deleted_rows\" AS \"t\";"
487+-- "WITH \"deleted_rws\" AS (DELETE FROM \"products\" WHERE (\"date\" < ($1 :: date)) RETURNING *) INSERT INTO \"products_deleted\" SELECT * FROM \"deleted_rws\" AS \"t\";"
492488with
493489 :: SOP.SListI commons
494490 => NP (Aliased (Manipulation schema params)) commons