on dev help sign in
tables ~> relations
fe669faEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+184−184
@@ -198,7 +198,7 @@ class (PGTyped (PGTypeOf ty), KnownNat n) => HasParameter
198 (params :: [NullityType])
198 (params :: [NullityType])
199 (ty :: NullityType)
199 (ty :: NullityType)
200 | n params -> ty where
200 | n params -> ty where
201− param :: Expression tables grouping params ty
201+ param :: Expression relations grouping params ty
202 param = UnsafeExpression $ parenthesized $
202 param = UnsafeExpression $ parenthesized $
203 "$" <> renderNat (Proxy @n) <+> "::"
203 "$" <> renderNat (Proxy @n) <+> "::"
204 <+> renderTypeExpression (pgtype @(PGTypeOf ty))
204 <+> renderTypeExpression (pgtype @(PGTypeOf ty))
@@ -207,61 +207,61 @@ instance {-# OVERLAPPING #-} PGTyped (PGTypeOf ty1)
207instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
207instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
208 => HasParameter n (ty' : params) ty
208 => HasParameter n (ty' : params) ty
209
209
210−instance (HasUnique table tables columns, Has column columns ty)
210+instance (HasUnique relation relations columns, Has column columns ty)
211− => IsLabel column (Expression tables 'Ungrouped params ty) where
211+ => IsLabel column (Expression relations 'Ungrouped params ty) where
212 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
212 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
213
213
214−instance (Has table tables columns, Has column columns ty)
214+instance (Has relation relations columns, Has column columns ty)
215− => IsTableColumn table column (Expression tables 'Ungrouped params ty) where
215+ => IsTableColumn relation column (Expression relations 'Ungrouped params ty) where
216− table ! column = UnsafeExpression $
216+ relation ! column = UnsafeExpression $
217− renderAlias table <> "." <> renderAlias column
217+ renderAlias relation <> "." <> renderAlias column
218
218
219{- | A `GroupedBy` constraint indicates that a table qualified column is
219{- | A `GroupedBy` constraint indicates that a table qualified column is
220a member of the auxiliary namespace created by @GROUP BY@ clauses and thus,
220a member of the auxiliary namespace created by @GROUP BY@ clauses and thus,
221may be called in an output `Expression` without aggregating.
221may be called in an output `Expression` without aggregating.
222-}
222-}
223−class (KnownSymbol table, KnownSymbol column)
223+class (KnownSymbol relation, KnownSymbol column)
224− => GroupedBy table column bys where
224+ => GroupedBy relation column bys where
225 getGroup1
225 getGroup1
226− :: (HasUnique table tables columns, Has column columns ty)
226+ :: (HasUnique relation relations columns, Has column columns ty)
227 => Alias column
227 => Alias column
228− -> Expression tables ('Grouped bys) params ty
228+ -> Expression relations ('Grouped bys) params ty
229 getGroup1 column = UnsafeExpression $ renderAlias column
229 getGroup1 column = UnsafeExpression $ renderAlias column
230 getGroup2
230 getGroup2
231− :: (Has table tables columns, Has column columns ty)
231+ :: (Has relation relations columns, Has column columns ty)
232− => Alias table
232+ => Alias relation
233 -> Alias column
233 -> Alias column
234− -> Expression tables ('Grouped bys) params ty
234+ -> Expression relations ('Grouped bys) params ty
235− getGroup2 table column = UnsafeExpression $
235+ getGroup2 relation column = UnsafeExpression $
236− renderAlias table <> "." <> renderAlias column
236+ renderAlias relation <> "." <> renderAlias column
237−instance {-# OVERLAPPING #-} (KnownSymbol table, KnownSymbol column)
237+instance {-# OVERLAPPING #-} (KnownSymbol relation, KnownSymbol column)
238− => GroupedBy table column ('(table,column) ': bys)
238+ => GroupedBy relation column ('(table,column) ': bys)
239instance {-# OVERLAPPABLE #-}
239instance {-# OVERLAPPABLE #-}
240− ( KnownSymbol table
240+ ( KnownSymbol relation
241 , KnownSymbol column
241 , KnownSymbol column
242− , GroupedBy table column bys
242+ , GroupedBy relation column bys
243− ) => GroupedBy table column (tabcol ': bys)
243+ ) => GroupedBy relation column (tabcol ': bys)
244
244
245instance
245instance
246− ( HasUnique table tables columns
246+ ( HasUnique relation relations columns
247 , Has column columns ty
247 , Has column columns ty
248− , GroupedBy table column bys
248+ , GroupedBy relation column bys
249 ) => IsLabel column
249 ) => IsLabel column
250− (Expression tables ('Grouped bys) params ty) where
250+ (Expression relations ('Grouped bys) params ty) where
251 fromLabel = getGroup1 (Alias @column)
251 fromLabel = getGroup1 (Alias @column)
252
252
253instance
253instance
254− ( Has table tables columns
254+ ( Has relation relations columns
255 , Has column columns ty
255 , Has column columns ty
256− , GroupedBy table column bys
256+ , GroupedBy relation column bys
257− ) => IsTableColumn table column
257+ ) => IsTableColumn relation column
258− (Expression tables ('Grouped bys) params ty) where (!) = getGroup2
258+ (Expression relations ('Grouped bys) params ty) where (!) = getGroup2
259
259
260-- | analagous to `Nothing`
260-- | analagous to `Nothing`
261--
261--
262-- >>> renderExpression $ null_
262-- >>> renderExpression $ null_
263-- "NULL"
263-- "NULL"
264−null_ :: Expression tables grouping params ('Null ty)
264+null_ :: Expression relations grouping params ('Null ty)
265null_ = UnsafeExpression "NULL"
265null_ = UnsafeExpression "NULL"
266
266
267-- | analagous to `Just`
267-- | analagous to `Just`
@@ -269,9 +269,9 @@ null_ = UnsafeExpression "NULL"
269-- >>> renderExpression $ unNull true
269-- >>> renderExpression $ unNull true
270-- "TRUE"
270-- "TRUE"
271unNull
271unNull
272− :: Expression tables grouping params ('NotNull ty)
272+ :: Expression relations grouping params ('NotNull ty)
273 -- ^ not @NULL@
273 -- ^ not @NULL@
274− -> Expression tables grouping params ('Null ty)
274+ -> Expression relations grouping params ('Null ty)
275unNull = UnsafeExpression . renderExpression
275unNull = UnsafeExpression . renderExpression
276
276
277-- | return the leftmost value which is not NULL
277-- | return the leftmost value which is not NULL
@@ -279,11 +279,11 @@ unNull = UnsafeExpression . renderExpression
279-- >>> renderExpression $ coalesce [null_, unNull true] false
279-- >>> renderExpression $ coalesce [null_, unNull true] false
280-- "COALESCE(NULL, TRUE, FALSE)"
280-- "COALESCE(NULL, TRUE, FALSE)"
281coalesce
281coalesce
282− :: [Expression tables grouping params ('Null ty)]
282+ :: [Expression relations grouping params ('Null ty)]
283 -- ^ @NULL@s may be present
283 -- ^ @NULL@s may be present
284− -> Expression tables grouping params ('NotNull ty)
284+ -> Expression relations grouping params ('NotNull ty)
285 -- ^ @NULL@ is absent
285 -- ^ @NULL@ is absent
286− -> Expression tables grouping params ('NotNull ty)
286+ -> Expression relations grouping params ('NotNull ty)
287coalesce nullxs notNullx = UnsafeExpression $
287coalesce nullxs notNullx = UnsafeExpression $
288 "COALESCE" <> parenthesized (commaSeparated
288 "COALESCE" <> parenthesized (commaSeparated
289 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
289 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -293,26 +293,26 @@ coalesce nullxs notNullx = UnsafeExpression $
293-- >>> renderExpression $ fromNull true null_
293-- >>> renderExpression $ fromNull true null_
294-- "COALESCE(NULL, TRUE)"
294-- "COALESCE(NULL, TRUE)"
295fromNull
295fromNull
296− :: Expression tables grouping params ('NotNull ty)
296+ :: Expression relations grouping params ('NotNull ty)
297 -- ^ what to convert @NULL@ to
297 -- ^ what to convert @NULL@ to
298− -> Expression tables grouping params ('Null ty)
298+ -> Expression relations grouping params ('Null ty)
299− -> Expression tables grouping params ('NotNull ty)
299+ -> Expression relations grouping params ('NotNull ty)
300fromNull notNullx nullx = coalesce [nullx] notNullx
300fromNull notNullx nullx = coalesce [nullx] notNullx
301
301
302-- | >>> renderExpression $ null_ & isNull
302-- | >>> renderExpression $ null_ & isNull
303-- "NULL IS NULL"
303-- "NULL IS NULL"
304isNull
304isNull
305− :: Expression tables grouping params ('Null ty)
305+ :: Expression relations grouping params ('Null ty)
306 -- ^ possibly @NULL@
306 -- ^ possibly @NULL@
307− -> Condition tables grouping params
307+ -> Condition relations grouping params
308isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
308isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
309
309
310-- | >>> renderExpression $ null_ & isn'tNull
310-- | >>> renderExpression $ null_ & isn'tNull
311-- "NULL IS NOT NULL"
311-- "NULL IS NOT NULL"
312isn'tNull
312isn'tNull
313− :: Expression tables grouping params ('Null ty)
313+ :: Expression relations grouping params ('Null ty)
314 -- ^ possibly @NULL@
314 -- ^ possibly @NULL@
315− -> Condition tables grouping params
315+ -> Condition relations grouping params
316isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
316isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
317
317
318-- | analagous to `maybe` using @IS NULL@
318-- | analagous to `maybe` using @IS NULL@
@@ -320,13 +320,13 @@ isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
320-- >>> renderExpression $ matchNull true not_ null_
320-- >>> renderExpression $ matchNull true not_ null_
321-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
321-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
322matchNull
322matchNull
323− :: Expression tables grouping params (nullty)
323+ :: Expression relations grouping params (nullty)
324 -- ^ what to convert @NULL@ to
324 -- ^ what to convert @NULL@ to
325− -> ( Expression tables grouping params ('NotNull ty)
325+ -> ( Expression relations grouping params ('NotNull ty)
326− -> Expression tables grouping params (nullty) )
326+ -> Expression relations grouping params (nullty) )
327 -- ^ function to perform when @NULL@ is absent
327 -- ^ function to perform when @NULL@ is absent
328− -> Expression tables grouping params ('Null ty)
328+ -> Expression relations grouping params ('Null ty)
329− -> Expression tables grouping params (nullty)
329+ -> Expression relations grouping params (nullty)
330matchNull y f x = ifThenElse (isNull x) y
330matchNull y f x = ifThenElse (isNull x) y
331 (f (UnsafeExpression (renderExpression x)))
331 (f (UnsafeExpression (renderExpression x)))
332
332
@@ -337,47 +337,47 @@ matchNull y f x = ifThenElse (isNull x) y
337-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
337-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
338-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
338-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
339nullIf
339nullIf
340− :: Expression tables grouping params ('NotNull ty)
340+ :: Expression relations grouping params ('NotNull ty)
341 -- ^ @NULL@ is absent
341 -- ^ @NULL@ is absent
342− -> Expression tables grouping params ('NotNull ty)
342+ -> Expression relations grouping params ('NotNull ty)
343 -- ^ @NULL@ is absent
343 -- ^ @NULL@ is absent
344− -> Expression tables grouping params ('Null ty)
344+ -> Expression relations grouping params ('Null ty)
345nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
345nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
346 (renderExpression x <> ", " <> renderExpression y)
346 (renderExpression x <> ", " <> renderExpression y)
347
347
348-- | >>> renderExpression $ array [null_, unNull false, unNull true]
348-- | >>> renderExpression $ array [null_, unNull false, unNull true]
349-- "ARRAY[NULL, FALSE, TRUE]"
349-- "ARRAY[NULL, FALSE, TRUE]"
350array
350array
351− :: [Expression tables grouping params ('Null ty)]
351+ :: [Expression relations grouping params ('Null ty)]
352 -- ^ array elements
352 -- ^ array elements
353− -> Expression tables grouping params (nullity ('PGvararray ty))
353+ -> Expression relations grouping params (nullity ('PGvararray ty))
354array xs = UnsafeExpression $
354array xs = UnsafeExpression $
355 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
355 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
356
356
357instance Monoid
357instance Monoid
358− (Expression tables grouping params (nullity ('PGvararray ty))) where
358+ (Expression relations grouping params (nullity ('PGvararray ty))) where
359 mempty = array []
359 mempty = array []
360 mappend = unsafeBinaryOp "||"
360 mappend = unsafeBinaryOp "||"
361
361
362-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
362-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
363-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
363-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
364greatest
364greatest
365− :: Expression tables grouping params (nullty)
365+ :: Expression relations grouping params (nullty)
366 -- ^ needs at least 1 argument
366 -- ^ needs at least 1 argument
367− -> [Expression tables grouping params (nullty)]
367+ -> [Expression relations grouping params (nullty)]
368 -- ^ or more
368 -- ^ or more
369− -> Expression tables grouping params (nullty)
369+ -> Expression relations grouping params (nullty)
370greatest x xs = UnsafeExpression $ "GREATEST("
370greatest x xs = UnsafeExpression $ "GREATEST("
371 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
371 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
372
372
373-- | >>> renderExpression $ least currentTimestamp [null_]
373-- | >>> renderExpression $ least currentTimestamp [null_]
374-- "LEAST(CURRENT_TIMESTAMP, NULL)"
374-- "LEAST(CURRENT_TIMESTAMP, NULL)"
375least
375least
376− :: Expression tables grouping params (nullty)
376+ :: Expression relations grouping params (nullty)
377 -- ^ needs at least 1 argument
377 -- ^ needs at least 1 argument
378− -> [Expression tables grouping params (nullty)]
378+ -> [Expression relations grouping params (nullty)]
379 -- ^ or more
379 -- ^ or more
380− -> Expression tables grouping params (nullty)
380+ -> Expression relations grouping params (nullty)
381least x xs = UnsafeExpression $ "LEAST("
381least x xs = UnsafeExpression $ "LEAST("
382 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
382 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
383
383
@@ -386,9 +386,9 @@ least x xs = UnsafeExpression $ "LEAST("
386unsafeBinaryOp
386unsafeBinaryOp
387 :: ByteString
387 :: ByteString
388 -- ^ operator
388 -- ^ operator
389− -> Expression tables grouping params (ty0)
389+ -> Expression relations grouping params (ty0)
390− -> Expression tables grouping params (ty1)
390+ -> Expression relations grouping params (ty1)
391− -> Expression tables grouping params (ty2)
391+ -> Expression relations grouping params (ty2)
392unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
392unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
393 renderExpression x <+> op <+> renderExpression y
393 renderExpression x <+> op <+> renderExpression y
394
394
@@ -397,8 +397,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
397unsafeUnaryOp
397unsafeUnaryOp
398 :: ByteString
398 :: ByteString
399 -- ^ operator
399 -- ^ operator
400− -> Expression tables grouping params (ty0)
400+ -> Expression relations grouping params (ty0)
401− -> Expression tables grouping params (ty1)
401+ -> Expression relations grouping params (ty1)
402unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
402unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
403 op <+> renderExpression x
403 op <+> renderExpression x
404
404
@@ -407,13 +407,13 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
407unsafeFunction
407unsafeFunction
408 :: ByteString
408 :: ByteString
409 -- ^ function
409 -- ^ function
410− -> Expression tables grouping params (xty)
410+ -> Expression relations grouping params (xty)
411− -> Expression tables grouping params (yty)
411+ -> Expression relations grouping params (yty)
412unsafeFunction fun x = UnsafeExpression $
412unsafeFunction fun x = UnsafeExpression $
413 fun <> parenthesized (renderExpression x)
413 fun <> parenthesized (renderExpression x)
414
414
415instance PGNum ty
415instance PGNum ty
416− => Num (Expression tables grouping params (nullity ty)) where
416+ => Num (Expression relations grouping params (nullity ty)) where
417 (+) = unsafeBinaryOp "+"
417 (+) = unsafeBinaryOp "+"
418 (-) = unsafeBinaryOp "-"
418 (-) = unsafeBinaryOp "-"
419 (*) = unsafeBinaryOp "*"
419 (*) = unsafeBinaryOp "*"
@@ -425,12 +425,12 @@ instance PGNum ty
425 . show
425 . show
426
426
427instance (PGNum ty, PGFloating ty) => Fractional
427instance (PGNum ty, PGFloating ty) => Fractional
428− (Expression tables grouping params (nullity ty)) where
428+ (Expression relations grouping params (nullity ty)) where
429 (/) = unsafeBinaryOp "/"
429 (/) = unsafeBinaryOp "/"
430 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
430 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
431
431
432instance (PGNum ty, PGFloating ty) => Floating
432instance (PGNum ty, PGFloating ty) => Floating
433− (Expression tables grouping params (nullity ty)) where
433+ (Expression relations grouping params (nullity ty)) where
434 pi = UnsafeExpression "pi()"
434 pi = UnsafeExpression "pi()"
435 exp = unsafeFunction "exp"
435 exp = unsafeFunction "exp"
436 log = unsafeFunction "ln"
436 log = unsafeFunction "ln"
@@ -453,18 +453,18 @@ instance (PGNum ty, PGFloating ty) => Floating
453
453
454-- | >>> :{
454-- | >>> :{
455-- let
455-- let
456−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
456+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
457-- expression = atan2_ pi 2
457-- expression = atan2_ pi 2
458-- in renderExpression expression
458-- in renderExpression expression
459-- :}
459-- :}
460-- "atan2(pi(), 2)"
460-- "atan2(pi(), 2)"
461atan2_
461atan2_
462 :: PGFloating float
462 :: PGFloating float
463− => Expression tables grouping params (nullity float)
463+ => Expression relations grouping params (nullity float)
464 -- ^ numerator
464 -- ^ numerator
465− -> Expression tables grouping params (nullity float)
465+ -> Expression relations grouping params (nullity float)
466 -- ^ denominator
466 -- ^ denominator
467− -> Expression tables grouping params (nullity float)
467+ -> Expression relations grouping params (nullity float)
468atan2_ y x = UnsafeExpression $
468atan2_ y x = UnsafeExpression $
469 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
469 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
470
470
@@ -477,9 +477,9 @@ atan2_ y x = UnsafeExpression $
477cast
477cast
478 :: TypeExpression ('NoDef :=> 'Null ty1)
478 :: TypeExpression ('NoDef :=> 'Null ty1)
479 -- ^ type to cast as
479 -- ^ type to cast as
480− -> Expression tables grouping params (nullity ty0)
480+ -> Expression relations grouping params (nullity ty0)
481 -- ^ value to convert
481 -- ^ value to convert
482− -> Expression tables grouping params (nullity ty1)
482+ -> Expression relations grouping params (nullity ty1)
483cast ty x = UnsafeExpression $ parenthesized $
483cast ty x = UnsafeExpression $ parenthesized $
484 renderExpression x <+> "::" <+> renderTypeExpression ty
484 renderExpression x <+> "::" <+> renderTypeExpression ty
485
485
@@ -487,133 +487,133 @@ cast ty x = UnsafeExpression $ parenthesized $
487--
487--
488-- >>> :{
488-- >>> :{
489-- let
489-- let
490−-- expression :: Expression tables grouping params (nullity 'PGint2)
490+-- expression :: Expression relations grouping params (nullity 'PGint2)
491-- expression = 5 `quot_` 2
491-- expression = 5 `quot_` 2
492-- in renderExpression expression
492-- in renderExpression expression
493-- :}
493-- :}
494-- "(5 / 2)"
494-- "(5 / 2)"
495quot_
495quot_
496 :: PGIntegral int
496 :: PGIntegral int
497− => Expression tables grouping params (nullity int)
497+ => Expression relations grouping params (nullity int)
498 -- ^ numerator
498 -- ^ numerator
499− -> Expression tables grouping params (nullity int)
499+ -> Expression relations grouping params (nullity int)
500 -- ^ denominator
500 -- ^ denominator
501− -> Expression tables grouping params (nullity int)
501+ -> Expression relations grouping params (nullity int)
502quot_ = unsafeBinaryOp "/"
502quot_ = unsafeBinaryOp "/"
503
503
504-- | remainder upon integer division
504-- | remainder upon integer division
505--
505--
506-- >>> :{
506-- >>> :{
507-- let
507-- let
508−-- expression :: Expression tables grouping params (nullity 'PGint2)
508+-- expression :: Expression relations grouping params (nullity 'PGint2)
509-- expression = 5 `rem_` 2
509-- expression = 5 `rem_` 2
510-- in renderExpression expression
510-- in renderExpression expression
511-- :}
511-- :}
512-- "(5 % 2)"
512-- "(5 % 2)"
513rem_
513rem_
514 :: PGIntegral int
514 :: PGIntegral int
515− => Expression tables grouping params (nullity int)
515+ => Expression relations grouping params (nullity int)
516 -- ^ numerator
516 -- ^ numerator
517− -> Expression tables grouping params (nullity int)
517+ -> Expression relations grouping params (nullity int)
518 -- ^ denominator
518 -- ^ denominator
519− -> Expression tables grouping params (nullity int)
519+ -> Expression relations grouping params (nullity int)
520rem_ = unsafeBinaryOp "%"
520rem_ = unsafeBinaryOp "%"
521
521
522-- | >>> :{
522-- | >>> :{
523-- let
523-- let
524−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
524+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
525-- expression = trunc pi
525-- expression = trunc pi
526-- in renderExpression expression
526-- in renderExpression expression
527-- :}
527-- :}
528-- "trunc(pi())"
528-- "trunc(pi())"
529trunc
529trunc
530 :: PGFloating frac
530 :: PGFloating frac
531− => Expression tables grouping params (nullity frac)
531+ => Expression relations grouping params (nullity frac)
532 -- ^ fractional number
532 -- ^ fractional number
533− -> Expression tables grouping params (nullity frac)
533+ -> Expression relations grouping params (nullity frac)
534trunc = unsafeFunction "trunc"
534trunc = unsafeFunction "trunc"
535
535
536-- | >>> :{
536-- | >>> :{
537-- let
537-- let
538−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
538+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
539-- expression = round_ pi
539-- expression = round_ pi
540-- in renderExpression expression
540-- in renderExpression expression
541-- :}
541-- :}
542-- "round(pi())"
542-- "round(pi())"
543round_
543round_
544 :: PGFloating frac
544 :: PGFloating frac
545− => Expression tables grouping params (nullity frac)
545+ => Expression relations grouping params (nullity frac)
546 -- ^ fractional number
546 -- ^ fractional number
547− -> Expression tables grouping params (nullity frac)
547+ -> Expression relations grouping params (nullity frac)
548round_ = unsafeFunction "round"
548round_ = unsafeFunction "round"
549
549
550-- | >>> :{
550-- | >>> :{
551-- let
551-- let
552−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
552+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
553-- expression = ceiling_ pi
553-- expression = ceiling_ pi
554-- in renderExpression expression
554-- in renderExpression expression
555-- :}
555-- :}
556-- "ceiling(pi())"
556-- "ceiling(pi())"
557ceiling_
557ceiling_
558 :: PGFloating frac
558 :: PGFloating frac
559− => Expression tables grouping params (nullity frac)
559+ => Expression relations grouping params (nullity frac)
560 -- ^ fractional number
560 -- ^ fractional number
561− -> Expression tables grouping params (nullity frac)
561+ -> Expression relations grouping params (nullity frac)
562ceiling_ = unsafeFunction "ceiling"
562ceiling_ = unsafeFunction "ceiling"
563
563
564-- | A `Condition` is a boolean valued `Expression`. While SQL allows
564-- | A `Condition` is a boolean valued `Expression`. While SQL allows
565-- conditions to have @NULL@, squeal instead chooses to disallow @NULL@,
565-- conditions to have @NULL@, squeal instead chooses to disallow @NULL@,
566-- forcing one to handle the case of @NULL@ explicitly to produce
566-- forcing one to handle the case of @NULL@ explicitly to produce
567-- a `Condition`.
567-- a `Condition`.
568−type Condition tables grouping params =
568+type Condition relations grouping params =
569− Expression tables grouping params ('NotNull 'PGbool)
569+ Expression relations grouping params ('NotNull 'PGbool)
570
570
571-- | >>> renderExpression true
571-- | >>> renderExpression true
572-- "TRUE"
572-- "TRUE"
573−true :: Condition tables grouping params
573+true :: Condition relations grouping params
574true = UnsafeExpression "TRUE"
574true = UnsafeExpression "TRUE"
575
575
576-- | >>> renderExpression false
576-- | >>> renderExpression false
577-- "FALSE"
577-- "FALSE"
578−false :: Condition tables grouping params
578+false :: Condition relations grouping params
579false = UnsafeExpression "FALSE"
579false = UnsafeExpression "FALSE"
580
580
581-- | >>> renderExpression $ not_ true
581-- | >>> renderExpression $ not_ true
582-- "(NOT TRUE)"
582-- "(NOT TRUE)"
583not_
583not_
584− :: Condition tables grouping params
584+ :: Condition relations grouping params
585− -> Condition tables grouping params
585+ -> Condition relations grouping params
586not_ = unsafeUnaryOp "NOT"
586not_ = unsafeUnaryOp "NOT"
587
587
588-- | >>> renderExpression $ true .&& false
588-- | >>> renderExpression $ true .&& false
589-- "(TRUE AND FALSE)"
589-- "(TRUE AND FALSE)"
590(.&&)
590(.&&)
591− :: Condition tables grouping params
591+ :: Condition relations grouping params
592− -> Condition tables grouping params
592+ -> Condition relations grouping params
593− -> Condition tables grouping params
593+ -> Condition relations grouping params
594(.&&) = unsafeBinaryOp "AND"
594(.&&) = unsafeBinaryOp "AND"
595
595
596-- | >>> renderExpression $ true .|| false
596-- | >>> renderExpression $ true .|| false
597-- "(TRUE OR FALSE)"
597-- "(TRUE OR FALSE)"
598(.||)
598(.||)
599− :: Condition tables grouping params
599+ :: Condition relations grouping params
600− -> Condition tables grouping params
600+ -> Condition relations grouping params
601− -> Condition tables grouping params
601+ -> Condition relations grouping params
602(.||) = unsafeBinaryOp "OR"
602(.||) = unsafeBinaryOp "OR"
603
603
604-- | >>> :{
604-- | >>> :{
605-- let
605-- let
606−-- expression :: Expression tables grouping params (nullity 'PGint2)
606+-- expression :: Expression relations grouping params (nullity 'PGint2)
607-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
607-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
608-- in renderExpression expression
608-- in renderExpression expression
609-- :}
609-- :}
610-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
610-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
611caseWhenThenElse
611caseWhenThenElse
612− :: [ ( Condition tables grouping params
612+ :: [ ( Condition relations grouping params
613− , Expression tables grouping params (ty)
613+ , Expression relations grouping params (ty)
614 ) ]
614 ) ]
615− -> Expression tables grouping params (ty)
615+ -> Expression relations grouping params (ty)
616− -> Expression tables grouping params (ty)
616+ -> Expression relations grouping params (ty)
617caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
617caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
618 [ "CASE"
618 [ "CASE"
619 , mconcat
619 , mconcat
@@ -629,16 +629,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
629
629
630-- | >>> :{
630-- | >>> :{
631-- let
631-- let
632−-- expression :: Expression tables grouping params (nullity 'PGint2)
632+-- expression :: Expression relations grouping params (nullity 'PGint2)
633-- expression = ifThenElse true 1 0
633-- expression = ifThenElse true 1 0
634-- in renderExpression expression
634-- in renderExpression expression
635-- :}
635-- :}
636-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
636-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
637ifThenElse
637ifThenElse
638− :: Condition tables grouping params
638+ :: Condition relations grouping params
639− -> Expression tables grouping params (ty)
639+ -> Expression relations grouping params (ty)
640− -> Expression tables grouping params (ty)
640+ -> Expression relations grouping params (ty)
641− -> Expression tables grouping params (ty)
641+ -> Expression relations grouping params (ty)
642ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
642ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
643
643
644-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
644-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -647,85 +647,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
647-- >>> renderExpression $ unNull true .== null_
647-- >>> renderExpression $ unNull true .== null_
648-- "(TRUE = NULL)"
648-- "(TRUE = NULL)"
649(.==)
649(.==)
650− :: Expression tables grouping params (nullity ty) -- ^ lhs
650+ :: Expression relations grouping params (nullity ty) -- ^ lhs
651− -> Expression tables grouping params (nullity ty) -- ^ rhs
651+ -> Expression relations grouping params (nullity ty) -- ^ rhs
652− -> Expression tables grouping params (nullity 'PGbool)
652+ -> Expression relations grouping params (nullity 'PGbool)
653(.==) = unsafeBinaryOp "="
653(.==) = unsafeBinaryOp "="
654infix 4 .==
654infix 4 .==
655
655
656-- | >>> renderExpression $ unNull true ./= null_
656-- | >>> renderExpression $ unNull true ./= null_
657-- "(TRUE <> NULL)"
657-- "(TRUE <> NULL)"
658(./=)
658(./=)
659− :: Expression tables grouping params (nullity ty) -- ^ lhs
659+ :: Expression relations grouping params (nullity ty) -- ^ lhs
660− -> Expression tables grouping params (nullity ty) -- ^ rhs
660+ -> Expression relations grouping params (nullity ty) -- ^ rhs
661− -> Expression tables grouping params (nullity 'PGbool)
661+ -> Expression relations grouping params (nullity 'PGbool)
662(./=) = unsafeBinaryOp "<>"
662(./=) = unsafeBinaryOp "<>"
663infix 4 ./=
663infix 4 ./=
664
664
665-- | >>> renderExpression $ unNull true .>= null_
665-- | >>> renderExpression $ unNull true .>= null_
666-- "(TRUE >= NULL)"
666-- "(TRUE >= NULL)"
667(.>=)
667(.>=)
668− :: Expression tables grouping params (nullity ty) -- ^ lhs
668+ :: Expression relations grouping params (nullity ty) -- ^ lhs
669− -> Expression tables grouping params (nullity ty) -- ^ rhs
669+ -> Expression relations grouping params (nullity ty) -- ^ rhs
670− -> Expression tables grouping params (nullity 'PGbool)
670+ -> Expression relations grouping params (nullity 'PGbool)
671(.>=) = unsafeBinaryOp ">="
671(.>=) = unsafeBinaryOp ">="
672infix 4 .>=
672infix 4 .>=
673
673
674-- | >>> renderExpression $ unNull true .< null_
674-- | >>> renderExpression $ unNull true .< null_
675-- "(TRUE < NULL)"
675-- "(TRUE < NULL)"
676(.<)
676(.<)
677− :: Expression tables grouping params (nullity ty) -- ^ lhs
677+ :: Expression relations grouping params (nullity ty) -- ^ lhs
678− -> Expression tables grouping params (nullity ty) -- ^ rhs
678+ -> Expression relations grouping params (nullity ty) -- ^ rhs
679− -> Expression tables grouping params (nullity 'PGbool)
679+ -> Expression relations grouping params (nullity 'PGbool)
680(.<) = unsafeBinaryOp "<"
680(.<) = unsafeBinaryOp "<"
681infix 4 .<
681infix 4 .<
682
682
683-- | >>> renderExpression $ unNull true .<= null_
683-- | >>> renderExpression $ unNull true .<= null_
684-- "(TRUE <= NULL)"
684-- "(TRUE <= NULL)"
685(.<=)
685(.<=)
686− :: Expression tables grouping params (nullity ty) -- ^ lhs
686+ :: Expression relations grouping params (nullity ty) -- ^ lhs
687− -> Expression tables grouping params (nullity ty) -- ^ rhs
687+ -> Expression relations grouping params (nullity ty) -- ^ rhs
688− -> Expression tables grouping params (nullity 'PGbool)
688+ -> Expression relations grouping params (nullity 'PGbool)
689(.<=) = unsafeBinaryOp "<="
689(.<=) = unsafeBinaryOp "<="
690infix 4 .<=
690infix 4 .<=
691
691
692-- | >>> renderExpression $ unNull true .> null_
692-- | >>> renderExpression $ unNull true .> null_
693-- "(TRUE > NULL)"
693-- "(TRUE > NULL)"
694(.>)
694(.>)
695− :: Expression tables grouping params (nullity ty) -- ^ lhs
695+ :: Expression relations grouping params (nullity ty) -- ^ lhs
696− -> Expression tables grouping params (nullity ty) -- ^ rhs
696+ -> Expression relations grouping params (nullity ty) -- ^ rhs
697− -> Expression tables grouping params (nullity 'PGbool)
697+ -> Expression relations grouping params (nullity 'PGbool)
698(.>) = unsafeBinaryOp ">"
698(.>) = unsafeBinaryOp ">"
699infix 4 .>
699infix 4 .>
700
700
701-- | >>> renderExpression $ currentDate
701-- | >>> renderExpression $ currentDate
702-- "CURRENT_DATE"
702-- "CURRENT_DATE"
703currentDate
703currentDate
704− :: Expression tables grouping params (nullity 'PGdate)
704+ :: Expression relations grouping params (nullity 'PGdate)
705currentDate = UnsafeExpression "CURRENT_DATE"
705currentDate = UnsafeExpression "CURRENT_DATE"
706
706
707-- | >>> renderExpression $ currentTime
707-- | >>> renderExpression $ currentTime
708-- "CURRENT_TIME"
708-- "CURRENT_TIME"
709currentTime
709currentTime
710− :: Expression tables grouping params (nullity 'PGtimetz)
710+ :: Expression relations grouping params (nullity 'PGtimetz)
711currentTime = UnsafeExpression "CURRENT_TIME"
711currentTime = UnsafeExpression "CURRENT_TIME"
712
712
713-- | >>> renderExpression $ currentTimestamp
713-- | >>> renderExpression $ currentTimestamp
714-- "CURRENT_TIMESTAMP"
714-- "CURRENT_TIMESTAMP"
715currentTimestamp
715currentTimestamp
716− :: Expression tables grouping params (nullity 'PGtimestamptz)
716+ :: Expression relations grouping params (nullity 'PGtimestamptz)
717currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
717currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
718
718
719-- | >>> renderExpression $ localTime
719-- | >>> renderExpression $ localTime
720-- "LOCALTIME"
720-- "LOCALTIME"
721localTime
721localTime
722− :: Expression tables grouping params (nullity 'PGtime)
722+ :: Expression relations grouping params (nullity 'PGtime)
723localTime = UnsafeExpression "LOCALTIME"
723localTime = UnsafeExpression "LOCALTIME"
724
724
725-- | >>> renderExpression $ localTimestamp
725-- | >>> renderExpression $ localTimestamp
726-- "LOCALTIMESTAMP"
726-- "LOCALTIMESTAMP"
727localTimestamp
727localTimestamp
728− :: Expression tables grouping params (nullity 'PGtimestamp)
728+ :: Expression relations grouping params (nullity 'PGtimestamp)
729localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
729localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
730
730
731{-----------------------------------------
731{-----------------------------------------
@@ -733,7 +733,7 @@ text
733-----------------------------------------}
733-----------------------------------------}
734
734
735instance IsString
735instance IsString
736− (Expression tables grouping params (nullity 'PGtext)) where
736+ (Expression relations grouping params (nullity 'PGtext)) where
737 fromString str = UnsafeExpression $
737 fromString str = UnsafeExpression $
738 "E\'" <> fromString (escape =<< str) <> "\'"
738 "E\'" <> fromString (escape =<< str) <> "\'"
739 where
739 where
@@ -749,32 +749,32 @@ instance IsString
749 c -> [c]
749 c -> [c]
750
750
751instance Monoid
751instance Monoid
752− (Expression tables grouping params (nullity 'PGtext)) where
752+ (Expression relations grouping params (nullity 'PGtext)) where
753 mempty = fromString ""
753 mempty = fromString ""
754 mappend = unsafeBinaryOp "||"
754 mappend = unsafeBinaryOp "||"
755
755
756-- | >>> renderExpression $ lower "ARRRGGG"
756-- | >>> renderExpression $ lower "ARRRGGG"
757-- "lower(E'ARRRGGG')"
757-- "lower(E'ARRRGGG')"
758lower
758lower
759− :: Expression tables grouping params (nullity 'PGtext)
759+ :: Expression relations grouping params (nullity 'PGtext)
760 -- ^ string to lower case
760 -- ^ string to lower case
761− -> Expression tables grouping params (nullity 'PGtext)
761+ -> Expression relations grouping params (nullity 'PGtext)
762lower = unsafeFunction "lower"
762lower = unsafeFunction "lower"
763
763
764-- | >>> renderExpression $ upper "eeee"
764-- | >>> renderExpression $ upper "eeee"
765-- "upper(E'eeee')"
765-- "upper(E'eeee')"
766upper
766upper
767− :: Expression tables grouping params (nullity 'PGtext)
767+ :: Expression relations grouping params (nullity 'PGtext)
768 -- ^ string to upper case
768 -- ^ string to upper case
769− -> Expression tables grouping params (nullity 'PGtext)
769+ -> Expression relations grouping params (nullity 'PGtext)
770upper = unsafeFunction "upper"
770upper = unsafeFunction "upper"
771
771
772-- | >>> renderExpression $ charLength "four"
772-- | >>> renderExpression $ charLength "four"
773-- "char_length(E'four')"
773-- "char_length(E'four')"
774charLength
774charLength
775− :: Expression tables grouping params (nullity 'PGtext)
775+ :: Expression relations grouping params (nullity 'PGtext)
776 -- ^ string to measure
776 -- ^ string to measure
777− -> Expression tables grouping params (nullity 'PGint4)
777+ -> Expression relations grouping params (nullity 'PGint4)
778charLength = unsafeFunction "char_length"
778charLength = unsafeFunction "char_length"
779
779
780-- | The `like` expression returns true if the @string@ matches
780-- | The `like` expression returns true if the @string@ matches
@@ -787,11 +787,11 @@ charLength = unsafeFunction "char_length"
787-- >>> renderExpression $ "abc" `like` "a%"
787-- >>> renderExpression $ "abc" `like` "a%"
788-- "(E'abc' LIKE E'a%')"
788-- "(E'abc' LIKE E'a%')"
789like
789like
790− :: Expression tables grouping params (nullity 'PGtext)
790+ :: Expression relations grouping params (nullity 'PGtext)
791 -- ^ string
791 -- ^ string
792− -> Expression tables grouping params (nullity 'PGtext)
792+ -> Expression relations grouping params (nullity 'PGtext)
793 -- ^ pattern
793 -- ^ pattern
794− -> Expression tables grouping params (nullity 'PGbool)
794+ -> Expression relations grouping params (nullity 'PGbool)
795like = unsafeBinaryOp "LIKE"
795like = unsafeBinaryOp "LIKE"
796
796
797{-----------------------------------------
797{-----------------------------------------
@@ -801,16 +801,16 @@ aggregation
801-- | escape hatch to define aggregate functions
801-- | escape hatch to define aggregate functions
802unsafeAggregate
802unsafeAggregate
803 :: ByteString -- ^ aggregate function
803 :: ByteString -- ^ aggregate function
804− -> Expression tables 'Ungrouped params (xty)
804+ -> Expression relations 'Ungrouped params (xty)
805− -> Expression tables ('Grouped bys) params (yty)
805+ -> Expression relations ('Grouped bys) params (yty)
806unsafeAggregate fun x = UnsafeExpression $ mconcat
806unsafeAggregate fun x = UnsafeExpression $ mconcat
807 [fun, "(", renderExpression x, ")"]
807 [fun, "(", renderExpression x, ")"]
808
808
809-- | escape hatch to define aggregate functions over distinct values
809-- | escape hatch to define aggregate functions over distinct values
810unsafeAggregateDistinct
810unsafeAggregateDistinct
811 :: ByteString -- ^ aggregate function
811 :: ByteString -- ^ aggregate function
812− -> Expression tables 'Ungrouped params (xty)
812+ -> Expression relations 'Ungrouped params (xty)
813− -> Expression tables ('Grouped bys) params (yty)
813+ -> Expression relations ('Grouped bys) params (yty)
814unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
814unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
815 [fun, "(DISTINCT ", renderExpression x, ")"]
815 [fun, "(DISTINCT ", renderExpression x, ")"]
816
816
@@ -823,9 +823,9 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
823-- "sum(col)"
823-- "sum(col)"
824sum_
824sum_
825 :: PGNum ty
825 :: PGNum ty
826− => Expression tables 'Ungrouped params (nullity ty)
826+ => Expression relations 'Ungrouped params (nullity ty)
827 -- ^ what to sum
827 -- ^ what to sum
828− -> Expression tables ('Grouped bys) params (nullity ty)
828+ -> Expression relations ('Grouped bys) params (nullity ty)
829sum_ = unsafeAggregate "sum"
829sum_ = unsafeAggregate "sum"
830
830
831-- | >>> :{
831-- | >>> :{
@@ -837,18 +837,18 @@ sum_ = unsafeAggregate "sum"
837-- "sum(DISTINCT col)"
837-- "sum(DISTINCT col)"
838sumDistinct
838sumDistinct
839 :: PGNum ty
839 :: PGNum ty
840− => Expression tables 'Ungrouped params (nullity ty)
840+ => Expression relations 'Ungrouped params (nullity ty)
841 -- ^ what to sum
841 -- ^ what to sum
842− -> Expression tables ('Grouped bys) params (nullity ty)
842+ -> Expression relations ('Grouped bys) params (nullity ty)
843sumDistinct = unsafeAggregateDistinct "sum"
843sumDistinct = unsafeAggregateDistinct "sum"
844
844
845-- | A constraint for `PGType`s that you can take averages of and the resulting
845-- | A constraint for `PGType`s that you can take averages of and the resulting
846-- `PGType`.
846-- `PGType`.
847class PGAvg ty avg | ty -> avg where
847class PGAvg ty avg | ty -> avg where
848 avg, avgDistinct
848 avg, avgDistinct
849− :: Expression tables 'Ungrouped params (nullity ty)
849+ :: Expression relations 'Ungrouped params (nullity ty)
850 -- ^ what to average
850 -- ^ what to average
851− -> Expression tables ('Grouped bys) params (nullity avg)
851+ -> Expression relations ('Grouped bys) params (nullity avg)
852 avg = unsafeAggregate "avg"
852 avg = unsafeAggregate "avg"
853 avgDistinct = unsafeAggregateDistinct "avg"
853 avgDistinct = unsafeAggregateDistinct "avg"
854instance PGAvg 'PGint2 'PGnumeric
854instance PGAvg 'PGint2 'PGnumeric
@@ -868,9 +868,9 @@ instance PGAvg 'PGinterval 'PGinterval
868-- "bit_and(col)"
868-- "bit_and(col)"
869bitAnd
869bitAnd
870 :: PGIntegral int
870 :: PGIntegral int
871− => Expression tables 'Ungrouped params (nullity int)
871+ => Expression relations 'Ungrouped params (nullity int)
872 -- ^ what to aggregate
872 -- ^ what to aggregate
873− -> Expression tables ('Grouped bys) params (nullity int)
873+ -> Expression relations ('Grouped bys) params (nullity int)
874bitAnd = unsafeAggregate "bit_and"
874bitAnd = unsafeAggregate "bit_and"
875
875
876-- | >>> :{
876-- | >>> :{
@@ -882,9 +882,9 @@ bitAnd = unsafeAggregate "bit_and"
882-- "bit_or(col)"
882-- "bit_or(col)"
883bitOr
883bitOr
884 :: PGIntegral int
884 :: PGIntegral int
885− => Expression tables 'Ungrouped params (nullity int)
885+ => Expression relations 'Ungrouped params (nullity int)
886 -- ^ what to aggregate
886 -- ^ what to aggregate
887− -> Expression tables ('Grouped bys) params (nullity int)
887+ -> Expression relations ('Grouped bys) params (nullity int)
888bitOr = unsafeAggregate "bit_or"
888bitOr = unsafeAggregate "bit_or"
889
889
890-- | >>> :{
890-- | >>> :{
@@ -896,9 +896,9 @@ bitOr = unsafeAggregate "bit_or"
896-- "bit_and(DISTINCT col)"
896-- "bit_and(DISTINCT col)"
897bitAndDistinct
897bitAndDistinct
898 :: PGIntegral int
898 :: PGIntegral int
899− => Expression tables 'Ungrouped params (nullity int)
899+ => Expression relations 'Ungrouped params (nullity int)
900 -- ^ what to aggregate
900 -- ^ what to aggregate
901− -> Expression tables ('Grouped bys) params (nullity int)
901+ -> Expression relations ('Grouped bys) params (nullity int)
902bitAndDistinct = unsafeAggregateDistinct "bit_and"
902bitAndDistinct = unsafeAggregateDistinct "bit_and"
903
903
904-- | >>> :{
904-- | >>> :{
@@ -910,9 +910,9 @@ bitAndDistinct = unsafeAggregateDistinct "bit_and"
910-- "bit_or(DISTINCT col)"
910-- "bit_or(DISTINCT col)"
911bitOrDistinct
911bitOrDistinct
912 :: PGIntegral int
912 :: PGIntegral int
913− => Expression tables 'Ungrouped params (nullity int)
913+ => Expression relations 'Ungrouped params (nullity int)
914 -- ^ what to aggregate
914 -- ^ what to aggregate
915− -> Expression tables ('Grouped bys) params (nullity int)
915+ -> Expression relations ('Grouped bys) params (nullity int)
916bitOrDistinct = unsafeAggregateDistinct "bit_or"
916bitOrDistinct = unsafeAggregateDistinct "bit_or"
917
917
918-- | >>> :{
918-- | >>> :{
@@ -923,9 +923,9 @@ bitOrDistinct = unsafeAggregateDistinct "bit_or"
923-- :}
923-- :}
924-- "bool_and(col)"
924-- "bool_and(col)"
925boolAnd
925boolAnd
926− :: Expression tables 'Ungrouped params (nullity 'PGbool)
926+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
927 -- ^ what to aggregate
927 -- ^ what to aggregate
928− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
928+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
929boolAnd = unsafeAggregate "bool_and"
929boolAnd = unsafeAggregate "bool_and"
930
930
931-- | >>> :{
931-- | >>> :{
@@ -936,9 +936,9 @@ boolAnd = unsafeAggregate "bool_and"
936-- :}
936-- :}
937-- "bool_or(col)"
937-- "bool_or(col)"
938boolOr
938boolOr
939− :: Expression tables 'Ungrouped params (nullity 'PGbool)
939+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
940 -- ^ what to aggregate
940 -- ^ what to aggregate
941− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
941+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
942boolOr = unsafeAggregate "bool_or"
942boolOr = unsafeAggregate "bool_or"
943
943
944-- | >>> :{
944-- | >>> :{
@@ -949,9 +949,9 @@ boolOr = unsafeAggregate "bool_or"
949-- :}
949-- :}
950-- "bool_and(DISTINCT col)"
950-- "bool_and(DISTINCT col)"
951boolAndDistinct
951boolAndDistinct
952− :: Expression tables 'Ungrouped params (nullity 'PGbool)
952+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
953 -- ^ what to aggregate
953 -- ^ what to aggregate
954− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
954+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
955boolAndDistinct = unsafeAggregateDistinct "bool_and"
955boolAndDistinct = unsafeAggregateDistinct "bool_and"
956
956
957-- | >>> :{
957-- | >>> :{
@@ -962,9 +962,9 @@ boolAndDistinct = unsafeAggregateDistinct "bool_and"
962-- :}
962-- :}
963-- "bool_or(DISTINCT col)"
963-- "bool_or(DISTINCT col)"
964boolOrDistinct
964boolOrDistinct
965− :: Expression tables 'Ungrouped params (nullity 'PGbool)
965+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
966 -- ^ what to aggregate
966 -- ^ what to aggregate
967− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
967+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
968boolOrDistinct = unsafeAggregateDistinct "bool_or"
968boolOrDistinct = unsafeAggregateDistinct "bool_or"
969
969
970-- | A special aggregation that does not require an input
970-- | A special aggregation that does not require an input
@@ -972,7 +972,7 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
972-- >>> renderExpression countStar
972-- >>> renderExpression countStar
973-- "count(*)"
973-- "count(*)"
974countStar
974countStar
975− :: Expression tables ('Grouped bys) params ('NotNull 'PGint8)
975+ :: Expression relations ('Grouped bys) params ('NotNull 'PGint8)
976countStar = UnsafeExpression $ "count(*)"
976countStar = UnsafeExpression $ "count(*)"
977
977
978-- | >>> :{
978-- | >>> :{
@@ -983,9 +983,9 @@ countStar = UnsafeExpression $ "count(*)"
983-- :}
983-- :}
984-- "count(col)"
984-- "count(col)"
985count
985count
986− :: Expression tables 'Ungrouped params ty
986+ :: Expression relations 'Ungrouped params ty
987 -- ^ what to count
987 -- ^ what to count
988− -> Expression tables ('Grouped bys) params ('NotNull 'PGint8)
988+ -> Expression relations ('Grouped bys) params ('NotNull 'PGint8)
989count = unsafeAggregate "count"
989count = unsafeAggregate "count"
990
990
991-- | >>> :{
991-- | >>> :{
@@ -996,9 +996,9 @@ count = unsafeAggregate "count"
996-- :}
996-- :}
997-- "count(DISTINCT col)"
997-- "count(DISTINCT col)"
998countDistinct
998countDistinct
999− :: Expression tables 'Ungrouped params ty
999+ :: Expression relations 'Ungrouped params ty
1000 -- ^ what to count
1000 -- ^ what to count
1001− -> Expression tables ('Grouped bys) params ('NotNull 'PGint8)
1001+ -> Expression relations ('Grouped bys) params ('NotNull 'PGint8)
1002countDistinct = unsafeAggregateDistinct "count"
1002countDistinct = unsafeAggregateDistinct "count"
1003
1003
1004-- | synonym for `boolAnd`
1004-- | synonym for `boolAnd`
@@ -1011,9 +1011,9 @@ countDistinct = unsafeAggregateDistinct "count"
1011-- :}
1011-- :}
1012-- "every(col)"
1012-- "every(col)"
1013every
1013every
1014− :: Expression tables 'Ungrouped params (nullity 'PGbool)
1014+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
1015 -- ^ what to aggregate
1015 -- ^ what to aggregate
1016− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
1016+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
1017every = unsafeAggregate "every"
1017every = unsafeAggregate "every"
1018
1018
1019-- | synonym for `boolAndDistinct`
1019-- | synonym for `boolAndDistinct`
@@ -1026,16 +1026,16 @@ every = unsafeAggregate "every"
1026-- :}
1026-- :}
1027-- "every(DISTINCT col)"
1027-- "every(DISTINCT col)"
1028everyDistinct
1028everyDistinct
1029− :: Expression tables 'Ungrouped params (nullity 'PGbool)
1029+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
1030 -- ^ what to aggregate
1030 -- ^ what to aggregate
1031− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
1031+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
1032everyDistinct = unsafeAggregateDistinct "every"
1032everyDistinct = unsafeAggregateDistinct "every"
1033
1033
1034-- | minimum and maximum aggregation
1034-- | minimum and maximum aggregation
1035max_, min_, maxDistinct, minDistinct
1035max_, min_, maxDistinct, minDistinct
1036− :: Expression tables 'Ungrouped params (nullity ty)
1036+ :: Expression relations 'Ungrouped params (nullity ty)
1037 -- ^ what to aggregate
1037 -- ^ what to aggregate
1038− -> Expression tables ('Grouped bys) params (nullity ty)
1038+ -> Expression relations ('Grouped bys) params (nullity ty)
1039max_ = unsafeAggregate "max"
1039max_ = unsafeAggregate "max"
1040min_ = unsafeAggregate "min"
1040min_ = unsafeAggregate "min"
1041maxDistinct = unsafeAggregateDistinct "max"
1041maxDistinct = unsafeAggregateDistinct "max"
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+3−3
@@ -151,7 +151,7 @@ instance Category (AlignedList p) where
151single :: p x0 x1 -> AlignedList p x0 x1
151single :: p x0 x1 -> AlignedList p x0 x1
152single step = step :>> Done
152single step = step :>> Done
153
153
154−-- | Run a `Migration` by creating the `MigrationsTable`
154+-- | Run `Migration`s by creating the `MigrationsTable`
155-- if it does not exist and then in a transaction, for each each `Migration`
155-- if it does not exist and then in a transaction, for each each `Migration`
156-- query to see if the `Migration` is executed. If not, then
156-- query to see if the `Migration` is executed. If not, then
157-- execute the `Migration` and insert its row in `MigrationsTable`.
157-- execute the `Migration` and insert its row in `MigrationsTable`.
@@ -207,13 +207,13 @@ migrateUp migration =
207 okResult result
207 okResult result
208 ntuples result
208 ntuples result
209
209
210−-- | Rewind a `Migration` by creating the `MigrationsTable`
210+-- | Rewind `Migration`s by creating the `MigrationsTable`
211-- if it does not exist and then in a transaction, for each each `Migration`
211-- if it does not exist and then in a transaction, for each each `Migration`
212-- query to see if the `Migration` is executed. If it is, then
212-- query to see if the `Migration` is executed. If it is, then
213-- rewind the `Migration` and delete its row in `MigrationsTable`.
213-- rewind the `Migration` and delete its row in `MigrationsTable`.
214migrateDown
214migrateDown
215 :: MonadBaseControl IO io
215 :: MonadBaseControl IO io
216− => AlignedList (Migration io) schema0 schema1 -- ^ migration to rewind
216+ => AlignedList (Migration io) schema0 schema1 -- ^ migrations to rewind
217 -> PQ
217 -> PQ
218 ("schema_migrations" ::: MigrationsTable ': schema1)
218 ("schema_migrations" ::: MigrationsTable ': schema1)
219 ("schema_migrations" ::: MigrationsTable ': schema0)
219 ("schema_migrations" ::: MigrationsTable ': schema0)
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+108−108
@@ -364,73 +364,73 @@ SELECT queries
364-- the intermediate table are actually output.
364-- the intermediate table are actually output.
365select
365select
366 :: SListI columns
366 :: SListI columns
367− => NP (Aliased (Expression tables grouping params)) (column ': columns)
367+ => NP (Aliased (Expression relations grouping params)) (column ': columns)
368 -- ^ select list
368 -- ^ select list
369− -> TableExpression schema params tables grouping
369+ -> TableExpression schema params relations grouping
370 -- ^ intermediate virtual table
370 -- ^ intermediate virtual table
371 -> Query schema params (column ': columns)
371 -> Query schema params (column ': columns)
372−select list tabs = UnsafeQuery $
372+select list rels = UnsafeQuery $
373 "SELECT"
373 "SELECT"
374 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
374 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
375− <+> renderTableExpression tabs
375+ <+> renderTableExpression rels
376
376
377-- | After the select list has been processed, the result table can
377-- | After the select list has been processed, the result table can
378-- be subject to the elimination of duplicate rows using `selectDistinct`.
378-- be subject to the elimination of duplicate rows using `selectDistinct`.
379selectDistinct
379selectDistinct
380 :: SListI columns
380 :: SListI columns
381− => NP (Aliased (Expression tables 'Ungrouped params)) (column ': columns)
381+ => NP (Aliased (Expression relations 'Ungrouped params)) (column ': columns)
382 -- ^ select list
382 -- ^ select list
383− -> TableExpression schema params tables 'Ungrouped
383+ -> TableExpression schema params relations 'Ungrouped
384 -- ^ intermediate virtual table
384 -- ^ intermediate virtual table
385 -> Query schema params (column ': columns)
385 -> Query schema params (column ': columns)
386−selectDistinct list tabs = UnsafeQuery $
386+selectDistinct list rels = UnsafeQuery $
387 "SELECT DISTINCT"
387 "SELECT DISTINCT"
388 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
388 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
389− <+> renderTableExpression tabs
389+ <+> renderTableExpression rels
390
390
391-- | The simplest kind of query is `selectStar` which emits all columns
391-- | The simplest kind of query is `selectStar` which emits all columns
392-- that the table expression produces.
392-- that the table expression produces.
393selectStar
393selectStar
394− :: HasUnique table tables columns
394+ :: HasUnique relation relations columns
395− => TableExpression schema params tables 'Ungrouped
395+ => TableExpression schema params relations 'Ungrouped
396 -- ^ intermediate virtual table
396 -- ^ intermediate virtual table
397 -> Query schema params columns
397 -> Query schema params columns
398−selectStar tabs = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression tabs
398+selectStar rels = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression rels
399
399
400-- | A `selectDistinctStar` emits all columns that the table expression
400-- | A `selectDistinctStar` emits all columns that the table expression
401-- produces and eliminates duplicate rows.
401-- produces and eliminates duplicate rows.
402selectDistinctStar
402selectDistinctStar
403− :: HasUnique table tables columns
403+ :: HasUnique relation relations columns
404− => TableExpression schema params tables 'Ungrouped
404+ => TableExpression schema params relations 'Ungrouped
405 -- ^ intermediate virtual table
405 -- ^ intermediate virtual table
406 -> Query schema params columns
406 -> Query schema params columns
407−selectDistinctStar tabs = UnsafeQuery $
407+selectDistinctStar rels = UnsafeQuery $
408− "SELECT DISTINCT" <+> "*" <+> renderTableExpression tabs
408+ "SELECT DISTINCT" <+> "*" <+> renderTableExpression rels
409
409
410-- | When working with multiple tables, it can also be useful to ask
410-- | When working with multiple tables, it can also be useful to ask
411-- for all the columns of a particular table, using `selectDotStar`.
411-- for all the columns of a particular table, using `selectDotStar`.
412selectDotStar
412selectDotStar
413− :: Has table tables columns
413+ :: Has relation relations columns
414− => Alias table
414+ => Alias relation
415 -- ^ particular virtual Table
415 -- ^ particular virtual Table
416− -> TableExpression schema params tables 'Ungrouped
416+ -> TableExpression schema params relations 'Ungrouped
417 -- ^ intermediate virtual table
417 -- ^ intermediate virtual table
418 -> Query schema params columns
418 -> Query schema params columns
419−selectDotStar tab tables = UnsafeQuery $
419+selectDotStar rel relations = UnsafeQuery $
420− "SELECT" <+> renderAlias tab <> ".*" <+> renderTableExpression tables
420+ "SELECT" <+> renderAlias rel <> ".*" <+> renderTableExpression relations
421
421
422-- | A `selectDistinctDotStar` asks for all the columns of a particular table,
422-- | A `selectDistinctDotStar` asks for all the columns of a particular table,
423-- and eliminates duplicate rows.
423-- and eliminates duplicate rows.
424selectDistinctDotStar
424selectDistinctDotStar
425− :: Has table tables columns
425+ :: Has relation relations columns
426− => Alias table
426+ => Alias relation
427 -- ^ particular virtual Table
427 -- ^ particular virtual Table
428− -> TableExpression schema params tables 'Ungrouped
428+ -> TableExpression schema params relations 'Ungrouped
429 -- ^ intermediate virtual table
429 -- ^ intermediate virtual table
430 -> Query schema params columns
430 -> Query schema params columns
431−selectDistinctDotStar tab tables = UnsafeQuery $
431+selectDistinctDotStar rel relations = UnsafeQuery $
432− "SELECT DISTINCT" <+> renderAlias tab <> ".*"
432+ "SELECT DISTINCT" <+> renderAlias rel <> ".*"
433− <+> renderTableExpression tables
433+ <+> renderTableExpression relations
434
434
435{-----------------------------------------
435{-----------------------------------------
436Table Expressions
436Table Expressions
@@ -445,13 +445,13 @@ Table Expressions
445data TableExpression
445data TableExpression
446 (schema :: TablesType)
446 (schema :: TablesType)
447 (params :: [NullityType])
447 (params :: [NullityType])
448− (tables :: RelationsType)
448+ (relations :: RelationsType)
449 (grouping :: Grouping)
449 (grouping :: Grouping)
450 = TableExpression
450 = TableExpression
451− { fromClause :: FromClause schema params tables
451+ { fromClause :: FromClause schema params relations
452 -- ^ A table reference that can be a table name, or a derived table such
452 -- ^ A table reference that can be a table name, or a derived table such
453 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
453 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
454− , whereClause :: [Condition tables 'Ungrouped params]
454+ , whereClause :: [Condition relations 'Ungrouped params]
455 -- ^ optional search coditions, combined with `.&&`. After the processing
455 -- ^ optional search coditions, combined with `.&&`. After the processing
456 -- of the `fromClause` is done, each row of the derived virtual table
456 -- of the `fromClause` is done, each row of the derived virtual table
457 -- is checked against the search condition. If the result of the
457 -- is checked against the search condition. If the result of the
@@ -460,20 +460,20 @@ data TableExpression
460 -- at least one column of the table generated in the `fromClause`;
460 -- at least one column of the table generated in the `fromClause`;
461 -- this is not required, but otherwise the WHERE clause will
461 -- this is not required, but otherwise the WHERE clause will
462 -- be fairly useless.
462 -- be fairly useless.
463− , groupByClause :: GroupByClause tables grouping
463+ , groupByClause :: GroupByClause relations grouping
464 -- ^ The `groupByClause` is used to group together those rows in a table
464 -- ^ The `groupByClause` is used to group together those rows in a table
465 -- that have the same values in all the columns listed. The order in which
465 -- that have the same values in all the columns listed. The order in which
466 -- the columns are listed does not matter. The effect is to combine each
466 -- the columns are listed does not matter. The effect is to combine each
467 -- set of rows having common values into one group row that represents all
467 -- set of rows having common values into one group row that represents all
468 -- rows in the group. This is done to eliminate redundancy in the output
468 -- rows in the group. This is done to eliminate redundancy in the output
469 -- and/or compute aggregates that apply to these groups.
469 -- and/or compute aggregates that apply to these groups.
470− , havingClause :: HavingClause tables grouping params
470+ , havingClause :: HavingClause relations grouping params
471 -- ^ If a table has been grouped using `groupBy`, but only certain groups
471 -- ^ If a table has been grouped using `groupBy`, but only certain groups
472 -- are of interest, the `havingClause` can be used, much like a
472 -- are of interest, the `havingClause` can be used, much like a
473 -- `whereClause`, to eliminate groups from the result. Expressions in the
473 -- `whereClause`, to eliminate groups from the result. Expressions in the
474 -- `havingClause` can refer both to grouped expressions and to ungrouped
474 -- `havingClause` can refer both to grouped expressions and to ungrouped
475 -- expressions (which necessarily involve an aggregate function).
475 -- expressions (which necessarily involve an aggregate function).
476− , orderByClause :: [SortExpression tables grouping params]
476+ , orderByClause :: [SortExpression relations grouping params]
477 -- ^ The `orderByClause` is for optional sorting. When more than one
477 -- ^ The `orderByClause` is for optional sorting. When more than one
478 -- `SortExpression` is specified, the later (right) values are used to sort
478 -- `SortExpression` is specified, the later (right) values are used to sort
479 -- rows that are equal according to the earlier (left) values.
479 -- rows that are equal according to the earlier (left) values.
@@ -491,11 +491,11 @@ data TableExpression
491
491
492-- | Render a `TableExpression`
492-- | Render a `TableExpression`
493renderTableExpression
493renderTableExpression
494− :: TableExpression schema params tables grouping
494+ :: TableExpression schema params relations grouping
495 -> ByteString
495 -> ByteString
496renderTableExpression
496renderTableExpression
497− (TableExpression tables whs' grps' hvs' srts' lims' offs') = mconcat
497+ (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
498− [ "FROM ", renderFromClause tables
498+ [ "FROM ", renderFromClause frm'
499 , renderWheres whs'
499 , renderWheres whs'
500 , renderGroupByClause grps'
500 , renderGroupByClause grps'
501 , renderHavingClause hvs'
501 , renderHavingClause hvs'
@@ -525,68 +525,68 @@ renderTableExpression
525-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
525-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
526-- to match the left-to-right sequencing of their placement in SQL.
526-- to match the left-to-right sequencing of their placement in SQL.
527from
527from
528− :: FromClause schema params tables -- ^ table reference
528+ :: FromClause schema params relations -- ^ table reference
529− -> TableExpression schema params tables 'Ungrouped
529+ -> TableExpression schema params relations 'Ungrouped
530−from tables = TableExpression tables [] NoGroups NoHaving [] [] []
530+from rels = TableExpression rels [] NoGroups NoHaving [] [] []
531
531
532-- | A `where_` is an endomorphism of `TableExpression`s which adds a
532-- | A `where_` is an endomorphism of `TableExpression`s which adds a
533-- search condition to the `whereClause`.
533-- search condition to the `whereClause`.
534where_
534where_
535− :: Condition tables 'Ungrouped params -- ^ filtering condition
535+ :: Condition relations 'Ungrouped params -- ^ filtering condition
536− -> TableExpression schema params tables grouping
536+ -> TableExpression schema params relations grouping
537− -> TableExpression schema params tables grouping
537+ -> TableExpression schema params relations grouping
538−where_ wh tables = tables {whereClause = wh : whereClause tables}
538+where_ wh rels = rels {whereClause = wh : whereClause rels}
539
539
540-- | A `group` is a transformation of `TableExpression`s which switches
540-- | A `group` is a transformation of `TableExpression`s which switches
541-- its `Grouping` from `Ungrouped` to `Grouped`. Use @group Nil@ to perform
541-- its `Grouping` from `Ungrouped` to `Grouped`. Use @group Nil@ to perform
542-- a "grand total" aggregation query.
542-- a "grand total" aggregation query.
543group
543group
544 :: SListI bys
544 :: SListI bys
545− => NP (By tables) bys -- ^ grouped columns
545+ => NP (By relations) bys -- ^ grouped columns
546− -> TableExpression schema params tables 'Ungrouped
546+ -> TableExpression schema params relations 'Ungrouped
547− -> TableExpression schema params tables ('Grouped bys)
547+ -> TableExpression schema params relations ('Grouped bys)
548−group bys tables = TableExpression
548+group bys rels = TableExpression
549− { fromClause = fromClause tables
549+ { fromClause = fromClause rels
550− , whereClause = whereClause tables
550+ , whereClause = whereClause rels
551 , groupByClause = Group bys
551 , groupByClause = Group bys
552 , havingClause = Having []
552 , havingClause = Having []
553 , orderByClause = []
553 , orderByClause = []
554− , limitClause = limitClause tables
554+ , limitClause = limitClause rels
555− , offsetClause = offsetClause tables
555+ , offsetClause = offsetClause rels
556 }
556 }
557
557
558-- | A `having` is an endomorphism of `TableExpression`s which adds a
558-- | A `having` is an endomorphism of `TableExpression`s which adds a
559-- search condition to the `havingClause`.
559-- search condition to the `havingClause`.
560having
560having
561− :: Condition tables ('Grouped bys) params -- ^ having condition
561+ :: Condition relations ('Grouped bys) params -- ^ having condition
562− -> TableExpression schema params tables ('Grouped bys)
562+ -> TableExpression schema params relations ('Grouped bys)
563− -> TableExpression schema params tables ('Grouped bys)
563+ -> TableExpression schema params relations ('Grouped bys)
564−having hv tables = tables
564+having hv rels = rels
565− { havingClause = case havingClause tables of Having hvs -> Having (hv:hvs) }
565+ { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
566
566
567-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
567-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
568-- ordering to the right of the `orderByClause`.
568-- ordering to the right of the `orderByClause`.
569orderBy
569orderBy
570− :: [SortExpression tables grouping params] -- ^ sort expressions
570+ :: [SortExpression relations grouping params] -- ^ sort expressions
571− -> TableExpression schema params tables grouping
571+ -> TableExpression schema params relations grouping
572− -> TableExpression schema params tables grouping
572+ -> TableExpression schema params relations grouping
573−orderBy srts tables = tables {orderByClause = orderByClause tables ++ srts}
573+orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
574
574
575-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
575-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
576-- `limitClause`.
576-- `limitClause`.
577limit
577limit
578 :: Word64 -- ^ limit parameter
578 :: Word64 -- ^ limit parameter
579− -> TableExpression schema params tables grouping
579+ -> TableExpression schema params relations grouping
580− -> TableExpression schema params tables grouping
580+ -> TableExpression schema params relations grouping
581−limit lim tables = tables {limitClause = lim : limitClause tables}
581+limit lim rels = rels {limitClause = lim : limitClause rels}
582
582
583-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
583-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
584-- `offsetClause`.
584-- `offsetClause`.
585offset
585offset
586 :: Word64 -- ^ offset parameter
586 :: Word64 -- ^ offset parameter
587− -> TableExpression schema params tables grouping
587+ -> TableExpression schema params relations grouping
588− -> TableExpression schema params tables grouping
588+ -> TableExpression schema params relations grouping
589−offset off tables = tables {offsetClause = off : offsetClause tables}
589+offset off rels = rels {offsetClause = off : offsetClause rels}
590
590
591{-----------------------------------------
591{-----------------------------------------
592FROM clauses
592FROM clauses
@@ -596,7 +596,7 @@ FROM clauses
596A `FromClause` can be a table name, or a derived table such
596A `FromClause` can be a table name, or a derived table such
597as a subquery, a @JOIN@ construct, or complex combinations of these.
597as a subquery, a @JOIN@ construct, or complex combinations of these.
598-}
598-}
599−newtype FromClause schema params tables
599+newtype FromClause schema params relations
600 = UnsafeFromClause { renderFromClause :: ByteString }
600 = UnsafeFromClause { renderFromClause :: ByteString }
601 deriving (GHC.Generic,Show,Eq,Ord,NFData)
601 deriving (GHC.Generic,Show,Eq,Ord,NFData)
602
602
@@ -655,7 +655,7 @@ leftOuterJoin
655 -- ^ @ON@ condition
655 -- ^ @ON@ condition
656 -> FromClause schema params left
656 -> FromClause schema params left
657 -- ^ left
657 -- ^ left
658− -> FromClause schema params (Join left (NullifyTables right))
658+ -> FromClause schema params (Join left (NullifyRelations right))
659leftOuterJoin right on left = UnsafeFromClause $
659leftOuterJoin right on left = UnsafeFromClause $
660 renderFromClause left <+> "LEFT OUTER JOIN" <+> renderFromClause right
660 renderFromClause left <+> "LEFT OUTER JOIN" <+> renderFromClause right
661 <+> "ON" <+> renderExpression on
661 <+> "ON" <+> renderExpression on
@@ -673,7 +673,7 @@ rightOuterJoin
673 -- ^ @ON@ condition
673 -- ^ @ON@ condition
674 -> FromClause schema params left
674 -> FromClause schema params left
675 -- ^ left
675 -- ^ left
676− -> FromClause schema params (Join (NullifyTables left) right)
676+ -> FromClause schema params (Join (NullifyRelations left) right)
677rightOuterJoin right on left = UnsafeFromClause $
677rightOuterJoin right on left = UnsafeFromClause $
678 renderFromClause left <+> "RIGHT OUTER JOIN" <+> renderFromClause right
678 renderFromClause left <+> "RIGHT OUTER JOIN" <+> renderFromClause right
679 <+> "ON" <+> renderExpression on
679 <+> "ON" <+> renderExpression on
@@ -693,7 +693,7 @@ fullOuterJoin
693 -> FromClause schema params left
693 -> FromClause schema params left
694 -- ^ left
694 -- ^ left
695 -> FromClause schema params
695 -> FromClause schema params
696− (Join (NullifyTables left) (NullifyTables right))
696+ (Join (NullifyRelations left) (NullifyRelations right))
697fullOuterJoin right on left = UnsafeFromClause $
697fullOuterJoin right on left = UnsafeFromClause $
698 renderFromClause left <+> "FULL OUTER JOIN" <+> renderFromClause right
698 renderFromClause left <+> "FULL OUTER JOIN" <+> renderFromClause right
699 <+> "ON" <+> renderExpression on
699 <+> "ON" <+> renderExpression on
@@ -708,40 +708,40 @@ Grouping
708-- column @col@; otherwise @By2 (\#tab \! \#col)@ will reference a table
708-- column @col@; otherwise @By2 (\#tab \! \#col)@ will reference a table
709-- qualified column @tab.col@.
709-- qualified column @tab.col@.
710data By
710data By
711− (tables :: RelationsType)
711+ (relations :: RelationsType)
712 (by :: (Symbol,Symbol)) where
712 (by :: (Symbol,Symbol)) where
713 By
713 By
714− :: (HasUnique table tables columns, Has column columns ty)
714+ :: (HasUnique relation relations columns, Has column columns ty)
715 => Alias column
715 => Alias column
716− -> By tables '(table, column)
716+ -> By relations '(relation, column)
717 By2
717 By2
718− :: (Has table tables columns, Has column columns ty)
718+ :: (Has relation relations columns, Has column columns ty)
719− => (Alias table, Alias column)
719+ => (Alias relation, Alias column)
720− -> By tables '(table, column)
720+ -> By relations '(relation, column)
721−deriving instance Show (By tables by)
721+deriving instance Show (By relations by)
722−deriving instance Eq (By tables by)
722+deriving instance Eq (By relations by)
723−deriving instance Ord (By tables by)
723+deriving instance Ord (By relations by)
724
724
725-- | Renders a `By`.
725-- | Renders a `By`.
726−renderBy :: By tables tabcolty -> ByteString
726+renderBy :: By relations by -> ByteString
727renderBy = \case
727renderBy = \case
728 By column -> renderAlias column
728 By column -> renderAlias column
729− By2 (tab, column) -> renderAlias tab <> "." <> renderAlias column
729+ By2 (rel, column) -> renderAlias rel <> "." <> renderAlias column
730
730
731-- | A `GroupByClause` indicates the `Grouping` of a `TableExpression`.
731-- | A `GroupByClause` indicates the `Grouping` of a `TableExpression`.
732-- A `NoGroups` indicates `Ungrouped` while a `Group` indicates `Grouped`.
732-- A `NoGroups` indicates `Ungrouped` while a `Group` indicates `Grouped`.
733-- @NoGroups@ is distinguised from @Group Nil@ since no aggregation can be
733-- @NoGroups@ is distinguised from @Group Nil@ since no aggregation can be
734-- done on @NoGroups@ while all output `Expression`s must be aggregated
734-- done on @NoGroups@ while all output `Expression`s must be aggregated
735-- in @Group Nil@.
735-- in @Group Nil@.
736−data GroupByClause tables grouping where
736+data GroupByClause relations grouping where
737− NoGroups :: GroupByClause tables 'Ungrouped
737+ NoGroups :: GroupByClause relations 'Ungrouped
738 Group
738 Group
739 :: SListI bys
739 :: SListI bys
740− => NP (By tables) bys
740+ => NP (By relations) bys
741− -> GroupByClause tables ('Grouped bys)
741+ -> GroupByClause relations ('Grouped bys)
742
742
743-- | Renders a `GroupByClause`.
743-- | Renders a `GroupByClause`.
744−renderGroupByClause :: GroupByClause tables grouping -> ByteString
744+renderGroupByClause :: GroupByClause relations grouping -> ByteString
745renderGroupByClause = \case
745renderGroupByClause = \case
746 NoGroups -> ""
746 NoGroups -> ""
747 Group Nil -> ""
747 Group Nil -> ""
@@ -751,17 +751,17 @@ renderGroupByClause = \case
751-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
751-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
752-- `TableExpression` must use `Having` whose conditions are combined with
752-- `TableExpression` must use `Having` whose conditions are combined with
753-- `.&&`.
753-- `.&&`.
754−data HavingClause tables grouping params where
754+data HavingClause relations grouping params where
755− NoHaving :: HavingClause tables 'Ungrouped params
755+ NoHaving :: HavingClause relations 'Ungrouped params
756 Having
756 Having
757− :: [Condition tables ('Grouped bys) params]
757+ :: [Condition relations ('Grouped bys) params]
758− -> HavingClause tables ('Grouped bys) params
758+ -> HavingClause relations ('Grouped bys) params
759−deriving instance Show (HavingClause tables grouping params)
759+deriving instance Show (HavingClause relations grouping params)
760−deriving instance Eq (HavingClause tables grouping params)
760+deriving instance Eq (HavingClause relations grouping params)
761−deriving instance Ord (HavingClause tables grouping params)
761+deriving instance Ord (HavingClause relations grouping params)
762
762
763-- | Render a `HavingClause`.
763-- | Render a `HavingClause`.
764−renderHavingClause :: HavingClause tables grouping params -> ByteString
764+renderHavingClause :: HavingClause relations grouping params -> ByteString
765renderHavingClause = \case
765renderHavingClause = \case
766 NoHaving -> ""
766 NoHaving -> ""
767 Having [] -> ""
767 Having [] -> ""
@@ -780,29 +780,29 @@ Sorting
780-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
780-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
781-- determine whether nulls appear before or after non-null values in the sort
781-- determine whether nulls appear before or after non-null values in the sort
782-- ordering of a `Null` result column.
782-- ordering of a `Null` result column.
783−data SortExpression tables grouping params where
783+data SortExpression relations grouping params where
784 Asc
784 Asc
785− :: Expression tables grouping params ('NotNull ty)
785+ :: Expression relations grouping params ('NotNull ty)
786− -> SortExpression tables grouping params
786+ -> SortExpression relations grouping params
787 Desc
787 Desc
788− :: Expression tables grouping params ('NotNull ty)
788+ :: Expression relations grouping params ('NotNull ty)
789− -> SortExpression tables grouping params
789+ -> SortExpression relations grouping params
790 AscNullsFirst
790 AscNullsFirst
791− :: Expression tables grouping params ('Null ty)
791+ :: Expression relations grouping params ('Null ty)
792− -> SortExpression tables grouping params
792+ -> SortExpression relations grouping params
793 AscNullsLast
793 AscNullsLast
794− :: Expression tables grouping params ('Null ty)
794+ :: Expression relations grouping params ('Null ty)
795− -> SortExpression tables grouping params
795+ -> SortExpression relations grouping params
796 DescNullsFirst
796 DescNullsFirst
797− :: Expression tables grouping params ('Null ty)
797+ :: Expression relations grouping params ('Null ty)
798− -> SortExpression tables grouping params
798+ -> SortExpression relations grouping params
799 DescNullsLast
799 DescNullsLast
800− :: Expression tables grouping params ('Null ty)
800+ :: Expression relations grouping params ('Null ty)
801− -> SortExpression tables grouping params
801+ -> SortExpression relations grouping params
802−deriving instance Show (SortExpression tables grouping params)
802+deriving instance Show (SortExpression relations grouping params)
803
803
804-- | Render a `SortExpression`.
804-- | Render a `SortExpression`.
805−renderSortExpression :: SortExpression tables grouping params -> ByteString
805+renderSortExpression :: SortExpression relations grouping params -> ByteString
806renderSortExpression = \case
806renderSortExpression = \case
807 Asc expression -> renderExpression expression <+> "ASC"
807 Asc expression -> renderExpression expression <+> "ASC"
808 Desc expression -> renderExpression expression <+> "DESC"
808 Desc expression -> renderExpression expression <+> "DESC"
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+12−12
@@ -75,8 +75,8 @@ module Squeal.PostgreSQL.Schema
75 , AllNotNull
75 , AllNotNull
76 , NotAllNull
76 , NotAllNull
77 , NullifyType
77 , NullifyType
78− , NullifyColumns
78+ , NullifyRelation
79− , NullifyTables
79+ , NullifyRelations
80 , Join
80 , Join
81 , Create
81 , Create
82 , AddColumn
82 , AddColumn
@@ -434,19 +434,19 @@ type family NullifyType (ty :: NullityType) :: NullityType where
434 NullifyType ('Null ty) = 'Null ty
434 NullifyType ('Null ty) = 'Null ty
435 NullifyType ('NotNull ty) = 'Null ty
435 NullifyType ('NotNull ty) = 'Null ty
436
436
437−-- | `NullifyColumns` is an idempotent that nullifies a `ColumnsType`.
437+-- | `NullifyRelation` is an idempotent that nullifies a `ColumnsType`.
438−type family NullifyColumns (columns :: RelationType) :: RelationType where
438+type family NullifyRelation (columns :: RelationType) :: RelationType where
439− NullifyColumns '[] = '[]
439+ NullifyRelation '[] = '[]
440− NullifyColumns (column ::: ty ': columns) =
440+ NullifyRelation (column ::: ty ': columns) =
441− column ::: NullifyType ty ': NullifyColumns columns
441+ column ::: NullifyType ty ': NullifyRelation columns
442
442
443−-- | `NullifyTables` is an idempotent that nullifies a `RelationsType`
443+-- | `NullifyRelations` is an idempotent that nullifies a `RelationsType`
444-- used to nullify the left or right hand side of an outer join
444-- used to nullify the left or right hand side of an outer join
445-- in a `Squeal.PostgreSQL.Query.FromClause`.
445-- in a `Squeal.PostgreSQL.Query.FromClause`.
446−type family NullifyTables (tables :: RelationsType) :: RelationsType where
446+type family NullifyRelations (tables :: RelationsType) :: RelationsType where
447− NullifyTables '[] = '[]
447+ NullifyRelations '[] = '[]
448− NullifyTables (table ::: columns ': tables) =
448+ NullifyRelations (table ::: columns ': tables) =
449− table ::: NullifyColumns columns ': NullifyTables tables
449+ table ::: NullifyRelation columns ': NullifyRelations tables
450
450
451-- | `Join` is simply promoted `++` and is used in @JOIN@s in
451-- | `Join` is simply promoted `++` and is used in @JOIN@s in
452-- `Squeal.PostgreSQL.Query.FromClause`s.
452-- `Squeal.PostgreSQL.Query.FromClause`s.