@@ -9,17 +9,13 @@ Squeal data manipulation language.
11{-# LANGUAGE
11{-# LANGUAGE
14− , DeriveGeneric
12+ DeriveGeneric
15 , FlexibleContexts
13 , FlexibleContexts
17 , GeneralizedNewtypeDeriving
15 , GeneralizedNewtypeDeriving
19 , LambdaCase
16 , LambdaCase
20 , OverloadedStrings
17 , OverloadedStrings
21 , RankNTypes
18 , RankNTypes
23 , TypeInType
19 , TypeInType
24 , TypeOperators
20 , TypeOperators
@@ -203,32 +199,32 @@ queryStatement q = UnsafeManipulation $ renderQuery q <> ";"
203INSERT statements
199INSERT statements
204-----------------------------------------}
200-----------------------------------------}
206−-- | Insert multiple rows.
202+-- | Insert multiple rws.
208-- When a table is created, it contains no data. The first thing to do
204-- When a table is created, it contains no data. The first thing to do
209-- before a database can be of much use is to insert data. Data is
205-- 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
206+-- conceptually inserted one rw 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.
207+-- more than one rw, but there is no way to insert less than one rw.
212−-- Even if you know only some column values, a complete row must be created.
208+-- Even if you know only some column values, a complete rw must be created.
213insertRows
209insertRows
214 :: ( SOP.SListI columns
210 :: ( SOP.SListI columns
215 , SOP.SListI results
211 , SOP.SListI results
216 , Has tab schema ('Table table)
212 , Has tab schema ('Table table)
217 , columns ~ TableToColumns table )
213 , columns ~ TableToColumns table )
218 => Alias tab -- ^ table to insert into
214 => Alias tab -- ^ table to insert into
219− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
215+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
220− -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rows to insert
216+ -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rws to insert
221 -> ConflictClause columns params
217 -> ConflictClause columns params
222 -- ^ what to do in case of constraint conflict
218 -- ^ what to do in case of constraint conflict
223 -> ReturningClause columns params results -- ^ results to return
219 -> ReturningClause columns params results -- ^ results to return
224 -> Manipulation schema params results
220 -> Manipulation schema params results
225−insertRows tab row rows conflict returning = UnsafeManipulation $
221+insertRows tab rw rws conflict returning = UnsafeManipulation $
226 "INSERT" <+> "INTO" <+> renderAlias tab
222 "INSERT" <+> "INTO" <+> renderAlias tab
227− <+> parenthesized (renderCommaSeparated renderAliasPart row)
223+ <+> parenthesized (renderCommaSeparated renderAliasPart rw)
228 <+> "VALUES"
224 <+> "VALUES"
229 <+> commaSeparated
225 <+> commaSeparated
230 ( parenthesized
226 ( parenthesized
231− . renderCommaSeparated renderColumnValuePart <$> row:rows )
227+ . renderCommaSeparated renderColumnValuePart <$> rw:rws )
232 <> renderConflictClause conflict
228 <> renderConflictClause conflict
233 <> renderReturningClause returning
229 <> renderReturningClause returning
@@ -239,41 +235,41 @@ insertRows tab row rows conflict returning = UnsafeManipulation $
239 Default -> "DEFAULT"
235 Default -> "DEFAULT"
240 Set expression -> renderExpression expression
236 Set expression -> renderExpression expression
242−-- | Insert a single row.
238+-- | Insert a single rw.
244 :: ( SOP.SListI columns
240 :: ( SOP.SListI columns
245 , SOP.SListI results
241 , SOP.SListI results
246 , Has tab schema ('Table table)
242 , Has tab schema ('Table table)
247 , columns ~ TableToColumns table )
243 , columns ~ TableToColumns table )
248 => Alias tab -- ^ table to insert into
244 => Alias tab -- ^ table to insert into
249− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
245+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
250 -> ConflictClause columns params
246 -> ConflictClause columns params
251 -- ^ what to do in case of constraint conflict
247 -- ^ what to do in case of constraint conflict
252 -> ReturningClause columns params results -- ^ results to return
248 -> ReturningClause columns params results -- ^ results to return
253 -> Manipulation schema params results
249 -> Manipulation schema params results
254−insertRow tab row = insertRows tab row []
250+insertRow tab rw = insertRows tab rw []
256−-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
252+-- | Insert multiple rws returning `Nil` and raising an error on conflicts.
257insertRows_
253insertRows_
258 :: ( SOP.SListI columns
254 :: ( SOP.SListI columns
259 , Has tab schema ('Table table)
255 , Has tab schema ('Table table)
260 , columns ~ TableToColumns table )
256 , columns ~ TableToColumns table )
261 => Alias tab -- ^ table to insert into
257 => Alias tab -- ^ table to insert into
262− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
258+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
263− -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rows to insert
259+ -> [NP (Aliased (ColumnValue '[] params)) columns] -- ^ more rws to insert
264 -> Manipulation schema params '[]
260 -> Manipulation schema params '[]
265−insertRows_ tab row rows =
261+insertRows_ tab rw rws =
266− insertRows tab row rows OnConflictDoRaise (Returning Nil)
262+ insertRows tab rw rws OnConflictDoRaise (Returning Nil)
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.
269insertRow_
265insertRow_
270 :: ( SOP.SListI columns
266 :: ( SOP.SListI columns
271 , Has tab schema ('Table table)
267 , Has tab schema ('Table table)
272 , columns ~ TableToColumns table )
268 , columns ~ TableToColumns table )
273 => Alias tab -- ^ table to insert into
269 => Alias tab -- ^ table to insert into
274− -> NP (Aliased (ColumnValue '[] params)) columns -- ^ row to insert
270+ -> NP (Aliased (ColumnValue '[] params)) columns -- ^ rw to insert
275 -> Manipulation schema params '[]
271 -> Manipulation schema params '[]
276−insertRow_ tab row = insertRow tab row OnConflictDoRaise (Returning Nil)
272+insertRow_ tab rw = insertRow tab rw OnConflictDoRaise (Returning Nil)
278-- | Insert a `Query`.
274-- | Insert a `Query`.
279insertQuery
275insertQuery
@@ -304,11 +300,11 @@ insertQuery_
304insertQuery_ tab query =
300insertQuery_ tab query =
305 insertQuery tab query OnConflictDoRaise (Returning Nil)
301 insertQuery tab query OnConflictDoRaise (Returning Nil)
307−-- | `ColumnValue`s are values to insert or update in a row
303+-- | `ColumnValue`s are values to insert or update in a rw
308-- `Same` updates with the same value.
304-- `Same` updates with the same value.
309-- `Default` inserts or updates with the @DEFAULT@ value
305-- `Default` inserts or updates with the @DEFAULT@ value
310-- `Set` a value to be an `Expression`, relative to the given
306-- `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.
312data ColumnValue
308data ColumnValue
313 (columns :: RelationType)
309 (columns :: RelationType)
314 (params :: [NullityType])
310 (params :: [NullityType])
@@ -321,14 +317,14 @@ data ColumnValue
321 -> ColumnValue columns params (constraint :=> ty)
317 -> ColumnValue columns params (constraint :=> ty)
323-- | A `ReturningClause` computes and return value(s) based
319-- | 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
325-- useful for obtaining values that were supplied by defaults, such as a
321-- useful for obtaining values that were supplied by defaults, such as a
326-- serial sequence number. However, any expression using the table's columns
322-- serial sequence number. However, any expression using the table's columns
327−-- is allowed. Only rows that were successfully inserted or updated or
323+-- is allowed. Only rws that were successfully inserted or updated or
328−-- deleted will be returned. For example, if a row was locked
324+-- deleted will be returned. For example, if a rw was locked
329-- but not updated because an `OnConflictDoUpdate` condition was not satisfied,
325-- but not updated because an `OnConflictDoUpdate` condition was not satisfied,
330−-- the row will not be returned. `ReturningStar` will return all columns
326+-- the rw will not be returned. `ReturningStar` will return all columns
331−-- in the row. Use @Returning Nil@ in the common case where no return
327+-- in the rw. Use @Returning Nil@ in the common case where no return
332-- values are desired.
328-- values are desired.
333data ReturningClause
329data ReturningClause
334 (columns :: ColumnsType)
330 (columns :: ColumnsType)
@@ -356,8 +352,8 @@ renderReturningClause = \case
357-- | A `ConflictClause` specifies an action to perform upon a constraint
353-- | A `ConflictClause` specifies an action to perform upon a constraint
358-- violation. `OnConflictDoRaise` will raise an error.
354-- violation. `OnConflictDoRaise` will raise an error.
359−-- `OnConflictDoNothing` simply avoids inserting a row.
355+-- `OnConflictDoNothing` simply avoids inserting a rw.
360−-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
356+-- `OnConflictDoUpdate` updates the existing rw that conflicts with the rw
361-- proposed for insertion.
357-- proposed for insertion.
362data ConflictClause (columns :: ColumnsType) params where
358data ConflictClause (columns :: ColumnsType) params where
363 OnConflictDoRaise :: ConflictClause columns params
359 OnConflictDoRaise :: ConflictClause columns params
@@ -397,7 +393,7 @@ UPDATE statements
397-----------------------------------------}
393-----------------------------------------}
399-- | An `update` command changes the values of the specified columns
395-- | 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.
402 :: ( SOP.SListI columns
398 :: ( SOP.SListI columns
403 , SOP.SListI results
399 , SOP.SListI results
@@ -407,7 +403,7 @@ update
407 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
403 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
408 -- ^ modified values to replace old values
404 -- ^ modified values to replace old values
409 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
405 -> 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
411 -> ReturningClause columns params results -- ^ results to return
407 -> ReturningClause columns params results -- ^ results to return
412 -> Manipulation schema params results
408 -> Manipulation schema params results
413update tab columns wh returning = UnsafeManipulation $
409update tab columns wh returning = UnsafeManipulation $
@@ -428,7 +424,7 @@ update tab columns wh returning = UnsafeManipulation $
428 Set expression `As` column -> Just $
424 Set expression `As` column -> Just $
429 renderAlias column <+> "=" <+> renderExpression expression
425 renderAlias column <+> "=" <+> renderExpression expression
431−-- | Update a row returning `Nil`.
427+-- | Update a rw returning `Nil`.
433 :: ( SOP.SListI columns
429 :: ( SOP.SListI columns
434 , Has tab schema ('Table table)
430 , Has tab schema ('Table table)
@@ -437,7 +433,7 @@ update_
437 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
433 -> NP (Aliased (ColumnValue (ColumnsToRelation columns) params)) columns
438 -- ^ modified values to replace old values
434 -- ^ modified values to replace old values
439 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
435 -> 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
441 -> Manipulation schema params '[]
437 -> Manipulation schema params '[]
442update_ tab columns wh = update tab columns wh (Returning Nil)
438update_ tab columns wh = update tab columns wh (Returning Nil)
@@ -445,14 +441,14 @@ update_ tab columns wh = update tab columns wh (Returning Nil)
445DELETE statements
441DELETE statements
446-----------------------------------------}
442-----------------------------------------}
448−-- | Delete rows of a table.
444+-- | Delete rws of a table.
449deleteFrom
445deleteFrom
450 :: ( SOP.SListI results
446 :: ( SOP.SListI results
451 , Has tab schema ('Table table)
447 , Has tab schema ('Table table)
452 , columns ~ TableToColumns table )
448 , columns ~ TableToColumns table )
453 => Alias tab -- ^ table to delete from
449 => Alias tab -- ^ table to delete from
454 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
450 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
455− -- ^ condition under which to delete a row
451+ -- ^ condition under which to delete a rw
456 -> ReturningClause columns params results -- ^ results to return
452 -> ReturningClause columns params results -- ^ results to return
457 -> Manipulation schema params results
453 -> Manipulation schema params results
458deleteFrom tab wh returning = UnsafeManipulation $
454deleteFrom tab wh returning = UnsafeManipulation $
@@ -460,13 +456,13 @@ deleteFrom tab wh returning = UnsafeManipulation $
460 <+> "WHERE" <+> renderExpression wh
456 <+> "WHERE" <+> renderExpression wh
461 <> renderReturningClause returning
457 <> renderReturningClause returning
463−-- | Delete rows returning `Nil`.
459+-- | Delete rws returning `Nil`.
464deleteFrom_
460deleteFrom_
465 :: ( Has tab schema ('Table table)
461 :: ( Has tab schema ('Table table)
466 , columns ~ TableToColumns table )
462 , columns ~ TableToColumns table )
467 => Alias tab -- ^ table to delete from
463 => Alias tab -- ^ table to delete from
468 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
464 -> Condition '[tab ::: ColumnsToRelation columns] 'Ungrouped params
469− -- ^ condition under which to delete a row
465+ -- ^ condition under which to delete a rw
470 -> Manipulation schema params '[]
466 -> Manipulation schema params '[]
471deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
467deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
@@ -484,11 +480,11 @@ WITH statements
485-- manipulation :: Manipulation '["products" ::: 'Table ProductsTable, "products_deleted" ::: 'Table ProductsTable] '[ 'NotNull 'PGdate] '[]
481-- manipulation :: Manipulation '["products" ::: 'Table ProductsTable, "products_deleted" ::: 'Table ProductsTable] '[ 'NotNull 'PGdate] '[]
486-- manipulation = with
482-- manipulation = with
487−-- (deleteFrom #products (#date .< param @1) ReturningStar `As` #deleted_rows :* Nil)
483+-- (deleteFrom #products (#date .< param @1) ReturningStar `As` #deleted_rws :* Nil)
488−-- (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rows `As` #t)))))
484+-- (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rws `As` #t)))))
489-- in renderManipulation manipulation
485-- in renderManipulation manipulation
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\";"
493 :: SOP.SListI commons
489 :: SOP.SListI commons
494 => NP (Aliased (Manipulation schema params)) commons
490 => NP (Aliased (Manipulation schema params)) commons