on dev help sign in
tables ~> relations
commitfe669fa71a710edb0341be86f82c7805a18d38dd authorEitan Chatav <eitan.chatav@gmail.com> dateSat 24 Mar 2018, 13:27 (9 years ago) parent5f9026f
4 files changed+307−307
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+184−184 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+108−108 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+12−12
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+184−184
@@ -198,7 +198,7 @@ class (PGTyped (PGTypeOf ty), KnownNat n) => HasParameter
198198 (params :: [NullityType])
199199 (ty :: NullityType)
200200 | n params -> ty where
201− param :: Expression tables grouping params ty
201+ param :: Expression relations grouping params ty
202202 param = UnsafeExpression $ parenthesized $
203203 "$" <> renderNat (Proxy @n) <+> "::"
204204 <+> renderTypeExpression (pgtype @(PGTypeOf ty))
@@ -207,61 +207,61 @@ instance {-# OVERLAPPING #-} PGTyped (PGTypeOf ty1)
207207instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
208208 => HasParameter n (ty' : params) ty
209209
210−instance (HasUnique table tables columns, Has column columns ty)
211− => IsLabel column (Expression tables 'Ungrouped params ty) where
210+instance (HasUnique relation relations columns, Has column columns ty)
211+ => IsLabel column (Expression relations 'Ungrouped params ty) where
212212 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
213213
214−instance (Has table tables columns, Has column columns ty)
215− => IsTableColumn table column (Expression tables 'Ungrouped params ty) where
216− table ! column = UnsafeExpression $
217− renderAlias table <> "." <> renderAlias column
214+instance (Has relation relations columns, Has column columns ty)
215+ => IsTableColumn relation column (Expression relations 'Ungrouped params ty) where
216+ relation ! column = UnsafeExpression $
217+ renderAlias relation <> "." <> renderAlias column
218218
219219{- | A `GroupedBy` constraint indicates that a table qualified column is
220220a member of the auxiliary namespace created by @GROUP BY@ clauses and thus,
221221may be called in an output `Expression` without aggregating.
222222-}
223−class (KnownSymbol table, KnownSymbol column)
224− => GroupedBy table column bys where
223+class (KnownSymbol relation, KnownSymbol column)
224+ => GroupedBy relation column bys where
225225 getGroup1
226− :: (HasUnique table tables columns, Has column columns ty)
226+ :: (HasUnique relation relations columns, Has column columns ty)
227227 => Alias column
228− -> Expression tables ('Grouped bys) params ty
228+ -> Expression relations ('Grouped bys) params ty
229229 getGroup1 column = UnsafeExpression $ renderAlias column
230230 getGroup2
231− :: (Has table tables columns, Has column columns ty)
232− => Alias table
231+ :: (Has relation relations columns, Has column columns ty)
232+ => Alias relation
233233 -> Alias column
234− -> Expression tables ('Grouped bys) params ty
235− getGroup2 table column = UnsafeExpression $
236− renderAlias table <> "." <> renderAlias column
237−instance {-# OVERLAPPING #-} (KnownSymbol table, KnownSymbol column)
238− => GroupedBy table column ('(table,column) ': bys)
234+ -> Expression relations ('Grouped bys) params ty
235+ getGroup2 relation column = UnsafeExpression $
236+ renderAlias relation <> "." <> renderAlias column
237+instance {-# OVERLAPPING #-} (KnownSymbol relation, KnownSymbol column)
238+ => GroupedBy relation column ('(table,column) ': bys)
239239instance {-# OVERLAPPABLE #-}
240− ( KnownSymbol table
240+ ( KnownSymbol relation
241241 , KnownSymbol column
242− , GroupedBy table column bys
243− ) => GroupedBy table column (tabcol ': bys)
242+ , GroupedBy relation column bys
243+ ) => GroupedBy relation column (tabcol ': bys)
244244
245245instance
246− ( HasUnique table tables columns
246+ ( HasUnique relation relations columns
247247 , Has column columns ty
248− , GroupedBy table column bys
248+ , GroupedBy relation column bys
249249 ) => IsLabel column
250− (Expression tables ('Grouped bys) params ty) where
250+ (Expression relations ('Grouped bys) params ty) where
251251 fromLabel = getGroup1 (Alias @column)
252252
253253instance
254− ( Has table tables columns
254+ ( Has relation relations columns
255255 , Has column columns ty
256− , GroupedBy table column bys
257− ) => IsTableColumn table column
258− (Expression tables ('Grouped bys) params ty) where (!) = getGroup2
256+ , GroupedBy relation column bys
257+ ) => IsTableColumn relation column
258+ (Expression relations ('Grouped bys) params ty) where (!) = getGroup2
259259
260260-- | analagous to `Nothing`
261261--
262262-- >>> renderExpression $ null_
263263-- "NULL"
264−null_ :: Expression tables grouping params ('Null ty)
264+null_ :: Expression relations grouping params ('Null ty)
265265null_ = UnsafeExpression "NULL"
266266
267267-- | analagous to `Just`
@@ -269,9 +269,9 @@ null_ = UnsafeExpression "NULL"
269269-- >>> renderExpression $ unNull true
270270-- "TRUE"
271271unNull
272− :: Expression tables grouping params ('NotNull ty)
272+ :: Expression relations grouping params ('NotNull ty)
273273 -- ^ not @NULL@
274− -> Expression tables grouping params ('Null ty)
274+ -> Expression relations grouping params ('Null ty)
275275unNull = UnsafeExpression . renderExpression
276276
277277-- | return the leftmost value which is not NULL
@@ -279,11 +279,11 @@ unNull = UnsafeExpression . renderExpression
279279-- >>> renderExpression $ coalesce [null_, unNull true] false
280280-- "COALESCE(NULL, TRUE, FALSE)"
281281coalesce
282− :: [Expression tables grouping params ('Null ty)]
282+ :: [Expression relations grouping params ('Null ty)]
283283 -- ^ @NULL@s may be present
284− -> Expression tables grouping params ('NotNull ty)
284+ -> Expression relations grouping params ('NotNull ty)
285285 -- ^ @NULL@ is absent
286− -> Expression tables grouping params ('NotNull ty)
286+ -> Expression relations grouping params ('NotNull ty)
287287coalesce nullxs notNullx = UnsafeExpression $
288288 "COALESCE" <> parenthesized (commaSeparated
289289 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -293,26 +293,26 @@ coalesce nullxs notNullx = UnsafeExpression $
293293-- >>> renderExpression $ fromNull true null_
294294-- "COALESCE(NULL, TRUE)"
295295fromNull
296− :: Expression tables grouping params ('NotNull ty)
296+ :: Expression relations grouping params ('NotNull ty)
297297 -- ^ what to convert @NULL@ to
298− -> Expression tables grouping params ('Null ty)
299− -> Expression tables grouping params ('NotNull ty)
298+ -> Expression relations grouping params ('Null ty)
299+ -> Expression relations grouping params ('NotNull ty)
300300fromNull notNullx nullx = coalesce [nullx] notNullx
301301
302302-- | >>> renderExpression $ null_ & isNull
303303-- "NULL IS NULL"
304304isNull
305− :: Expression tables grouping params ('Null ty)
305+ :: Expression relations grouping params ('Null ty)
306306 -- ^ possibly @NULL@
307− -> Condition tables grouping params
307+ -> Condition relations grouping params
308308isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
309309
310310-- | >>> renderExpression $ null_ & isn'tNull
311311-- "NULL IS NOT NULL"
312312isn'tNull
313− :: Expression tables grouping params ('Null ty)
313+ :: Expression relations grouping params ('Null ty)
314314 -- ^ possibly @NULL@
315− -> Condition tables grouping params
315+ -> Condition relations grouping params
316316isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
317317
318318-- | analagous to `maybe` using @IS NULL@
@@ -320,13 +320,13 @@ isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
320320-- >>> renderExpression $ matchNull true not_ null_
321321-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
322322matchNull
323− :: Expression tables grouping params (nullty)
323+ :: Expression relations grouping params (nullty)
324324 -- ^ what to convert @NULL@ to
325− -> ( Expression tables grouping params ('NotNull ty)
326− -> Expression tables grouping params (nullty) )
325+ -> ( Expression relations grouping params ('NotNull ty)
326+ -> Expression relations grouping params (nullty) )
327327 -- ^ function to perform when @NULL@ is absent
328− -> Expression tables grouping params ('Null ty)
329− -> Expression tables grouping params (nullty)
328+ -> Expression relations grouping params ('Null ty)
329+ -> Expression relations grouping params (nullty)
330330matchNull y f x = ifThenElse (isNull x) y
331331 (f (UnsafeExpression (renderExpression x)))
332332
@@ -337,47 +337,47 @@ matchNull y f x = ifThenElse (isNull x) y
337337-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
338338-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
339339nullIf
340− :: Expression tables grouping params ('NotNull ty)
340+ :: Expression relations grouping params ('NotNull ty)
341341 -- ^ @NULL@ is absent
342− -> Expression tables grouping params ('NotNull ty)
342+ -> Expression relations grouping params ('NotNull ty)
343343 -- ^ @NULL@ is absent
344− -> Expression tables grouping params ('Null ty)
344+ -> Expression relations grouping params ('Null ty)
345345nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
346346 (renderExpression x <> ", " <> renderExpression y)
347347
348348-- | >>> renderExpression $ array [null_, unNull false, unNull true]
349349-- "ARRAY[NULL, FALSE, TRUE]"
350350array
351− :: [Expression tables grouping params ('Null ty)]
351+ :: [Expression relations grouping params ('Null ty)]
352352 -- ^ array elements
353− -> Expression tables grouping params (nullity ('PGvararray ty))
353+ -> Expression relations grouping params (nullity ('PGvararray ty))
354354array xs = UnsafeExpression $
355355 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
356356
357357instance Monoid
358− (Expression tables grouping params (nullity ('PGvararray ty))) where
358+ (Expression relations grouping params (nullity ('PGvararray ty))) where
359359 mempty = array []
360360 mappend = unsafeBinaryOp "||"
361361
362362-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
363363-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
364364greatest
365− :: Expression tables grouping params (nullty)
365+ :: Expression relations grouping params (nullty)
366366 -- ^ needs at least 1 argument
367− -> [Expression tables grouping params (nullty)]
367+ -> [Expression relations grouping params (nullty)]
368368 -- ^ or more
369− -> Expression tables grouping params (nullty)
369+ -> Expression relations grouping params (nullty)
370370greatest x xs = UnsafeExpression $ "GREATEST("
371371 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
372372
373373-- | >>> renderExpression $ least currentTimestamp [null_]
374374-- "LEAST(CURRENT_TIMESTAMP, NULL)"
375375least
376− :: Expression tables grouping params (nullty)
376+ :: Expression relations grouping params (nullty)
377377 -- ^ needs at least 1 argument
378− -> [Expression tables grouping params (nullty)]
378+ -> [Expression relations grouping params (nullty)]
379379 -- ^ or more
380− -> Expression tables grouping params (nullty)
380+ -> Expression relations grouping params (nullty)
381381least x xs = UnsafeExpression $ "LEAST("
382382 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
383383
@@ -386,9 +386,9 @@ least x xs = UnsafeExpression $ "LEAST("
386386unsafeBinaryOp
387387 :: ByteString
388388 -- ^ operator
389− -> Expression tables grouping params (ty0)
390− -> Expression tables grouping params (ty1)
391− -> Expression tables grouping params (ty2)
389+ -> Expression relations grouping params (ty0)
390+ -> Expression relations grouping params (ty1)
391+ -> Expression relations grouping params (ty2)
392392unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
393393 renderExpression x <+> op <+> renderExpression y
394394
@@ -397,8 +397,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
397397unsafeUnaryOp
398398 :: ByteString
399399 -- ^ operator
400− -> Expression tables grouping params (ty0)
401− -> Expression tables grouping params (ty1)
400+ -> Expression relations grouping params (ty0)
401+ -> Expression relations grouping params (ty1)
402402unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
403403 op <+> renderExpression x
404404
@@ -407,13 +407,13 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
407407unsafeFunction
408408 :: ByteString
409409 -- ^ function
410− -> Expression tables grouping params (xty)
411− -> Expression tables grouping params (yty)
410+ -> Expression relations grouping params (xty)
411+ -> Expression relations grouping params (yty)
412412unsafeFunction fun x = UnsafeExpression $
413413 fun <> parenthesized (renderExpression x)
414414
415415instance PGNum ty
416− => Num (Expression tables grouping params (nullity ty)) where
416+ => Num (Expression relations grouping params (nullity ty)) where
417417 (+) = unsafeBinaryOp "+"
418418 (-) = unsafeBinaryOp "-"
419419 (*) = unsafeBinaryOp "*"
@@ -425,12 +425,12 @@ instance PGNum ty
425425 . show
426426
427427instance (PGNum ty, PGFloating ty) => Fractional
428− (Expression tables grouping params (nullity ty)) where
428+ (Expression relations grouping params (nullity ty)) where
429429 (/) = unsafeBinaryOp "/"
430430 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
431431
432432instance (PGNum ty, PGFloating ty) => Floating
433− (Expression tables grouping params (nullity ty)) where
433+ (Expression relations grouping params (nullity ty)) where
434434 pi = UnsafeExpression "pi()"
435435 exp = unsafeFunction "exp"
436436 log = unsafeFunction "ln"
@@ -453,18 +453,18 @@ instance (PGNum ty, PGFloating ty) => Floating
453453
454454-- | >>> :{
455455-- let
456−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
456+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
457457-- expression = atan2_ pi 2
458458-- in renderExpression expression
459459-- :}
460460-- "atan2(pi(), 2)"
461461atan2_
462462 :: PGFloating float
463− => Expression tables grouping params (nullity float)
463+ => Expression relations grouping params (nullity float)
464464 -- ^ numerator
465− -> Expression tables grouping params (nullity float)
465+ -> Expression relations grouping params (nullity float)
466466 -- ^ denominator
467− -> Expression tables grouping params (nullity float)
467+ -> Expression relations grouping params (nullity float)
468468atan2_ y x = UnsafeExpression $
469469 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
470470
@@ -477,9 +477,9 @@ atan2_ y x = UnsafeExpression $
477477cast
478478 :: TypeExpression ('NoDef :=> 'Null ty1)
479479 -- ^ type to cast as
480− -> Expression tables grouping params (nullity ty0)
480+ -> Expression relations grouping params (nullity ty0)
481481 -- ^ value to convert
482− -> Expression tables grouping params (nullity ty1)
482+ -> Expression relations grouping params (nullity ty1)
483483cast ty x = UnsafeExpression $ parenthesized $
484484 renderExpression x <+> "::" <+> renderTypeExpression ty
485485
@@ -487,133 +487,133 @@ cast ty x = UnsafeExpression $ parenthesized $
487487--
488488-- >>> :{
489489-- let
490−-- expression :: Expression tables grouping params (nullity 'PGint2)
490+-- expression :: Expression relations grouping params (nullity 'PGint2)
491491-- expression = 5 `quot_` 2
492492-- in renderExpression expression
493493-- :}
494494-- "(5 / 2)"
495495quot_
496496 :: PGIntegral int
497− => Expression tables grouping params (nullity int)
497+ => Expression relations grouping params (nullity int)
498498 -- ^ numerator
499− -> Expression tables grouping params (nullity int)
499+ -> Expression relations grouping params (nullity int)
500500 -- ^ denominator
501− -> Expression tables grouping params (nullity int)
501+ -> Expression relations grouping params (nullity int)
502502quot_ = unsafeBinaryOp "/"
503503
504504-- | remainder upon integer division
505505--
506506-- >>> :{
507507-- let
508−-- expression :: Expression tables grouping params (nullity 'PGint2)
508+-- expression :: Expression relations grouping params (nullity 'PGint2)
509509-- expression = 5 `rem_` 2
510510-- in renderExpression expression
511511-- :}
512512-- "(5 % 2)"
513513rem_
514514 :: PGIntegral int
515− => Expression tables grouping params (nullity int)
515+ => Expression relations grouping params (nullity int)
516516 -- ^ numerator
517− -> Expression tables grouping params (nullity int)
517+ -> Expression relations grouping params (nullity int)
518518 -- ^ denominator
519− -> Expression tables grouping params (nullity int)
519+ -> Expression relations grouping params (nullity int)
520520rem_ = unsafeBinaryOp "%"
521521
522522-- | >>> :{
523523-- let
524−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
524+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
525525-- expression = trunc pi
526526-- in renderExpression expression
527527-- :}
528528-- "trunc(pi())"
529529trunc
530530 :: PGFloating frac
531− => Expression tables grouping params (nullity frac)
531+ => Expression relations grouping params (nullity frac)
532532 -- ^ fractional number
533− -> Expression tables grouping params (nullity frac)
533+ -> Expression relations grouping params (nullity frac)
534534trunc = unsafeFunction "trunc"
535535
536536-- | >>> :{
537537-- let
538−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
538+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
539539-- expression = round_ pi
540540-- in renderExpression expression
541541-- :}
542542-- "round(pi())"
543543round_
544544 :: PGFloating frac
545− => Expression tables grouping params (nullity frac)
545+ => Expression relations grouping params (nullity frac)
546546 -- ^ fractional number
547− -> Expression tables grouping params (nullity frac)
547+ -> Expression relations grouping params (nullity frac)
548548round_ = unsafeFunction "round"
549549
550550-- | >>> :{
551551-- let
552−-- expression :: Expression tables grouping params (nullity 'PGfloat4)
552+-- expression :: Expression relations grouping params (nullity 'PGfloat4)
553553-- expression = ceiling_ pi
554554-- in renderExpression expression
555555-- :}
556556-- "ceiling(pi())"
557557ceiling_
558558 :: PGFloating frac
559− => Expression tables grouping params (nullity frac)
559+ => Expression relations grouping params (nullity frac)
560560 -- ^ fractional number
561− -> Expression tables grouping params (nullity frac)
561+ -> Expression relations grouping params (nullity frac)
562562ceiling_ = unsafeFunction "ceiling"
563563
564564-- | A `Condition` is a boolean valued `Expression`. While SQL allows
565565-- conditions to have @NULL@, squeal instead chooses to disallow @NULL@,
566566-- forcing one to handle the case of @NULL@ explicitly to produce
567567-- a `Condition`.
568−type Condition tables grouping params =
569− Expression tables grouping params ('NotNull 'PGbool)
568+type Condition relations grouping params =
569+ Expression relations grouping params ('NotNull 'PGbool)
570570
571571-- | >>> renderExpression true
572572-- "TRUE"
573−true :: Condition tables grouping params
573+true :: Condition relations grouping params
574574true = UnsafeExpression "TRUE"
575575
576576-- | >>> renderExpression false
577577-- "FALSE"
578−false :: Condition tables grouping params
578+false :: Condition relations grouping params
579579false = UnsafeExpression "FALSE"
580580
581581-- | >>> renderExpression $ not_ true
582582-- "(NOT TRUE)"
583583not_
584− :: Condition tables grouping params
585− -> Condition tables grouping params
584+ :: Condition relations grouping params
585+ -> Condition relations grouping params
586586not_ = unsafeUnaryOp "NOT"
587587
588588-- | >>> renderExpression $ true .&& false
589589-- "(TRUE AND FALSE)"
590590(.&&)
591− :: Condition tables grouping params
592− -> Condition tables grouping params
593− -> Condition tables grouping params
591+ :: Condition relations grouping params
592+ -> Condition relations grouping params
593+ -> Condition relations grouping params
594594(.&&) = unsafeBinaryOp "AND"
595595
596596-- | >>> renderExpression $ true .|| false
597597-- "(TRUE OR FALSE)"
598598(.||)
599− :: Condition tables grouping params
600− -> Condition tables grouping params
601− -> Condition tables grouping params
599+ :: Condition relations grouping params
600+ -> Condition relations grouping params
601+ -> Condition relations grouping params
602602(.||) = unsafeBinaryOp "OR"
603603
604604-- | >>> :{
605605-- let
606−-- expression :: Expression tables grouping params (nullity 'PGint2)
606+-- expression :: Expression relations grouping params (nullity 'PGint2)
607607-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
608608-- in renderExpression expression
609609-- :}
610610-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
611611caseWhenThenElse
612− :: [ ( Condition tables grouping params
613− , Expression tables grouping params (ty)
612+ :: [ ( Condition relations grouping params
613+ , Expression relations grouping params (ty)
614614 ) ]
615− -> Expression tables grouping params (ty)
616− -> Expression tables grouping params (ty)
615+ -> Expression relations grouping params (ty)
616+ -> Expression relations grouping params (ty)
617617caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
618618 [ "CASE"
619619 , mconcat
@@ -629,16 +629,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
629629
630630-- | >>> :{
631631-- let
632−-- expression :: Expression tables grouping params (nullity 'PGint2)
632+-- expression :: Expression relations grouping params (nullity 'PGint2)
633633-- expression = ifThenElse true 1 0
634634-- in renderExpression expression
635635-- :}
636636-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
637637ifThenElse
638− :: Condition tables grouping params
639− -> Expression tables grouping params (ty)
640− -> Expression tables grouping params (ty)
641− -> Expression tables grouping params (ty)
638+ :: Condition relations grouping params
639+ -> Expression relations grouping params (ty)
640+ -> Expression relations grouping params (ty)
641+ -> Expression relations grouping params (ty)
642642ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
643643
644644-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -647,85 +647,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
647647-- >>> renderExpression $ unNull true .== null_
648648-- "(TRUE = NULL)"
649649(.==)
650− :: Expression tables grouping params (nullity ty) -- ^ lhs
651− -> Expression tables grouping params (nullity ty) -- ^ rhs
652− -> Expression tables grouping params (nullity 'PGbool)
650+ :: Expression relations grouping params (nullity ty) -- ^ lhs
651+ -> Expression relations grouping params (nullity ty) -- ^ rhs
652+ -> Expression relations grouping params (nullity 'PGbool)
653653(.==) = unsafeBinaryOp "="
654654infix 4 .==
655655
656656-- | >>> renderExpression $ unNull true ./= null_
657657-- "(TRUE <> NULL)"
658658(./=)
659− :: Expression tables grouping params (nullity ty) -- ^ lhs
660− -> Expression tables grouping params (nullity ty) -- ^ rhs
661− -> Expression tables grouping params (nullity 'PGbool)
659+ :: Expression relations grouping params (nullity ty) -- ^ lhs
660+ -> Expression relations grouping params (nullity ty) -- ^ rhs
661+ -> Expression relations grouping params (nullity 'PGbool)
662662(./=) = unsafeBinaryOp "<>"
663663infix 4 ./=
664664
665665-- | >>> renderExpression $ unNull true .>= null_
666666-- "(TRUE >= NULL)"
667667(.>=)
668− :: Expression tables grouping params (nullity ty) -- ^ lhs
669− -> Expression tables grouping params (nullity ty) -- ^ rhs
670− -> Expression tables grouping params (nullity 'PGbool)
668+ :: Expression relations grouping params (nullity ty) -- ^ lhs
669+ -> Expression relations grouping params (nullity ty) -- ^ rhs
670+ -> Expression relations grouping params (nullity 'PGbool)
671671(.>=) = unsafeBinaryOp ">="
672672infix 4 .>=
673673
674674-- | >>> renderExpression $ unNull true .< null_
675675-- "(TRUE < NULL)"
676676(.<)
677− :: Expression tables grouping params (nullity ty) -- ^ lhs
678− -> Expression tables grouping params (nullity ty) -- ^ rhs
679− -> Expression tables grouping params (nullity 'PGbool)
677+ :: Expression relations grouping params (nullity ty) -- ^ lhs
678+ -> Expression relations grouping params (nullity ty) -- ^ rhs
679+ -> Expression relations grouping params (nullity 'PGbool)
680680(.<) = unsafeBinaryOp "<"
681681infix 4 .<
682682
683683-- | >>> renderExpression $ unNull true .<= null_
684684-- "(TRUE <= NULL)"
685685(.<=)
686− :: Expression tables grouping params (nullity ty) -- ^ lhs
687− -> Expression tables grouping params (nullity ty) -- ^ rhs
688− -> Expression tables grouping params (nullity 'PGbool)
686+ :: Expression relations grouping params (nullity ty) -- ^ lhs
687+ -> Expression relations grouping params (nullity ty) -- ^ rhs
688+ -> Expression relations grouping params (nullity 'PGbool)
689689(.<=) = unsafeBinaryOp "<="
690690infix 4 .<=
691691
692692-- | >>> renderExpression $ unNull true .> null_
693693-- "(TRUE > NULL)"
694694(.>)
695− :: Expression tables grouping params (nullity ty) -- ^ lhs
696− -> Expression tables grouping params (nullity ty) -- ^ rhs
697− -> Expression tables grouping params (nullity 'PGbool)
695+ :: Expression relations grouping params (nullity ty) -- ^ lhs
696+ -> Expression relations grouping params (nullity ty) -- ^ rhs
697+ -> Expression relations grouping params (nullity 'PGbool)
698698(.>) = unsafeBinaryOp ">"
699699infix 4 .>
700700
701701-- | >>> renderExpression $ currentDate
702702-- "CURRENT_DATE"
703703currentDate
704− :: Expression tables grouping params (nullity 'PGdate)
704+ :: Expression relations grouping params (nullity 'PGdate)
705705currentDate = UnsafeExpression "CURRENT_DATE"
706706
707707-- | >>> renderExpression $ currentTime
708708-- "CURRENT_TIME"
709709currentTime
710− :: Expression tables grouping params (nullity 'PGtimetz)
710+ :: Expression relations grouping params (nullity 'PGtimetz)
711711currentTime = UnsafeExpression "CURRENT_TIME"
712712
713713-- | >>> renderExpression $ currentTimestamp
714714-- "CURRENT_TIMESTAMP"
715715currentTimestamp
716− :: Expression tables grouping params (nullity 'PGtimestamptz)
716+ :: Expression relations grouping params (nullity 'PGtimestamptz)
717717currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
718718
719719-- | >>> renderExpression $ localTime
720720-- "LOCALTIME"
721721localTime
722− :: Expression tables grouping params (nullity 'PGtime)
722+ :: Expression relations grouping params (nullity 'PGtime)
723723localTime = UnsafeExpression "LOCALTIME"
724724
725725-- | >>> renderExpression $ localTimestamp
726726-- "LOCALTIMESTAMP"
727727localTimestamp
728− :: Expression tables grouping params (nullity 'PGtimestamp)
728+ :: Expression relations grouping params (nullity 'PGtimestamp)
729729localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
730730
731731{-----------------------------------------
@@ -733,7 +733,7 @@ text
733733-----------------------------------------}
734734
735735instance IsString
736− (Expression tables grouping params (nullity 'PGtext)) where
736+ (Expression relations grouping params (nullity 'PGtext)) where
737737 fromString str = UnsafeExpression $
738738 "E\'" <> fromString (escape =<< str) <> "\'"
739739 where
@@ -749,32 +749,32 @@ instance IsString
749749 c -> [c]
750750
751751instance Monoid
752− (Expression tables grouping params (nullity 'PGtext)) where
752+ (Expression relations grouping params (nullity 'PGtext)) where
753753 mempty = fromString ""
754754 mappend = unsafeBinaryOp "||"
755755
756756-- | >>> renderExpression $ lower "ARRRGGG"
757757-- "lower(E'ARRRGGG')"
758758lower
759− :: Expression tables grouping params (nullity 'PGtext)
759+ :: Expression relations grouping params (nullity 'PGtext)
760760 -- ^ string to lower case
761− -> Expression tables grouping params (nullity 'PGtext)
761+ -> Expression relations grouping params (nullity 'PGtext)
762762lower = unsafeFunction "lower"
763763
764764-- | >>> renderExpression $ upper "eeee"
765765-- "upper(E'eeee')"
766766upper
767− :: Expression tables grouping params (nullity 'PGtext)
767+ :: Expression relations grouping params (nullity 'PGtext)
768768 -- ^ string to upper case
769− -> Expression tables grouping params (nullity 'PGtext)
769+ -> Expression relations grouping params (nullity 'PGtext)
770770upper = unsafeFunction "upper"
771771
772772-- | >>> renderExpression $ charLength "four"
773773-- "char_length(E'four')"
774774charLength
775− :: Expression tables grouping params (nullity 'PGtext)
775+ :: Expression relations grouping params (nullity 'PGtext)
776776 -- ^ string to measure
777− -> Expression tables grouping params (nullity 'PGint4)
777+ -> Expression relations grouping params (nullity 'PGint4)
778778charLength = unsafeFunction "char_length"
779779
780780-- | The `like` expression returns true if the @string@ matches
@@ -787,11 +787,11 @@ charLength = unsafeFunction "char_length"
787787-- >>> renderExpression $ "abc" `like` "a%"
788788-- "(E'abc' LIKE E'a%')"
789789like
790− :: Expression tables grouping params (nullity 'PGtext)
790+ :: Expression relations grouping params (nullity 'PGtext)
791791 -- ^ string
792− -> Expression tables grouping params (nullity 'PGtext)
792+ -> Expression relations grouping params (nullity 'PGtext)
793793 -- ^ pattern
794− -> Expression tables grouping params (nullity 'PGbool)
794+ -> Expression relations grouping params (nullity 'PGbool)
795795like = unsafeBinaryOp "LIKE"
796796
797797{-----------------------------------------
@@ -801,16 +801,16 @@ aggregation
801801-- | escape hatch to define aggregate functions
802802unsafeAggregate
803803 :: ByteString -- ^ aggregate function
804− -> Expression tables 'Ungrouped params (xty)
805− -> Expression tables ('Grouped bys) params (yty)
804+ -> Expression relations 'Ungrouped params (xty)
805+ -> Expression relations ('Grouped bys) params (yty)
806806unsafeAggregate fun x = UnsafeExpression $ mconcat
807807 [fun, "(", renderExpression x, ")"]
808808
809809-- | escape hatch to define aggregate functions over distinct values
810810unsafeAggregateDistinct
811811 :: ByteString -- ^ aggregate function
812− -> Expression tables 'Ungrouped params (xty)
813− -> Expression tables ('Grouped bys) params (yty)
812+ -> Expression relations 'Ungrouped params (xty)
813+ -> Expression relations ('Grouped bys) params (yty)
814814unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
815815 [fun, "(DISTINCT ", renderExpression x, ")"]
816816
@@ -823,9 +823,9 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
823823-- "sum(col)"
824824sum_
825825 :: PGNum ty
826− => Expression tables 'Ungrouped params (nullity ty)
826+ => Expression relations 'Ungrouped params (nullity ty)
827827 -- ^ what to sum
828− -> Expression tables ('Grouped bys) params (nullity ty)
828+ -> Expression relations ('Grouped bys) params (nullity ty)
829829sum_ = unsafeAggregate "sum"
830830
831831-- | >>> :{
@@ -837,18 +837,18 @@ sum_ = unsafeAggregate "sum"
837837-- "sum(DISTINCT col)"
838838sumDistinct
839839 :: PGNum ty
840− => Expression tables 'Ungrouped params (nullity ty)
840+ => Expression relations 'Ungrouped params (nullity ty)
841841 -- ^ what to sum
842− -> Expression tables ('Grouped bys) params (nullity ty)
842+ -> Expression relations ('Grouped bys) params (nullity ty)
843843sumDistinct = unsafeAggregateDistinct "sum"
844844
845845-- | A constraint for `PGType`s that you can take averages of and the resulting
846846-- `PGType`.
847847class PGAvg ty avg | ty -> avg where
848848 avg, avgDistinct
849− :: Expression tables 'Ungrouped params (nullity ty)
849+ :: Expression relations 'Ungrouped params (nullity ty)
850850 -- ^ what to average
851− -> Expression tables ('Grouped bys) params (nullity avg)
851+ -> Expression relations ('Grouped bys) params (nullity avg)
852852 avg = unsafeAggregate "avg"
853853 avgDistinct = unsafeAggregateDistinct "avg"
854854instance PGAvg 'PGint2 'PGnumeric
@@ -868,9 +868,9 @@ instance PGAvg 'PGinterval 'PGinterval
868868-- "bit_and(col)"
869869bitAnd
870870 :: PGIntegral int
871− => Expression tables 'Ungrouped params (nullity int)
871+ => Expression relations 'Ungrouped params (nullity int)
872872 -- ^ what to aggregate
873− -> Expression tables ('Grouped bys) params (nullity int)
873+ -> Expression relations ('Grouped bys) params (nullity int)
874874bitAnd = unsafeAggregate "bit_and"
875875
876876-- | >>> :{
@@ -882,9 +882,9 @@ bitAnd = unsafeAggregate "bit_and"
882882-- "bit_or(col)"
883883bitOr
884884 :: PGIntegral int
885− => Expression tables 'Ungrouped params (nullity int)
885+ => Expression relations 'Ungrouped params (nullity int)
886886 -- ^ what to aggregate
887− -> Expression tables ('Grouped bys) params (nullity int)
887+ -> Expression relations ('Grouped bys) params (nullity int)
888888bitOr = unsafeAggregate "bit_or"
889889
890890-- | >>> :{
@@ -896,9 +896,9 @@ bitOr = unsafeAggregate "bit_or"
896896-- "bit_and(DISTINCT col)"
897897bitAndDistinct
898898 :: PGIntegral int
899− => Expression tables 'Ungrouped params (nullity int)
899+ => Expression relations 'Ungrouped params (nullity int)
900900 -- ^ what to aggregate
901− -> Expression tables ('Grouped bys) params (nullity int)
901+ -> Expression relations ('Grouped bys) params (nullity int)
902902bitAndDistinct = unsafeAggregateDistinct "bit_and"
903903
904904-- | >>> :{
@@ -910,9 +910,9 @@ bitAndDistinct = unsafeAggregateDistinct "bit_and"
910910-- "bit_or(DISTINCT col)"
911911bitOrDistinct
912912 :: PGIntegral int
913− => Expression tables 'Ungrouped params (nullity int)
913+ => Expression relations 'Ungrouped params (nullity int)
914914 -- ^ what to aggregate
915− -> Expression tables ('Grouped bys) params (nullity int)
915+ -> Expression relations ('Grouped bys) params (nullity int)
916916bitOrDistinct = unsafeAggregateDistinct "bit_or"
917917
918918-- | >>> :{
@@ -923,9 +923,9 @@ bitOrDistinct = unsafeAggregateDistinct "bit_or"
923923-- :}
924924-- "bool_and(col)"
925925boolAnd
926− :: Expression tables 'Ungrouped params (nullity 'PGbool)
926+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
927927 -- ^ what to aggregate
928− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
928+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
929929boolAnd = unsafeAggregate "bool_and"
930930
931931-- | >>> :{
@@ -936,9 +936,9 @@ boolAnd = unsafeAggregate "bool_and"
936936-- :}
937937-- "bool_or(col)"
938938boolOr
939− :: Expression tables 'Ungrouped params (nullity 'PGbool)
939+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
940940 -- ^ what to aggregate
941− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
941+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
942942boolOr = unsafeAggregate "bool_or"
943943
944944-- | >>> :{
@@ -949,9 +949,9 @@ boolOr = unsafeAggregate "bool_or"
949949-- :}
950950-- "bool_and(DISTINCT col)"
951951boolAndDistinct
952− :: Expression tables 'Ungrouped params (nullity 'PGbool)
952+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
953953 -- ^ what to aggregate
954− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
954+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
955955boolAndDistinct = unsafeAggregateDistinct "bool_and"
956956
957957-- | >>> :{
@@ -962,9 +962,9 @@ boolAndDistinct = unsafeAggregateDistinct "bool_and"
962962-- :}
963963-- "bool_or(DISTINCT col)"
964964boolOrDistinct
965− :: Expression tables 'Ungrouped params (nullity 'PGbool)
965+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
966966 -- ^ what to aggregate
967− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
967+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
968968boolOrDistinct = unsafeAggregateDistinct "bool_or"
969969
970970-- | A special aggregation that does not require an input
@@ -972,7 +972,7 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
972972-- >>> renderExpression countStar
973973-- "count(*)"
974974countStar
975− :: Expression tables ('Grouped bys) params ('NotNull 'PGint8)
975+ :: Expression relations ('Grouped bys) params ('NotNull 'PGint8)
976976countStar = UnsafeExpression $ "count(*)"
977977
978978-- | >>> :{
@@ -983,9 +983,9 @@ countStar = UnsafeExpression $ "count(*)"
983983-- :}
984984-- "count(col)"
985985count
986− :: Expression tables 'Ungrouped params ty
986+ :: Expression relations 'Ungrouped params ty
987987 -- ^ what to count
988− -> Expression tables ('Grouped bys) params ('NotNull 'PGint8)
988+ -> Expression relations ('Grouped bys) params ('NotNull 'PGint8)
989989count = unsafeAggregate "count"
990990
991991-- | >>> :{
@@ -996,9 +996,9 @@ count = unsafeAggregate "count"
996996-- :}
997997-- "count(DISTINCT col)"
998998countDistinct
999− :: Expression tables 'Ungrouped params ty
999+ :: Expression relations 'Ungrouped params ty
10001000 -- ^ what to count
1001− -> Expression tables ('Grouped bys) params ('NotNull 'PGint8)
1001+ -> Expression relations ('Grouped bys) params ('NotNull 'PGint8)
10021002countDistinct = unsafeAggregateDistinct "count"
10031003
10041004-- | synonym for `boolAnd`
@@ -1011,9 +1011,9 @@ countDistinct = unsafeAggregateDistinct "count"
10111011-- :}
10121012-- "every(col)"
10131013every
1014− :: Expression tables 'Ungrouped params (nullity 'PGbool)
1014+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
10151015 -- ^ what to aggregate
1016− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
1016+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
10171017every = unsafeAggregate "every"
10181018
10191019-- | synonym for `boolAndDistinct`
@@ -1026,16 +1026,16 @@ every = unsafeAggregate "every"
10261026-- :}
10271027-- "every(DISTINCT col)"
10281028everyDistinct
1029− :: Expression tables 'Ungrouped params (nullity 'PGbool)
1029+ :: Expression relations 'Ungrouped params (nullity 'PGbool)
10301030 -- ^ what to aggregate
1031− -> Expression tables ('Grouped bys) params (nullity 'PGbool)
1031+ -> Expression relations ('Grouped bys) params (nullity 'PGbool)
10321032everyDistinct = unsafeAggregateDistinct "every"
10331033
10341034-- | minimum and maximum aggregation
10351035max_, min_, maxDistinct, minDistinct
1036− :: Expression tables 'Ungrouped params (nullity ty)
1036+ :: Expression relations 'Ungrouped params (nullity ty)
10371037 -- ^ what to aggregate
1038− -> Expression tables ('Grouped bys) params (nullity ty)
1038+ -> Expression relations ('Grouped bys) params (nullity ty)
10391039max_ = unsafeAggregate "max"
10401040min_ = unsafeAggregate "min"
10411041maxDistinct = unsafeAggregateDistinct "max"
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+3−3
@@ -151,7 +151,7 @@ instance Category (AlignedList p) where
151151single :: p x0 x1 -> AlignedList p x0 x1
152152single step = step :>> Done
153153
154−-- | Run a `Migration` by creating the `MigrationsTable`
154+-- | Run `Migration`s by creating the `MigrationsTable`
155155-- if it does not exist and then in a transaction, for each each `Migration`
156156-- query to see if the `Migration` is executed. If not, then
157157-- execute the `Migration` and insert its row in `MigrationsTable`.
@@ -207,13 +207,13 @@ migrateUp migration =
207207 okResult result
208208 ntuples result
209209
210−-- | Rewind a `Migration` by creating the `MigrationsTable`
210+-- | Rewind `Migration`s by creating the `MigrationsTable`
211211-- if it does not exist and then in a transaction, for each each `Migration`
212212-- query to see if the `Migration` is executed. If it is, then
213213-- rewind the `Migration` and delete its row in `MigrationsTable`.
214214migrateDown
215215 :: MonadBaseControl IO io
216− => AlignedList (Migration io) schema0 schema1 -- ^ migration to rewind
216+ => AlignedList (Migration io) schema0 schema1 -- ^ migrations to rewind
217217 -> PQ
218218 ("schema_migrations" ::: MigrationsTable ': schema1)
219219 ("schema_migrations" ::: MigrationsTable ': schema0)
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+108−108
@@ -364,73 +364,73 @@ SELECT queries
364364-- the intermediate table are actually output.
365365select
366366 :: SListI columns
367− => NP (Aliased (Expression tables grouping params)) (column ': columns)
367+ => NP (Aliased (Expression relations grouping params)) (column ': columns)
368368 -- ^ select list
369− -> TableExpression schema params tables grouping
369+ -> TableExpression schema params relations grouping
370370 -- ^ intermediate virtual table
371371 -> Query schema params (column ': columns)
372−select list tabs = UnsafeQuery $
372+select list rels = UnsafeQuery $
373373 "SELECT"
374374 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
375− <+> renderTableExpression tabs
375+ <+> renderTableExpression rels
376376
377377-- | After the select list has been processed, the result table can
378378-- be subject to the elimination of duplicate rows using `selectDistinct`.
379379selectDistinct
380380 :: SListI columns
381− => NP (Aliased (Expression tables 'Ungrouped params)) (column ': columns)
381+ => NP (Aliased (Expression relations 'Ungrouped params)) (column ': columns)
382382 -- ^ select list
383− -> TableExpression schema params tables 'Ungrouped
383+ -> TableExpression schema params relations 'Ungrouped
384384 -- ^ intermediate virtual table
385385 -> Query schema params (column ': columns)
386−selectDistinct list tabs = UnsafeQuery $
386+selectDistinct list rels = UnsafeQuery $
387387 "SELECT DISTINCT"
388388 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
389− <+> renderTableExpression tabs
389+ <+> renderTableExpression rels
390390
391391-- | The simplest kind of query is `selectStar` which emits all columns
392392-- that the table expression produces.
393393selectStar
394− :: HasUnique table tables columns
395− => TableExpression schema params tables 'Ungrouped
394+ :: HasUnique relation relations columns
395+ => TableExpression schema params relations 'Ungrouped
396396 -- ^ intermediate virtual table
397397 -> Query schema params columns
398−selectStar tabs = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression tabs
398+selectStar rels = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression rels
399399
400400-- | A `selectDistinctStar` emits all columns that the table expression
401401-- produces and eliminates duplicate rows.
402402selectDistinctStar
403− :: HasUnique table tables columns
404− => TableExpression schema params tables 'Ungrouped
403+ :: HasUnique relation relations columns
404+ => TableExpression schema params relations 'Ungrouped
405405 -- ^ intermediate virtual table
406406 -> Query schema params columns
407−selectDistinctStar tabs = UnsafeQuery $
408− "SELECT DISTINCT" <+> "*" <+> renderTableExpression tabs
407+selectDistinctStar rels = UnsafeQuery $
408+ "SELECT DISTINCT" <+> "*" <+> renderTableExpression rels
409409
410410-- | When working with multiple tables, it can also be useful to ask
411411-- for all the columns of a particular table, using `selectDotStar`.
412412selectDotStar
413− :: Has table tables columns
414− => Alias table
413+ :: Has relation relations columns
414+ => Alias relation
415415 -- ^ particular virtual Table
416− -> TableExpression schema params tables 'Ungrouped
416+ -> TableExpression schema params relations 'Ungrouped
417417 -- ^ intermediate virtual table
418418 -> Query schema params columns
419−selectDotStar tab tables = UnsafeQuery $
420− "SELECT" <+> renderAlias tab <> ".*" <+> renderTableExpression tables
419+selectDotStar rel relations = UnsafeQuery $
420+ "SELECT" <+> renderAlias rel <> ".*" <+> renderTableExpression relations
421421
422422-- | A `selectDistinctDotStar` asks for all the columns of a particular table,
423423-- and eliminates duplicate rows.
424424selectDistinctDotStar
425− :: Has table tables columns
426− => Alias table
425+ :: Has relation relations columns
426+ => Alias relation
427427 -- ^ particular virtual Table
428− -> TableExpression schema params tables 'Ungrouped
428+ -> TableExpression schema params relations 'Ungrouped
429429 -- ^ intermediate virtual table
430430 -> Query schema params columns
431−selectDistinctDotStar tab tables = UnsafeQuery $
432− "SELECT DISTINCT" <+> renderAlias tab <> ".*"
433− <+> renderTableExpression tables
431+selectDistinctDotStar rel relations = UnsafeQuery $
432+ "SELECT DISTINCT" <+> renderAlias rel <> ".*"
433+ <+> renderTableExpression relations
434434
435435{-----------------------------------------
436436Table Expressions
@@ -445,13 +445,13 @@ Table Expressions
445445data TableExpression
446446 (schema :: TablesType)
447447 (params :: [NullityType])
448− (tables :: RelationsType)
448+ (relations :: RelationsType)
449449 (grouping :: Grouping)
450450 = TableExpression
451− { fromClause :: FromClause schema params tables
451+ { fromClause :: FromClause schema params relations
452452 -- ^ A table reference that can be a table name, or a derived table such
453453 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
454− , whereClause :: [Condition tables 'Ungrouped params]
454+ , whereClause :: [Condition relations 'Ungrouped params]
455455 -- ^ optional search coditions, combined with `.&&`. After the processing
456456 -- of the `fromClause` is done, each row of the derived virtual table
457457 -- is checked against the search condition. If the result of the
@@ -460,20 +460,20 @@ data TableExpression
460460 -- at least one column of the table generated in the `fromClause`;
461461 -- this is not required, but otherwise the WHERE clause will
462462 -- be fairly useless.
463− , groupByClause :: GroupByClause tables grouping
463+ , groupByClause :: GroupByClause relations grouping
464464 -- ^ The `groupByClause` is used to group together those rows in a table
465465 -- that have the same values in all the columns listed. The order in which
466466 -- the columns are listed does not matter. The effect is to combine each
467467 -- set of rows having common values into one group row that represents all
468468 -- rows in the group. This is done to eliminate redundancy in the output
469469 -- and/or compute aggregates that apply to these groups.
470− , havingClause :: HavingClause tables grouping params
470+ , havingClause :: HavingClause relations grouping params
471471 -- ^ If a table has been grouped using `groupBy`, but only certain groups
472472 -- are of interest, the `havingClause` can be used, much like a
473473 -- `whereClause`, to eliminate groups from the result. Expressions in the
474474 -- `havingClause` can refer both to grouped expressions and to ungrouped
475475 -- expressions (which necessarily involve an aggregate function).
476− , orderByClause :: [SortExpression tables grouping params]
476+ , orderByClause :: [SortExpression relations grouping params]
477477 -- ^ The `orderByClause` is for optional sorting. When more than one
478478 -- `SortExpression` is specified, the later (right) values are used to sort
479479 -- rows that are equal according to the earlier (left) values.
@@ -491,11 +491,11 @@ data TableExpression
491491
492492-- | Render a `TableExpression`
493493renderTableExpression
494− :: TableExpression schema params tables grouping
494+ :: TableExpression schema params relations grouping
495495 -> ByteString
496496renderTableExpression
497− (TableExpression tables whs' grps' hvs' srts' lims' offs') = mconcat
498− [ "FROM ", renderFromClause tables
497+ (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
498+ [ "FROM ", renderFromClause frm'
499499 , renderWheres whs'
500500 , renderGroupByClause grps'
501501 , renderHavingClause hvs'
@@ -525,68 +525,68 @@ renderTableExpression
525525-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
526526-- to match the left-to-right sequencing of their placement in SQL.
527527from
528− :: FromClause schema params tables -- ^ table reference
529− -> TableExpression schema params tables 'Ungrouped
530−from tables = TableExpression tables [] NoGroups NoHaving [] [] []
528+ :: FromClause schema params relations -- ^ table reference
529+ -> TableExpression schema params relations 'Ungrouped
530+from rels = TableExpression rels [] NoGroups NoHaving [] [] []
531531
532532-- | A `where_` is an endomorphism of `TableExpression`s which adds a
533533-- search condition to the `whereClause`.
534534where_
535− :: Condition tables 'Ungrouped params -- ^ filtering condition
536− -> TableExpression schema params tables grouping
537− -> TableExpression schema params tables grouping
538−where_ wh tables = tables {whereClause = wh : whereClause tables}
535+ :: Condition relations 'Ungrouped params -- ^ filtering condition
536+ -> TableExpression schema params relations grouping
537+ -> TableExpression schema params relations grouping
538+where_ wh rels = rels {whereClause = wh : whereClause rels}
539539
540540-- | A `group` is a transformation of `TableExpression`s which switches
541541-- its `Grouping` from `Ungrouped` to `Grouped`. Use @group Nil@ to perform
542542-- a "grand total" aggregation query.
543543group
544544 :: SListI bys
545− => NP (By tables) bys -- ^ grouped columns
546− -> TableExpression schema params tables 'Ungrouped
547− -> TableExpression schema params tables ('Grouped bys)
548−group bys tables = TableExpression
549− { fromClause = fromClause tables
550− , whereClause = whereClause tables
545+ => NP (By relations) bys -- ^ grouped columns
546+ -> TableExpression schema params relations 'Ungrouped
547+ -> TableExpression schema params relations ('Grouped bys)
548+group bys rels = TableExpression
549+ { fromClause = fromClause rels
550+ , whereClause = whereClause rels
551551 , groupByClause = Group bys
552552 , havingClause = Having []
553553 , orderByClause = []
554− , limitClause = limitClause tables
555− , offsetClause = offsetClause tables
554+ , limitClause = limitClause rels
555+ , offsetClause = offsetClause rels
556556 }
557557
558558-- | A `having` is an endomorphism of `TableExpression`s which adds a
559559-- search condition to the `havingClause`.
560560having
561− :: Condition tables ('Grouped bys) params -- ^ having condition
562− -> TableExpression schema params tables ('Grouped bys)
563− -> TableExpression schema params tables ('Grouped bys)
564−having hv tables = tables
565− { havingClause = case havingClause tables of Having hvs -> Having (hv:hvs) }
561+ :: Condition relations ('Grouped bys) params -- ^ having condition
562+ -> TableExpression schema params relations ('Grouped bys)
563+ -> TableExpression schema params relations ('Grouped bys)
564+having hv rels = rels
565+ { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
566566
567567-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
568568-- ordering to the right of the `orderByClause`.
569569orderBy
570− :: [SortExpression tables grouping params] -- ^ sort expressions
571− -> TableExpression schema params tables grouping
572− -> TableExpression schema params tables grouping
573−orderBy srts tables = tables {orderByClause = orderByClause tables ++ srts}
570+ :: [SortExpression relations grouping params] -- ^ sort expressions
571+ -> TableExpression schema params relations grouping
572+ -> TableExpression schema params relations grouping
573+orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
574574
575575-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
576576-- `limitClause`.
577577limit
578578 :: Word64 -- ^ limit parameter
579− -> TableExpression schema params tables grouping
580− -> TableExpression schema params tables grouping
581−limit lim tables = tables {limitClause = lim : limitClause tables}
579+ -> TableExpression schema params relations grouping
580+ -> TableExpression schema params relations grouping
581+limit lim rels = rels {limitClause = lim : limitClause rels}
582582
583583-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
584584-- `offsetClause`.
585585offset
586586 :: Word64 -- ^ offset parameter
587− -> TableExpression schema params tables grouping
588− -> TableExpression schema params tables grouping
589−offset off tables = tables {offsetClause = off : offsetClause tables}
587+ -> TableExpression schema params relations grouping
588+ -> TableExpression schema params relations grouping
589+offset off rels = rels {offsetClause = off : offsetClause rels}
590590
591591{-----------------------------------------
592592FROM clauses
@@ -596,7 +596,7 @@ FROM clauses
596596A `FromClause` can be a table name, or a derived table such
597597as a subquery, a @JOIN@ construct, or complex combinations of these.
598598-}
599−newtype FromClause schema params tables
599+newtype FromClause schema params relations
600600 = UnsafeFromClause { renderFromClause :: ByteString }
601601 deriving (GHC.Generic,Show,Eq,Ord,NFData)
602602
@@ -655,7 +655,7 @@ leftOuterJoin
655655 -- ^ @ON@ condition
656656 -> FromClause schema params left
657657 -- ^ left
658− -> FromClause schema params (Join left (NullifyTables right))
658+ -> FromClause schema params (Join left (NullifyRelations right))
659659leftOuterJoin right on left = UnsafeFromClause $
660660 renderFromClause left <+> "LEFT OUTER JOIN" <+> renderFromClause right
661661 <+> "ON" <+> renderExpression on
@@ -673,7 +673,7 @@ rightOuterJoin
673673 -- ^ @ON@ condition
674674 -> FromClause schema params left
675675 -- ^ left
676− -> FromClause schema params (Join (NullifyTables left) right)
676+ -> FromClause schema params (Join (NullifyRelations left) right)
677677rightOuterJoin right on left = UnsafeFromClause $
678678 renderFromClause left <+> "RIGHT OUTER JOIN" <+> renderFromClause right
679679 <+> "ON" <+> renderExpression on
@@ -693,7 +693,7 @@ fullOuterJoin
693693 -> FromClause schema params left
694694 -- ^ left
695695 -> FromClause schema params
696− (Join (NullifyTables left) (NullifyTables right))
696+ (Join (NullifyRelations left) (NullifyRelations right))
697697fullOuterJoin right on left = UnsafeFromClause $
698698 renderFromClause left <+> "FULL OUTER JOIN" <+> renderFromClause right
699699 <+> "ON" <+> renderExpression on
@@ -708,40 +708,40 @@ Grouping
708708-- column @col@; otherwise @By2 (\#tab \! \#col)@ will reference a table
709709-- qualified column @tab.col@.
710710data By
711− (tables :: RelationsType)
711+ (relations :: RelationsType)
712712 (by :: (Symbol,Symbol)) where
713713 By
714− :: (HasUnique table tables columns, Has column columns ty)
714+ :: (HasUnique relation relations columns, Has column columns ty)
715715 => Alias column
716− -> By tables '(table, column)
716+ -> By relations '(relation, column)
717717 By2
718− :: (Has table tables columns, Has column columns ty)
719− => (Alias table, Alias column)
720− -> By tables '(table, column)
721−deriving instance Show (By tables by)
722−deriving instance Eq (By tables by)
723−deriving instance Ord (By tables by)
718+ :: (Has relation relations columns, Has column columns ty)
719+ => (Alias relation, Alias column)
720+ -> By relations '(relation, column)
721+deriving instance Show (By relations by)
722+deriving instance Eq (By relations by)
723+deriving instance Ord (By relations by)
724724
725725-- | Renders a `By`.
726−renderBy :: By tables tabcolty -> ByteString
726+renderBy :: By relations by -> ByteString
727727renderBy = \case
728728 By column -> renderAlias column
729− By2 (tab, column) -> renderAlias tab <> "." <> renderAlias column
729+ By2 (rel, column) -> renderAlias rel <> "." <> renderAlias column
730730
731731-- | A `GroupByClause` indicates the `Grouping` of a `TableExpression`.
732732-- A `NoGroups` indicates `Ungrouped` while a `Group` indicates `Grouped`.
733733-- @NoGroups@ is distinguised from @Group Nil@ since no aggregation can be
734734-- done on @NoGroups@ while all output `Expression`s must be aggregated
735735-- in @Group Nil@.
736−data GroupByClause tables grouping where
737− NoGroups :: GroupByClause tables 'Ungrouped
736+data GroupByClause relations grouping where
737+ NoGroups :: GroupByClause relations 'Ungrouped
738738 Group
739739 :: SListI bys
740− => NP (By tables) bys
741− -> GroupByClause tables ('Grouped bys)
740+ => NP (By relations) bys
741+ -> GroupByClause relations ('Grouped bys)
742742
743743-- | Renders a `GroupByClause`.
744−renderGroupByClause :: GroupByClause tables grouping -> ByteString
744+renderGroupByClause :: GroupByClause relations grouping -> ByteString
745745renderGroupByClause = \case
746746 NoGroups -> ""
747747 Group Nil -> ""
@@ -751,17 +751,17 @@ renderGroupByClause = \case
751751-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
752752-- `TableExpression` must use `Having` whose conditions are combined with
753753-- `.&&`.
754−data HavingClause tables grouping params where
755− NoHaving :: HavingClause tables 'Ungrouped params
754+data HavingClause relations grouping params where
755+ NoHaving :: HavingClause relations 'Ungrouped params
756756 Having
757− :: [Condition tables ('Grouped bys) params]
758− -> HavingClause tables ('Grouped bys) params
759−deriving instance Show (HavingClause tables grouping params)
760−deriving instance Eq (HavingClause tables grouping params)
761−deriving instance Ord (HavingClause tables grouping params)
757+ :: [Condition relations ('Grouped bys) params]
758+ -> HavingClause relations ('Grouped bys) params
759+deriving instance Show (HavingClause relations grouping params)
760+deriving instance Eq (HavingClause relations grouping params)
761+deriving instance Ord (HavingClause relations grouping params)
762762
763763-- | Render a `HavingClause`.
764−renderHavingClause :: HavingClause tables grouping params -> ByteString
764+renderHavingClause :: HavingClause relations grouping params -> ByteString
765765renderHavingClause = \case
766766 NoHaving -> ""
767767 Having [] -> ""
@@ -780,29 +780,29 @@ Sorting
780780-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
781781-- determine whether nulls appear before or after non-null values in the sort
782782-- ordering of a `Null` result column.
783−data SortExpression tables grouping params where
783+data SortExpression relations grouping params where
784784 Asc
785− :: Expression tables grouping params ('NotNull ty)
786− -> SortExpression tables grouping params
785+ :: Expression relations grouping params ('NotNull ty)
786+ -> SortExpression relations grouping params
787787 Desc
788− :: Expression tables grouping params ('NotNull ty)
789− -> SortExpression tables grouping params
788+ :: Expression relations grouping params ('NotNull ty)
789+ -> SortExpression relations grouping params
790790 AscNullsFirst
791− :: Expression tables grouping params ('Null ty)
792− -> SortExpression tables grouping params
791+ :: Expression relations grouping params ('Null ty)
792+ -> SortExpression relations grouping params
793793 AscNullsLast
794− :: Expression tables grouping params ('Null ty)
795− -> SortExpression tables grouping params
794+ :: Expression relations grouping params ('Null ty)
795+ -> SortExpression relations grouping params
796796 DescNullsFirst
797− :: Expression tables grouping params ('Null ty)
798− -> SortExpression tables grouping params
797+ :: Expression relations grouping params ('Null ty)
798+ -> SortExpression relations grouping params
799799 DescNullsLast
800− :: Expression tables grouping params ('Null ty)
801− -> SortExpression tables grouping params
802−deriving instance Show (SortExpression tables grouping params)
800+ :: Expression relations grouping params ('Null ty)
801+ -> SortExpression relations grouping params
802+deriving instance Show (SortExpression relations grouping params)
803803
804804-- | Render a `SortExpression`.
805−renderSortExpression :: SortExpression tables grouping params -> ByteString
805+renderSortExpression :: SortExpression relations grouping params -> ByteString
806806renderSortExpression = \case
807807 Asc expression -> renderExpression expression <+> "ASC"
808808 Desc expression -> renderExpression expression <+> "DESC"
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+12−12
@@ -75,8 +75,8 @@ module Squeal.PostgreSQL.Schema
7575 , AllNotNull
7676 , NotAllNull
7777 , NullifyType
78− , NullifyColumns
79− , NullifyTables
78+ , NullifyRelation
79+ , NullifyRelations
8080 , Join
8181 , Create
8282 , AddColumn
@@ -434,19 +434,19 @@ type family NullifyType (ty :: NullityType) :: NullityType where
434434 NullifyType ('Null ty) = 'Null ty
435435 NullifyType ('NotNull ty) = 'Null ty
436436
437−-- | `NullifyColumns` is an idempotent that nullifies a `ColumnsType`.
438−type family NullifyColumns (columns :: RelationType) :: RelationType where
439− NullifyColumns '[] = '[]
440− NullifyColumns (column ::: ty ': columns) =
441− column ::: NullifyType ty ': NullifyColumns columns
437+-- | `NullifyRelation` is an idempotent that nullifies a `ColumnsType`.
438+type family NullifyRelation (columns :: RelationType) :: RelationType where
439+ NullifyRelation '[] = '[]
440+ NullifyRelation (column ::: ty ': columns) =
441+ column ::: NullifyType ty ': NullifyRelation columns
442442
443−-- | `NullifyTables` is an idempotent that nullifies a `RelationsType`
443+-- | `NullifyRelations` is an idempotent that nullifies a `RelationsType`
444444-- used to nullify the left or right hand side of an outer join
445445-- in a `Squeal.PostgreSQL.Query.FromClause`.
446−type family NullifyTables (tables :: RelationsType) :: RelationsType where
447− NullifyTables '[] = '[]
448− NullifyTables (table ::: columns ': tables) =
449− table ::: NullifyColumns columns ': NullifyTables tables
446+type family NullifyRelations (tables :: RelationsType) :: RelationsType where
447+ NullifyRelations '[] = '[]
448+ NullifyRelations (table ::: columns ': tables) =
449+ table ::: NullifyRelation columns ': NullifyRelations tables
450450
451451-- | `Join` is simply promoted `++` and is used in @JOIN@s in
452452-- `Squeal.PostgreSQL.Query.FromClause`s.