@@ -217,7 +217,7 @@ values from primitive expression using arithmetic, logical,
217217and other operations.
218218-}
219219newtype Expression
220− (schema :: SchemaType)
220+ (db :: DBType)
221221 (from :: FromType)
222222 (grouping :: Grouping)
223223 (params :: [NullityType])
@@ -225,7 +225,7 @@ newtype Expression
225225 = UnsafeExpression { renderExpression :: ByteString }
226226 deriving (GHC.Generic,Show,Eq,Ord,NFData)
227227
228−instance RenderSQL (Expression schema from grouping params ty) where
228+instance RenderSQL (Expression db from grouping params ty) where
229229 renderSQL = renderExpression
230230
231231{- | A `HasParameter` constraint is used to indicate a value that is
@@ -238,7 +238,7 @@ refer to the out-of-line data values.
238238-}
239239class KnownNat n => HasParameter
240240 (n :: Nat)
241− (schema :: SchemaType)
241+ (db :: DBType)
242242 (params :: [NullityType])
243243 (ty :: NullityType)
244244 | n params -> ty where
@@ -248,8 +248,8 @@ class KnownNat n => HasParameter
248248 -- >>> printSQL expr
249249 -- ($1 :: int4)
250250 parameter
251− :: TypeExpression schema ty
252− -> Expression schema from grouping params ty
251+ :: TypeExpression db ty
252+ -> Expression db from grouping params ty
253253 parameter ty = UnsafeExpression $ parenthesized $
254254 "$" <> renderNat @n <+> "::"
255255 <+> renderTypeExpression ty
@@ -264,34 +264,34 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
264264-- >>> printSQL expr
265265-- ($1 :: int4)
266266param
267− :: forall n schema params from grouping ty
268− . (PGTyped schema ty, HasParameter n schema params ty)
269− => Expression schema from grouping params ty -- ^ param
267+ :: forall n db params from grouping ty
268+ . (PGTyped db ty, HasParameter n db params ty)
269+ => Expression db from grouping params ty -- ^ param
270270param = parameter @n pgtype
271271
272272instance (HasUnique table from columns, Has column columns ty)
273− => IsLabel column (Expression schema from 'Ungrouped params ty) where
273+ => IsLabel column (Expression db from 'Ungrouped params ty) where
274274 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
275275instance (HasUnique table from columns, Has column columns ty)
276276 => IsLabel column
277− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
277+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
278278 fromLabel = fromLabel @column `As` Alias @column
279279instance (HasUnique table from columns, Has column columns ty)
280280 => IsLabel column
281− (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
281+ (NP (Aliased (Expression db from 'Ungrouped params)) '[column ::: ty]) where
282282 fromLabel = fromLabel @column :* Nil
283283
284284instance (Has table from columns, Has column columns ty)
285− => IsQualified table column (Expression schema from 'Ungrouped params ty) where
285+ => IsQualified table column (Expression db from 'Ungrouped params ty) where
286286 table ! column = UnsafeExpression $
287287 renderAlias table <> "." <> renderAlias column
288288instance (Has table from columns, Has column columns ty)
289289 => IsQualified table column
290− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
290+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
291291 table ! column = table ! column `As` column
292292instance (Has table from columns, Has column columns ty)
293293 => IsQualified table column
294− (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
294+ (NP (Aliased (Expression db from 'Ungrouped params)) '[column ::: ty]) where
295295 table ! column = table ! column :* Nil
296296
297297instance
@@ -299,14 +299,14 @@ instance
299299 , Has column columns ty
300300 , GroupedBy table column bys
301301 ) => IsLabel column
302− (Expression schema from ('Grouped bys) params ty) where
302+ (Expression db from ('Grouped bys) params ty) where
303303 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
304304instance
305305 ( HasUnique table from columns
306306 , Has column columns ty
307307 , GroupedBy table column bys
308308 ) => IsLabel column
309− ( Aliased (Expression schema from ('Grouped bys) params)
309+ ( Aliased (Expression db from ('Grouped bys) params)
310310 (column ::: ty) ) where
311311 fromLabel = fromLabel @column `As` Alias @column
312312instance
@@ -314,7 +314,7 @@ instance
314314 , Has column columns ty
315315 , GroupedBy table column bys
316316 ) => IsLabel column
317− ( NP (Aliased (Expression schema from ('Grouped bys) params))
317+ ( NP (Aliased (Expression db from ('Grouped bys) params))
318318 '[column ::: ty] ) where
319319 fromLabel = fromLabel @column :* Nil
320320
@@ -323,7 +323,7 @@ instance
323323 , Has column columns ty
324324 , GroupedBy table column bys
325325 ) => IsQualified table column
326− (Expression schema from ('Grouped bys) params ty) where
326+ (Expression db from ('Grouped bys) params ty) where
327327 table ! column = UnsafeExpression $
328328 renderAlias table <> "." <> renderAlias column
329329instance
@@ -331,7 +331,7 @@ instance
331331 , Has column columns ty
332332 , GroupedBy table column bys
333333 ) => IsQualified table column
334− (Aliased (Expression schema from ('Grouped bys) params)
334+ (Aliased (Expression db from ('Grouped bys) params)
335335 (column ::: ty)) where
336336 table ! column = table ! column `As` column
337337instance
@@ -339,7 +339,7 @@ instance
339339 , Has column columns ty
340340 , GroupedBy table column bys
341341 ) => IsQualified table column
342− ( NP (Aliased (Expression schema from ('Grouped bys) params))
342+ ( NP (Aliased (Expression db from ('Grouped bys) params))
343343 '[column ::: ty]) where
344344 table ! column = table ! column :* Nil
345345
@@ -347,7 +347,7 @@ instance
347347--
348348-- >>> printSQL null_
349349-- NULL
350−null_ :: Expression schema rels grouping params ('Null ty)
350+null_ :: Expression db rels grouping params ('Null ty)
351351null_ = UnsafeExpression "NULL"
352352
353353-- | analagous to `Just`
@@ -355,8 +355,8 @@ null_ = UnsafeExpression "NULL"
355355-- >>> printSQL $ notNull true
356356-- TRUE
357357notNull
358− :: Expression schema rels grouping params ('NotNull ty)
359− -> Expression schema rels grouping params ('Null ty)
358+ :: Expression db rels grouping params ('NotNull ty)
359+ -> Expression db rels grouping params ('Null ty)
360360notNull = UnsafeExpression . renderExpression
361361
362362-- | return the leftmost value which is not NULL
@@ -364,11 +364,11 @@ notNull = UnsafeExpression . renderExpression
364364-- >>> printSQL $ coalesce [null_, true] false
365365-- COALESCE(NULL, TRUE, FALSE)
366366coalesce
367− :: [Expression schema from grouping params ('Null ty)]
367+ :: [Expression db from grouping params ('Null ty)]
368368 -- ^ @NULL@s may be present
369− -> Expression schema from grouping params ('NotNull ty)
369+ -> Expression db from grouping params ('NotNull ty)
370370 -- ^ @NULL@ is absent
371− -> Expression schema from grouping params ('NotNull ty)
371+ -> Expression db from grouping params ('NotNull ty)
372372coalesce nullxs notNullx = UnsafeExpression $
373373 "COALESCE" <> parenthesized (commaSeparated
374374 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -378,26 +378,26 @@ coalesce nullxs notNullx = UnsafeExpression $
378378-- >>> printSQL $ fromNull true null_
379379-- COALESCE(NULL, TRUE)
380380fromNull
381− :: Expression schema from grouping params ('NotNull ty)
381+ :: Expression db from grouping params ('NotNull ty)
382382 -- ^ what to convert @NULL@ to
383− -> Expression schema from grouping params ('Null ty)
384− -> Expression schema from grouping params ('NotNull ty)
383+ -> Expression db from grouping params ('Null ty)
384+ -> Expression db from grouping params ('NotNull ty)
385385fromNull notNullx nullx = coalesce [nullx] notNullx
386386
387387-- | >>> printSQL $ null_ & isNull
388388-- NULL IS NULL
389389isNull
390− :: Expression schema from grouping params ('Null ty)
390+ :: Expression db from grouping params ('Null ty)
391391 -- ^ possibly @NULL@
392− -> Condition schema from grouping params
392+ -> Condition db from grouping params
393393isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
394394
395395-- | >>> printSQL $ null_ & isNotNull
396396-- NULL IS NOT NULL
397397isNotNull
398− :: Expression schema from grouping params ('Null ty)
398+ :: Expression db from grouping params ('Null ty)
399399 -- ^ possibly @NULL@
400− -> Condition schema from grouping params
400+ -> Condition db from grouping params
401401isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
402402
403403-- | analagous to `maybe` using @IS NULL@
@@ -405,13 +405,13 @@ isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
405405-- >>> printSQL $ matchNull true not_ null_
406406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407407matchNull
408− :: Expression schema from grouping params (nullty)
408+ :: Expression db from grouping params (nullty)
409409 -- ^ what to convert @NULL@ to
410− -> ( Expression schema from grouping params ('NotNull ty)
411− -> Expression schema from grouping params (nullty) )
410+ -> ( Expression db from grouping params ('NotNull ty)
411+ -> Expression db from grouping params (nullty) )
412412 -- ^ function to perform when @NULL@ is absent
413− -> Expression schema from grouping params ('Null ty)
414− -> Expression schema from grouping params (nullty)
413+ -> Expression db from grouping params ('Null ty)
414+ -> Expression db from grouping params (nullty)
415415matchNull y f x = ifThenElse (isNull x) y
416416 (f (UnsafeExpression (renderExpression x)))
417417
@@ -419,25 +419,25 @@ matchNull y f x = ifThenElse (isNull x) y
419419`nullIf` gives @NULL@.
420420
421421>>> :set -XTypeApplications -XDataKinds
422−>>> let expr = nullIf false (param @1) :: Expression schema rels grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
422+>>> let expr = nullIf false (param @1) :: Expression db rels grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
423423>>> printSQL expr
424424NULL IF (FALSE, ($1 :: bool))
425425-}
426426nullIf
427− :: Expression schema from grouping params ('NotNull ty)
427+ :: Expression db from grouping params ('NotNull ty)
428428 -- ^ @NULL@ is absent
429− -> Expression schema from grouping params ('NotNull ty)
429+ -> Expression db from grouping params ('NotNull ty)
430430 -- ^ @NULL@ is absent
431− -> Expression schema from grouping params ('Null ty)
431+ -> Expression db from grouping params ('Null ty)
432432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
433433 (renderExpression x <> ", " <> renderExpression y)
434434
435435-- | >>> printSQL $ array [null_, false, true]
436436-- ARRAY[NULL, FALSE, TRUE]
437437array
438− :: [Expression schema from grouping params ty]
438+ :: [Expression db from grouping params ty]
439439 -- ^ array elements
440− -> Expression schema from grouping params (nullity ('PGvararray ty))
440+ -> Expression db from grouping params (nullity ('PGvararray ty))
441441array xs = UnsafeExpression $
442442 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
443443
@@ -445,13 +445,13 @@ array xs = UnsafeExpression $
445445-- (ARRAY[NULL, FALSE, TRUE])[2]
446446index
447447 :: Word64 -- ^ index
448− -> Expression schema from grouping params (nullity ('PGvararray ty)) -- ^ array
449− -> Expression schema from grouping params (NullifyType ty)
448+ -> Expression db from grouping params (nullity ('PGvararray ty)) -- ^ array
449+ -> Expression db from grouping params (NullifyType ty)
450450index n expr = UnsafeExpression $
451451 parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
452452
453453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
454− (Expression schema from grouping params (nullity ('PGenum labels))) where
454+ (Expression db from grouping params (nullity ('PGenum labels))) where
455455 label = UnsafeExpression $ renderLabel (PGlabel @label)
456456
457457-- | A row constructor is an expression that builds a row value
@@ -468,9 +468,9 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
468468-- ROW(0, 1)
469469row
470470 :: SListI row
471− => NP (Aliased (Expression schema from grouping params)) row
471+ => NP (Aliased (Expression db from grouping params)) row
472472 -- ^ zero or more expressions for the row field values
473− -> Expression schema from grouping params (nullity ('PGcomposite row))
473+ -> Expression db from grouping params (nullity ('PGcomposite row))
474474row exprs = UnsafeExpression $ "ROW" <> parenthesized
475475 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
476476
@@ -484,21 +484,22 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
484484-- >>> printSQL $ i & field #complex #imaginary
485485-- (ROW(0, 1)::"complex")."imaginary"
486486field
487− :: (Has tydef schema ('Typedef ('PGcomposite row)), Has field row ty)
488− => Alias tydef -- ^ row type
487+ :: ( HasQualified sch tydef db schema ('Typedef ('PGcomposite row))
488+ , Has field row ty)
489+ => QualifiedAlias sch tydef -- ^ row type
489490 -> Alias field -- ^ field name
490− -> Expression schema from grouping params ('NotNull ('PGcomposite row))
491− -> Expression schema from grouping params ty
491+ -> Expression db from grouping params ('NotNull ('PGcomposite row))
492+ -> Expression db from grouping params ty
492493field td fld expr = UnsafeExpression $
493− parenthesized (renderExpression expr <> "::" <> renderAlias td)
494+ parenthesized (renderExpression expr <> "::" <> renderQualifiedAlias td)
494495 <> "." <> renderAlias fld
495496
496497instance Semigroup
497− (Expression schema from grouping params (nullity ('PGvararray ty))) where
498+ (Expression db from grouping params (nullity ('PGvararray ty))) where
498499 (<>) = unsafeBinaryOp "||"
499500
500501instance Monoid
501− (Expression schema from grouping params (nullity ('PGvararray ty))) where
502+ (Expression db from grouping params (nullity ('PGvararray ty))) where
502503 mempty = array []
503504 mappend = (<>)
504505
@@ -506,22 +507,22 @@ instance Monoid
506507-- >>> printSQL expr
507508-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
508509greatest
509− :: Expression schema from grouping params (nullty)
510+ :: Expression db from grouping params (nullty)
510511 -- ^ needs at least 1 argument
511− -> [Expression schema from grouping params (nullty)]
512+ -> [Expression db from grouping params (nullty)]
512513 -- ^ or more
513− -> Expression schema from grouping params (nullty)
514+ -> Expression db from grouping params (nullty)
514515greatest x xs = UnsafeExpression $ "GREATEST("
515516 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
516517
517518-- | >>> printSQL $ least currentTimestamp [null_]
518519-- LEAST(CURRENT_TIMESTAMP, NULL)
519520least
520− :: Expression schema from grouping params (nullty)
521+ :: Expression db from grouping params (nullty)
521522 -- ^ needs at least 1 argument
522− -> [Expression schema from grouping params (nullty)]
523+ -> [Expression db from grouping params (nullty)]
523524 -- ^ or more
524− -> Expression schema from grouping params (nullty)
525+ -> Expression db from grouping params (nullty)
525526least x xs = UnsafeExpression $ "LEAST("
526527 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
527528
@@ -530,9 +531,9 @@ least x xs = UnsafeExpression $ "LEAST("
530531unsafeBinaryOp
531532 :: ByteString
532533 -- ^ operator
533− -> Expression schema from grouping params (ty0)
534− -> Expression schema from grouping params (ty1)
535− -> Expression schema from grouping params (ty2)
534+ -> Expression db from grouping params (ty0)
535+ -> Expression db from grouping params (ty1)
536+ -> Expression db from grouping params (ty2)
536537unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
537538 renderExpression x <+> op <+> renderExpression y
538539
@@ -541,8 +542,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
541542unsafeUnaryOp
542543 :: ByteString
543544 -- ^ operator
544− -> Expression schema from grouping params (ty0)
545− -> Expression schema from grouping params (ty1)
545+ -> Expression db from grouping params (ty0)
546+ -> Expression db from grouping params (ty1)
546547unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
547548 op <+> renderExpression x
548549
@@ -551,8 +552,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
551552unsafeFunction
552553 :: ByteString
553554 -- ^ function
554− -> Expression schema from grouping params (xty)
555− -> Expression schema from grouping params (yty)
555+ -> Expression db from grouping params (xty)
556+ -> Expression db from grouping params (yty)
556557unsafeFunction fun x = UnsafeExpression $
557558 fun <> parenthesized (renderExpression x)
558559
@@ -561,13 +562,13 @@ unsafeVariadicFunction
561562 :: SListI elems
562563 => ByteString
563564 -- ^ function
564− -> NP (Expression schema from grouping params) elems
565− -> Expression schema from grouping params ret
565+ -> NP (Expression db from grouping params) elems
566+ -> Expression db from grouping params ret
566567unsafeVariadicFunction fun x = UnsafeExpression $
567568 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
568569
569570instance ty `In` PGNum
570− => Num (Expression schema from grouping params (nullity ty)) where
571+ => Num (Expression db from grouping params (nullity ty)) where
571572 (+) = unsafeBinaryOp "+"
572573 (-) = unsafeBinaryOp "-"
573574 (*) = unsafeBinaryOp "*"
@@ -579,12 +580,12 @@ instance ty `In` PGNum
579580 . show
580581
581582instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
582− (Expression schema from grouping params (nullity ty)) where
583+ (Expression db from grouping params (nullity ty)) where
583584 (/) = unsafeBinaryOp "/"
584585 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
585586
586587instance (ty `In` PGNum, ty `In` PGFloating) => Floating
587− (Expression schema from grouping params (nullity ty)) where
588+ (Expression db from grouping params (nullity ty)) where
588589 pi = UnsafeExpression "pi()"
589590 exp = unsafeFunction "exp"
590591 log = unsafeFunction "ln"
@@ -607,18 +608,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
607608
608609-- | >>> :{
609610-- let
610−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
611+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
611612-- expression = atan2_ pi 2
612613-- in printSQL expression
613614-- :}
614615-- atan2(pi(), 2)
615616atan2_
616617 :: float `In` PGFloating
617− => Expression schema from grouping params (nullity float)
618+ => Expression db from grouping params (nullity float)
618619 -- ^ numerator
619− -> Expression schema from grouping params (nullity float)
620+ -> Expression db from grouping params (nullity float)
620621 -- ^ denominator
621− -> Expression schema from grouping params (nullity float)
622+ -> Expression db from grouping params (nullity float)
622623atan2_ y x = UnsafeExpression $
623624 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
624625
@@ -629,11 +630,11 @@ atan2_ y x = UnsafeExpression $
629630-- | >>> printSQL $ true & cast int4
630631-- (TRUE :: int4)
631632cast
632− :: TypeExpression schema ty1
633+ :: TypeExpression db ty1
633634 -- ^ type to cast as
634− -> Expression schema from grouping params ty0
635+ -> Expression db from grouping params ty0
635636 -- ^ value to convert
636− -> Expression schema from grouping params ty1
637+ -> Expression db from grouping params ty1
637638cast ty x = UnsafeExpression $ parenthesized $
638639 renderExpression x <+> "::" <+> renderTypeExpression ty
639640
@@ -641,136 +642,136 @@ cast ty x = UnsafeExpression $ parenthesized $
641642--
642643-- >>> :{
643644-- let
644−-- expression :: Expression schema from grouping params (nullity 'PGint2)
645+-- expression :: Expression db from grouping params (nullity 'PGint2)
645646-- expression = 5 `quot_` 2
646647-- in printSQL expression
647648-- :}
648649-- (5 / 2)
649650quot_
650651 :: int `In` PGIntegral
651− => Expression schema from grouping params (nullity int)
652+ => Expression db from grouping params (nullity int)
652653 -- ^ numerator
653− -> Expression schema from grouping params (nullity int)
654+ -> Expression db from grouping params (nullity int)
654655 -- ^ denominator
655− -> Expression schema from grouping params (nullity int)
656+ -> Expression db from grouping params (nullity int)
656657quot_ = unsafeBinaryOp "/"
657658
658659-- | remainder upon integer division
659660--
660661-- >>> :{
661662-- let
662−-- expression :: Expression schema from grouping params (nullity 'PGint2)
663+-- expression :: Expression db from grouping params (nullity 'PGint2)
663664-- expression = 5 `rem_` 2
664665-- in printSQL expression
665666-- :}
666667-- (5 % 2)
667668rem_
668669 :: int `In` PGIntegral
669− => Expression schema from grouping params (nullity int)
670+ => Expression db from grouping params (nullity int)
670671 -- ^ numerator
671− -> Expression schema from grouping params (nullity int)
672+ -> Expression db from grouping params (nullity int)
672673 -- ^ denominator
673− -> Expression schema from grouping params (nullity int)
674+ -> Expression db from grouping params (nullity int)
674675rem_ = unsafeBinaryOp "%"
675676
676677-- | >>> :{
677678-- let
678−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
679+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
679680-- expression = trunc pi
680681-- in printSQL expression
681682-- :}
682683-- trunc(pi())
683684trunc
684685 :: frac `In` PGFloating
685− => Expression schema from grouping params (nullity frac)
686+ => Expression db from grouping params (nullity frac)
686687 -- ^ fractional number
687− -> Expression schema from grouping params (nullity frac)
688+ -> Expression db from grouping params (nullity frac)
688689trunc = unsafeFunction "trunc"
689690
690691-- | >>> :{
691692-- let
692−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
693+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
693694-- expression = round_ pi
694695-- in printSQL expression
695696-- :}
696697-- round(pi())
697698round_
698699 :: frac `In` PGFloating
699− => Expression schema from grouping params (nullity frac)
700+ => Expression db from grouping params (nullity frac)
700701 -- ^ fractional number
701− -> Expression schema from grouping params (nullity frac)
702+ -> Expression db from grouping params (nullity frac)
702703round_ = unsafeFunction "round"
703704
704705-- | >>> :{
705706-- let
706−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
707+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
707708-- expression = ceiling_ pi
708709-- in printSQL expression
709710-- :}
710711-- ceiling(pi())
711712ceiling_
712713 :: frac `In` PGFloating
713− => Expression schema from grouping params (nullity frac)
714+ => Expression db from grouping params (nullity frac)
714715 -- ^ fractional number
715− -> Expression schema from grouping params (nullity frac)
716+ -> Expression db from grouping params (nullity frac)
716717ceiling_ = unsafeFunction "ceiling"
717718
718719-- | A `Condition` is an `Expression`, which can evaluate
719720-- to `true`, `false` or `null_`. This is because SQL uses
720721-- a three valued logic.
721−type Condition schema from grouping params =
722− Expression schema from grouping params ('Null 'PGbool)
722+type Condition db from grouping params =
723+ Expression db from grouping params ('Null 'PGbool)
723724
724725-- | >>> printSQL true
725726-- TRUE
726−true :: Expression schema from grouping params (nullity 'PGbool)
727+true :: Expression db from grouping params (nullity 'PGbool)
727728true = UnsafeExpression "TRUE"
728729
729730-- | >>> printSQL false
730731-- FALSE
731−false :: Expression schema from grouping params (nullity 'PGbool)
732+false :: Expression db from grouping params (nullity 'PGbool)
732733false = UnsafeExpression "FALSE"
733734
734735-- | >>> printSQL $ not_ true
735736-- (NOT TRUE)
736737not_
737− :: Expression schema from grouping params (nullity 'PGbool)
738− -> Expression schema from grouping params (nullity 'PGbool)
738+ :: Expression db from grouping params (nullity 'PGbool)
739+ -> Expression db from grouping params (nullity 'PGbool)
739740not_ = unsafeUnaryOp "NOT"
740741
741742-- | >>> printSQL $ true .&& false
742743-- (TRUE AND FALSE)
743744(.&&)
744− :: Expression schema from grouping params (nullity 'PGbool)
745− -> Expression schema from grouping params (nullity 'PGbool)
746− -> Expression schema from grouping params (nullity 'PGbool)
745+ :: Expression db from grouping params (nullity 'PGbool)
746+ -> Expression db from grouping params (nullity 'PGbool)
747+ -> Expression db from grouping params (nullity 'PGbool)
747748infixr 3 .&&
748749(.&&) = unsafeBinaryOp "AND"
749750
750751-- | >>> printSQL $ true .|| false
751752-- (TRUE OR FALSE)
752753(.||)
753− :: Expression schema from grouping params (nullity 'PGbool)
754− -> Expression schema from grouping params (nullity 'PGbool)
755− -> Expression schema from grouping params (nullity 'PGbool)
754+ :: Expression db from grouping params (nullity 'PGbool)
755+ -> Expression db from grouping params (nullity 'PGbool)
756+ -> Expression db from grouping params (nullity 'PGbool)
756757infixr 2 .||
757758(.||) = unsafeBinaryOp "OR"
758759
759760-- | >>> :{
760761-- let
761−-- expression :: Expression schema from grouping params (nullity 'PGint2)
762+-- expression :: Expression db from grouping params (nullity 'PGint2)
762763-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
763764-- in printSQL expression
764765-- :}
765766-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
766767caseWhenThenElse
767− :: [ ( Condition schema from grouping params
768− , Expression schema from grouping params ty
768+ :: [ ( Condition db from grouping params
769+ , Expression db from grouping params ty
769770 ) ]
770771 -- ^ whens and thens
771− -> Expression schema from grouping params ty
772+ -> Expression db from grouping params ty
772773 -- ^ else
773− -> Expression schema from grouping params ty
774+ -> Expression db from grouping params ty
774775caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
775776 [ "CASE"
776777 , mconcat
@@ -786,16 +787,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
786787
787788-- | >>> :{
788789-- let
789−-- expression :: Expression schema from grouping params (nullity 'PGint2)
790+-- expression :: Expression db from grouping params (nullity 'PGint2)
790791-- expression = ifThenElse true 1 0
791792-- in printSQL expression
792793-- :}
793794-- CASE WHEN TRUE THEN 1 ELSE 0 END
794795ifThenElse
795− :: Condition schema from grouping params
796− -> Expression schema from grouping params ty -- ^ then
797− -> Expression schema from grouping params ty -- ^ else
798− -> Expression schema from grouping params ty
796+ :: Condition db from grouping params
797+ -> Expression db from grouping params ty -- ^ then
798+ -> Expression db from grouping params ty -- ^ else
799+ -> Expression db from grouping params ty
799800ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
800801
801802-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -804,85 +805,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
804805-- >>> printSQL $ true .== null_
805806-- (TRUE = NULL)
806807(.==)
807− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
808− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
809− -> Condition schema from grouping params
808+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
809+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
810+ -> Condition db from grouping params
810811(.==) = unsafeBinaryOp "="
811812infix 4 .==
812813
813814-- | >>> printSQL $ true ./= null_
814815-- (TRUE <> NULL)
815816(./=)
816− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
817− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
818− -> Condition schema from grouping params
817+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
818+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
819+ -> Condition db from grouping params
819820(./=) = unsafeBinaryOp "<>"
820821infix 4 ./=
821822
822823-- | >>> printSQL $ true .>= null_
823824-- (TRUE >= NULL)
824825(.>=)
825− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
826− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
827− -> Condition schema from grouping params
826+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
827+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
828+ -> Condition db from grouping params
828829(.>=) = unsafeBinaryOp ">="
829830infix 4 .>=
830831
831832-- | >>> printSQL $ true .< null_
832833-- (TRUE < NULL)
833834(.<)
834− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
835− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
836− -> Condition schema from grouping params
835+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
836+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
837+ -> Condition db from grouping params
837838(.<) = unsafeBinaryOp "<"
838839infix 4 .<
839840
840841-- | >>> printSQL $ true .<= null_
841842-- (TRUE <= NULL)
842843(.<=)
843− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
844− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
845− -> Condition schema from grouping params
844+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
845+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
846+ -> Condition db from grouping params
846847(.<=) = unsafeBinaryOp "<="
847848infix 4 .<=
848849
849850-- | >>> printSQL $ true .> null_
850851-- (TRUE > NULL)
851852(.>)
852− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
853− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
854− -> Condition schema from grouping params
853+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
854+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
855+ -> Condition db from grouping params
855856(.>) = unsafeBinaryOp ">"
856857infix 4 .>
857858
858859-- | >>> printSQL currentDate
859860-- CURRENT_DATE
860861currentDate
861− :: Expression schema from grouping params (nullity 'PGdate)
862+ :: Expression db from grouping params (nullity 'PGdate)
862863currentDate = UnsafeExpression "CURRENT_DATE"
863864
864865-- | >>> printSQL currentTime
865866-- CURRENT_TIME
866867currentTime
867− :: Expression schema from grouping params (nullity 'PGtimetz)
868+ :: Expression db from grouping params (nullity 'PGtimetz)
868869currentTime = UnsafeExpression "CURRENT_TIME"
869870
870871-- | >>> printSQL currentTimestamp
871872-- CURRENT_TIMESTAMP
872873currentTimestamp
873− :: Expression schema from grouping params (nullity 'PGtimestamptz)
874+ :: Expression db from grouping params (nullity 'PGtimestamptz)
874875currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
875876
876877-- | >>> printSQL localTime
877878-- LOCALTIME
878879localTime
879− :: Expression schema from grouping params (nullity 'PGtime)
880+ :: Expression db from grouping params (nullity 'PGtime)
880881localTime = UnsafeExpression "LOCALTIME"
881882
882883-- | >>> printSQL localTimestamp
883884-- LOCALTIMESTAMP
884885localTimestamp
885− :: Expression schema from grouping params (nullity 'PGtimestamp)
886+ :: Expression db from grouping params (nullity 'PGtimestamp)
886887localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
887888
888889{-----------------------------------------
@@ -890,7 +891,7 @@ text
890891-----------------------------------------}
891892
892893instance IsString
893− (Expression schema from grouping params (nullity 'PGtext)) where
894+ (Expression db from grouping params (nullity 'PGtext)) where
894895 fromString str = UnsafeExpression $
895896 "E\'" <> fromString (escape =<< str) <> "\'"
896897 where
@@ -906,36 +907,36 @@ instance IsString
906907 c -> [c]
907908
908909instance Semigroup
909− (Expression schema from grouping params (nullity 'PGtext)) where
910+ (Expression db from grouping params (nullity 'PGtext)) where
910911 (<>) = unsafeBinaryOp "||"
911912
912913instance Monoid
913− (Expression schema from grouping params (nullity 'PGtext)) where
914+ (Expression db from grouping params (nullity 'PGtext)) where
914915 mempty = fromString ""
915916 mappend = (<>)
916917
917918-- | >>> printSQL $ lower "ARRRGGG"
918919-- lower(E'ARRRGGG')
919920lower
920− :: Expression schema from grouping params (nullity 'PGtext)
921+ :: Expression db from grouping params (nullity 'PGtext)
921922 -- ^ string to lower case
922− -> Expression schema from grouping params (nullity 'PGtext)
923+ -> Expression db from grouping params (nullity 'PGtext)
923924lower = unsafeFunction "lower"
924925
925926-- | >>> printSQL $ upper "eeee"
926927-- upper(E'eeee')
927928upper
928− :: Expression schema from grouping params (nullity 'PGtext)
929+ :: Expression db from grouping params (nullity 'PGtext)
929930 -- ^ string to upper case
930− -> Expression schema from grouping params (nullity 'PGtext)
931+ -> Expression db from grouping params (nullity 'PGtext)
931932upper = unsafeFunction "upper"
932933
933934-- | >>> printSQL $ charLength "four"
934935-- char_length(E'four')
935936charLength
936− :: Expression schema from grouping params (nullity 'PGtext)
937+ :: Expression db from grouping params (nullity 'PGtext)
937938 -- ^ string to measure
938− -> Expression schema from grouping params (nullity 'PGint4)
939+ -> Expression db from grouping params (nullity 'PGint4)
939940charLength = unsafeFunction "char_length"
940941
941942-- | The `like` expression returns true if the @string@ matches
@@ -948,11 +949,11 @@ charLength = unsafeFunction "char_length"
948949-- >>> printSQL $ "abc" `like` "a%"
949950-- (E'abc' LIKE E'a%')
950951like
951− :: Expression schema from grouping params (nullity 'PGtext)
952+ :: Expression db from grouping params (nullity 'PGtext)
952953 -- ^ string
953− -> Expression schema from grouping params (nullity 'PGtext)
954+ -> Expression db from grouping params (nullity 'PGtext)
954955 -- ^ pattern
955− -> Expression schema from grouping params (nullity 'PGbool)
956+ -> Expression db from grouping params (nullity 'PGbool)
956957like = unsafeBinaryOp "LIKE"
957958
958959{-----------------------------------------
@@ -967,36 +968,36 @@ Table 9.44: json and jsonb operators
967968-- | Get JSON value (object field or array element) at a key.
968969(.->)
969970 :: (json `In` PGJsonType, key `In` PGJsonKey)
970− => Expression schema from grouping params (nullity json)
971− -> Expression schema from grouping params (nullity key)
972− -> Expression schema from grouping params ('Null json)
971+ => Expression db from grouping params (nullity json)
972+ -> Expression db from grouping params (nullity key)
973+ -> Expression db from grouping params ('Null json)
973974infixl 8 .->
974975(.->) = unsafeBinaryOp "->"
975976
976977-- | Get JSON value (object field or array element) at a key, as text.
977978(.->>)
978979 :: (json `In` PGJsonType, key `In` PGJsonKey)
979− => Expression schema from grouping params (nullity json)
980− -> Expression schema from grouping params (nullity key)
981− -> Expression schema from grouping params ('Null 'PGtext)
980+ => Expression db from grouping params (nullity json)
981+ -> Expression db from grouping params (nullity key)
982+ -> Expression db from grouping params ('Null 'PGtext)
982983infixl 8 .->>
983984(.->>) = unsafeBinaryOp "->>"
984985
985986-- | Get JSON value at a specified path.
986987(.#>)
987988 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
988− => Expression schema from grouping params (nullity json)
989− -> Expression schema from grouping params (nullity path)
990− -> Expression schema from grouping params ('Null json)
989+ => Expression db from grouping params (nullity json)
990+ -> Expression db from grouping params (nullity path)
991+ -> Expression db from grouping params ('Null json)
991992infixl 8 .#>
992993(.#>) = unsafeBinaryOp "#>"
993994
994995-- | Get JSON value at a specified path as text.
995996(.#>>)
996997 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
997− => Expression schema from grouping params (nullity json)
998− -> Expression schema from grouping params (nullity path)
999− -> Expression schema from grouping params ('Null 'PGtext)
998+ => Expression db from grouping params (nullity json)
999+ -> Expression db from grouping params (nullity path)
1000+ -> Expression db from grouping params ('Null 'PGtext)
10001001infixl 8 .#>>
10011002(.#>>) = unsafeBinaryOp "#>>"
10021003
@@ -1005,48 +1006,48 @@ infixl 8 .#>>
10051006-- | Does the left JSON value contain the right JSON path/value entries at the
10061007-- top level?
10071008(.@>)
1008− :: Expression schema from grouping params (nullity 'PGjsonb)
1009− -> Expression schema from grouping params (nullity 'PGjsonb)
1010− -> Condition schema from grouping params
1009+ :: Expression db from grouping params (nullity 'PGjsonb)
1010+ -> Expression db from grouping params (nullity 'PGjsonb)
1011+ -> Condition db from grouping params
10111012infixl 9 .@>
10121013(.@>) = unsafeBinaryOp "@>"
10131014
10141015-- | Are the left JSON path/value entries contained at the top level within the
10151016-- right JSON value?
10161017(.<@)
1017− :: Expression schema from grouping params (nullity 'PGjsonb)
1018− -> Expression schema from grouping params (nullity 'PGjsonb)
1019− -> Condition schema from grouping params
1018+ :: Expression db from grouping params (nullity 'PGjsonb)
1019+ -> Expression db from grouping params (nullity 'PGjsonb)
1020+ -> Condition db from grouping params
10201021infixl 9 .<@
10211022(.<@) = unsafeBinaryOp "<@"
10221023
10231024-- | Does the string exist as a top-level key within the JSON value?
10241025(.?)
1025− :: Expression schema from grouping params (nullity 'PGjsonb)
1026− -> Expression schema from grouping params (nullity 'PGtext)
1027− -> Condition schema from grouping params
1026+ :: Expression db from grouping params (nullity 'PGjsonb)
1027+ -> Expression db from grouping params (nullity 'PGtext)
1028+ -> Condition db from grouping params
10281029infixl 9 .?
10291030(.?) = unsafeBinaryOp "?"
10301031
10311032-- | Do any of these array strings exist as top-level keys?
10321033(.?|)
1033− :: Expression schema from grouping params (nullity 'PGjsonb)
1034− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1035− -> Condition schema from grouping params
1034+ :: Expression db from grouping params (nullity 'PGjsonb)
1035+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1036+ -> Condition db from grouping params
10361037infixl 9 .?|
10371038(.?|) = unsafeBinaryOp "?|"
10381039
10391040-- | Do all of these array strings exist as top-level keys?
10401041(.?&)
1041− :: Expression schema from grouping params (nullity 'PGjsonb)
1042− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1043− -> Condition schema from grouping params
1042+ :: Expression db from grouping params (nullity 'PGjsonb)
1043+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1044+ -> Condition db from grouping params
10441045infixl 9 .?&
10451046(.?&) = unsafeBinaryOp "?&"
10461047
10471048-- | Concatenate two jsonb values into a new jsonb value.
10481049instance
1049− Semigroup (Expression schema from grouping param (nullity 'PGjsonb)) where
1050+ Semigroup (Expression db from grouping param (nullity 'PGjsonb)) where
10501051 (<>) = unsafeBinaryOp "||"
10511052
10521053-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1063,9 +1064,9 @@ instance
10631064-- count from the end). Throws an error if top level container is not an array.
10641065(.-.)
10651066 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1066− => Expression schema from grouping params (nullity 'PGjsonb)
1067− -> Expression schema from grouping params (nullity key)
1068− -> Expression schema from grouping params (nullity 'PGjsonb)
1067+ => Expression db from grouping params (nullity 'PGjsonb)
1068+ -> Expression db from grouping params (nullity key)
1069+ -> Expression db from grouping params (nullity 'PGjsonb)
10691070infixl 6 .-.
10701071(.-.) = unsafeBinaryOp "-"
10711072
@@ -1073,9 +1074,9 @@ infixl 6 .-.
10731074-- integers count from the end)
10741075(#-.)
10751076 :: PGTextArray "(#-.)" arrayty
1076− => Expression schema from grouping params (nullity 'PGjsonb)
1077− -> Expression schema from grouping params (nullity arrayty)
1078− -> Expression schema from grouping params (nullity 'PGjsonb)
1077+ => Expression db from grouping params (nullity 'PGjsonb)
1078+ -> Expression db from grouping params (nullity arrayty)
1079+ -> Expression db from grouping params (nullity 'PGjsonb)
10791080infixl 6 #-.
10801081(#-.) = unsafeBinaryOp "#-"
10811082
@@ -1086,14 +1087,14 @@ Table 9.45: JSON creation functions
10861087-- | Literal binary JSON
10871088jsonbLit
10881089 :: JSON.ToJSON x
1089− => x -> Expression schema from grouping params (nullity 'PGjsonb)
1090+ => x -> Expression db from grouping params (nullity 'PGjsonb)
10901091jsonbLit = cast jsonb . UnsafeExpression
10911092 . singleQuotedUtf8 . toStrict . JSON.encode
10921093
10931094-- | Literal JSON
10941095jsonLit
10951096 :: JSON.ToJSON x
1096− => x -> Expression schema from grouping params (nullity 'PGjson)
1097+ => x -> Expression db from grouping params (nullity 'PGjson)
10971098jsonLit = cast json . UnsafeExpression
10981099 . singleQuotedUtf8 . toStrict . JSON.encode
10991100
@@ -1104,8 +1105,8 @@ jsonLit = cast json . UnsafeExpression
11041105-- number, a Boolean, or a null value, the text representation will be used, in
11051106-- such a fashion that it is a valid json value.
11061107toJson
1107− :: Expression schema from grouping params (nullity ty)
1108− -> Expression schema from grouping params (nullity 'PGjson)
1108+ :: Expression db from grouping params (nullity ty)
1109+ -> Expression db from grouping params (nullity 'PGjson)
11091110toJson = unsafeFunction "to_json"
11101111
11111112-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1115,43 +1116,43 @@ toJson = unsafeFunction "to_json"
11151116-- number, a Boolean, or a null value, the text representation will be used, in
11161117-- such a fashion that it is a valid jsonb value.
11171118toJsonb
1118− :: Expression schema from grouping params (nullity ty)
1119− -> Expression schema from grouping params (nullity 'PGjsonb)
1119+ :: Expression db from grouping params (nullity ty)
1120+ -> Expression db from grouping params (nullity 'PGjsonb)
11201121toJsonb = unsafeFunction "to_jsonb"
11211122
11221123-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
11231124-- becomes a JSON array of arrays.
11241125arrayToJson
11251126 :: PGArray "arrayToJson" arr
1126− => Expression schema from grouping params (nullity arr)
1127− -> Expression schema from grouping params (nullity 'PGjson)
1127+ => Expression db from grouping params (nullity arr)
1128+ -> Expression db from grouping params (nullity 'PGjson)
11281129arrayToJson = unsafeFunction "array_to_json"
11291130
11301131-- | Returns the row as a JSON object.
11311132rowToJson
1132− :: Expression schema from grouping params (nullity ('PGcomposite ty))
1133− -> Expression schema from grouping params (nullity 'PGjson)
1133+ :: Expression db from grouping params (nullity ('PGcomposite ty))
1134+ -> Expression db from grouping params (nullity 'PGjson)
11341135rowToJson = unsafeFunction "row_to_json"
11351136
11361137-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
11371138-- argument list.
11381139jsonBuildArray
11391140 :: SListI elems
1140− => NP (Expression schema from grouping params) elems
1141− -> Expression schema from grouping params (nullity 'PGjson)
1141+ => NP (Expression db from grouping params) elems
1142+ -> Expression db from grouping params (nullity 'PGjson)
11421143jsonBuildArray = unsafeVariadicFunction "json_build_array"
11431144
11441145-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
11451146-- variadic argument list.
11461147jsonbBuildArray
11471148 :: SListI elems
1148− => NP (Expression schema from grouping params) elems
1149− -> Expression schema from grouping params (nullity 'PGjsonb)
1149+ => NP (Expression db from grouping params) elems
1150+ -> Expression db from grouping params (nullity 'PGjsonb)
11501151jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
11511152
11521153unsafeRowFunction
11531154 :: All Top elems
1154− => NP (Aliased (Expression schema from grouping params)) elems
1155+ => NP (Aliased (Expression db from grouping params)) elems
11551156 -> [ByteString]
11561157unsafeRowFunction =
11571158 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1163,8 +1164,8 @@ unsafeRowFunction =
11631164-- and values.
11641165jsonBuildObject
11651166 :: All Top elems
1166− => NP (Aliased (Expression schema from grouping params)) elems
1167− -> Expression schema from grouping params (nullity 'PGjson)
1167+ => NP (Aliased (Expression db from grouping params)) elems
1168+ -> Expression db from grouping params (nullity 'PGjson)
11681169jsonBuildObject
11691170 = unsafeFunction "json_build_object"
11701171 . UnsafeExpression
@@ -1176,8 +1177,8 @@ jsonBuildObject
11761177-- between text and values.
11771178jsonbBuildObject
11781179 :: All Top elems
1179− => NP (Aliased (Expression schema from grouping params)) elems
1180− -> Expression schema from grouping params (nullity 'PGjsonb)
1180+ => NP (Aliased (Expression db from grouping params)) elems
1181+ -> Expression db from grouping params (nullity 'PGjsonb)
11811182jsonbBuildObject
11821183 = unsafeFunction "jsonb_build_object"
11831184 . UnsafeExpression
@@ -1190,8 +1191,8 @@ jsonbBuildObject
11901191-- array has exactly two elements, which are taken as a key/value pair.
11911192jsonObject
11921193 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1193− => Expression schema from grouping params (nullity arr)
1194− -> Expression schema from grouping params (nullity 'PGjson)
1194+ => Expression db from grouping params (nullity arr)
1195+ -> Expression db from grouping params (nullity 'PGjson)
11951196jsonObject = unsafeFunction "json_object"
11961197
11971198-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1200,8 +1201,8 @@ jsonObject = unsafeFunction "json_object"
12001201-- array has exactly two elements, which are taken as a key/value pair.
12011202jsonbObject
12021203 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1203− => Expression schema from grouping params (nullity arr)
1204− -> Expression schema from grouping params (nullity 'PGjsonb)
1204+ => Expression db from grouping params (nullity arr)
1205+ -> Expression db from grouping params (nullity 'PGjsonb)
12051206jsonbObject = unsafeFunction "jsonb_object"
12061207
12071208-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1209,9 +1210,9 @@ jsonbObject = unsafeFunction "jsonb_object"
12091210jsonZipObject
12101211 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
12111212 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1212− => Expression schema from grouping params (nullity keysArray)
1213− -> Expression schema from grouping params (nullity valuesArray)
1214− -> Expression schema from grouping params (nullity 'PGjson)
1213+ => Expression db from grouping params (nullity keysArray)
1214+ -> Expression db from grouping params (nullity valuesArray)
1215+ -> Expression db from grouping params (nullity 'PGjson)
12151216jsonZipObject ks vs =
12161217 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
12171218
@@ -1221,9 +1222,9 @@ jsonZipObject ks vs =
12211222jsonbZipObject
12221223 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
12231224 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1224− => Expression schema from grouping params (nullity keysArray)
1225− -> Expression schema from grouping params (nullity valuesArray)
1226− -> Expression schema from grouping params (nullity 'PGjsonb)
1225+ => Expression db from grouping params (nullity keysArray)
1226+ -> Expression db from grouping params (nullity valuesArray)
1227+ -> Expression db from grouping params (nullity 'PGjsonb)
12271228jsonbZipObject ks vs =
12281229 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
12291230
@@ -1233,23 +1234,23 @@ Table 9.46: JSON processing functions
12331234
12341235-- | Returns the number of elements in the outermost JSON array.
12351236jsonArrayLength
1236− :: Expression schema from grouping params (nullity 'PGjson)
1237− -> Expression schema from grouping params (nullity 'PGint4)
1237+ :: Expression db from grouping params (nullity 'PGjson)
1238+ -> Expression db from grouping params (nullity 'PGint4)
12381239jsonArrayLength = unsafeFunction "json_array_length"
12391240
12401241-- | Returns the number of elements in the outermost binary JSON array.
12411242jsonbArrayLength
1242− :: Expression schema from grouping params (nullity 'PGjsonb)
1243− -> Expression schema from grouping params (nullity 'PGint4)
1243+ :: Expression db from grouping params (nullity 'PGjsonb)
1244+ -> Expression db from grouping params (nullity 'PGint4)
12441245jsonbArrayLength = unsafeFunction "jsonb_array_length"
12451246
12461247-- | Returns JSON value pointed to by the given path (equivalent to #>
12471248-- operator).
12481249jsonExtractPath
12491250 :: SListI elems
1250− => Expression schema from grouping params (nullity 'PGjson)
1251− -> NP (Expression schema from grouping params) elems
1252− -> Expression schema from grouping params (nullity 'PGjsonb)
1251+ => Expression db from grouping params (nullity 'PGjson)
1252+ -> NP (Expression db from grouping params) elems
1253+ -> Expression db from grouping params (nullity 'PGjsonb)
12531254jsonExtractPath x xs =
12541255 unsafeVariadicFunction "json_extract_path" (x :* xs)
12551256
@@ -1257,9 +1258,9 @@ jsonExtractPath x xs =
12571258-- operator).
12581259jsonbExtractPath
12591260 :: SListI elems
1260− => Expression schema from grouping params (nullity 'PGjsonb)
1261− -> NP (Expression schema from grouping params) elems
1262− -> Expression schema from grouping params (nullity 'PGjsonb)
1261+ => Expression db from grouping params (nullity 'PGjsonb)
1262+ -> NP (Expression db from grouping params) elems
1263+ -> Expression db from grouping params (nullity 'PGjsonb)
12631264jsonbExtractPath x xs =
12641265 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
12651266
@@ -1267,9 +1268,9 @@ jsonbExtractPath x xs =
12671268-- operator), as text.
12681269jsonExtractPathAsText
12691270 :: SListI elems
1270− => Expression schema from grouping params (nullity 'PGjson)
1271− -> NP (Expression schema from grouping params) elems
1272− -> Expression schema from grouping params (nullity 'PGjson)
1271+ => Expression db from grouping params (nullity 'PGjson)
1272+ -> NP (Expression db from grouping params) elems
1273+ -> Expression db from grouping params (nullity 'PGjson)
12731274jsonExtractPathAsText x xs =
12741275 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
12751276
@@ -1277,38 +1278,38 @@ jsonExtractPathAsText x xs =
12771278-- operator), as text.
12781279jsonbExtractPathAsText
12791280 :: SListI elems
1280− => Expression schema from grouping params (nullity 'PGjsonb)
1281− -> NP (Expression schema from grouping params) elems
1282− -> Expression schema from grouping params (nullity 'PGjsonb)
1281+ => Expression db from grouping params (nullity 'PGjsonb)
1282+ -> NP (Expression db from grouping params) elems
1283+ -> Expression db from grouping params (nullity 'PGjsonb)
12831284jsonbExtractPathAsText x xs =
12841285 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
12851286
12861287-- | Returns the type of the outermost JSON value as a text string. Possible
12871288-- types are object, array, string, number, boolean, and null.
12881289jsonTypeof
1289− :: Expression schema from grouping params (nullity 'PGjson)
1290− -> Expression schema from grouping params (nullity 'PGtext)
1290+ :: Expression db from grouping params (nullity 'PGjson)
1291+ -> Expression db from grouping params (nullity 'PGtext)
12911292jsonTypeof = unsafeFunction "json_typeof"
12921293
12931294-- | Returns the type of the outermost binary JSON value as a text string.
12941295-- Possible types are object, array, string, number, boolean, and null.
12951296jsonbTypeof
1296− :: Expression schema from grouping params (nullity 'PGjsonb)
1297− -> Expression schema from grouping params (nullity 'PGtext)
1297+ :: Expression db from grouping params (nullity 'PGjsonb)
1298+ -> Expression db from grouping params (nullity 'PGtext)
12981299jsonbTypeof = unsafeFunction "jsonb_typeof"
12991300
13001301-- | Returns its argument with all object fields that have null values omitted.
13011302-- Other null values are untouched.
13021303jsonStripNulls
1303− :: Expression schema from grouping params (nullity 'PGjson)
1304− -> Expression schema from grouping params (nullity 'PGjson)
1304+ :: Expression db from grouping params (nullity 'PGjson)
1305+ -> Expression db from grouping params (nullity 'PGjson)
13051306jsonStripNulls = unsafeFunction "json_strip_nulls"
13061307
13071308-- | Returns its argument with all object fields that have null values omitted.
13081309-- Other null values are untouched.
13091310jsonbStripNulls
1310− :: Expression schema from grouping params (nullity 'PGjsonb)
1311− -> Expression schema from grouping params (nullity 'PGjsonb)
1311+ :: Expression db from grouping params (nullity 'PGjsonb)
1312+ -> Expression db from grouping params (nullity 'PGjsonb)
13121313jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13131314
13141315-- | @ jsonbSet target path new_value create_missing @
@@ -1320,11 +1321,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13201321-- arrays.
13211322jsonbSet
13221323 :: PGTextArray "jsonbSet" arr
1323− => Expression schema from grouping params (nullity 'PGjsonb)
1324− -> Expression schema from grouping params (nullity arr)
1325− -> Expression schema from grouping params (nullity 'PGjsonb)
1326− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1327− -> Expression schema from grouping params (nullity 'PGjsonb)
1324+ => Expression db from grouping params (nullity 'PGjsonb)
1325+ -> Expression db from grouping params (nullity arr)
1326+ -> Expression db from grouping params (nullity 'PGjsonb)
1327+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1328+ -> Expression db from grouping params (nullity 'PGjsonb)
13281329jsonbSet tgt path val createMissing = case createMissing of
13291330 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
13301331 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1339,19 +1340,19 @@ jsonbSet tgt path val createMissing = case createMissing of
13391340-- in path count from the end of JSON arrays.
13401341jsonbInsert
13411342 :: PGTextArray "jsonbInsert" arr
1342− => Expression schema from grouping params (nullity 'PGjsonb)
1343− -> Expression schema from grouping params (nullity arr)
1344− -> Expression schema from grouping params (nullity 'PGjsonb)
1345− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1346− -> Expression schema from grouping params (nullity 'PGjsonb)
1343+ => Expression db from grouping params (nullity 'PGjsonb)
1344+ -> Expression db from grouping params (nullity arr)
1345+ -> Expression db from grouping params (nullity 'PGjsonb)
1346+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1347+ -> Expression db from grouping params (nullity 'PGjsonb)
13471348jsonbInsert tgt path val insertAfter = case insertAfter of
13481349 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
13491350 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
13501351
13511352-- | Returns its argument as indented JSON text.
13521353jsonbPretty
1353− :: Expression schema from grouping params (nullity 'PGjsonb)
1354− -> Expression schema from grouping params (nullity 'PGtext)
1354+ :: Expression db from grouping params (nullity 'PGjsonb)
1355+ -> Expression db from grouping params (nullity 'PGtext)
13551356jsonbPretty = unsafeFunction "jsonb_pretty"
13561357
13571358{-----------------------------------------
@@ -1361,54 +1362,54 @@ aggregation
13611362-- | escape hatch to define aggregate functions
13621363unsafeAggregate
13631364 :: ByteString -- ^ aggregate function
1364− -> Expression schema from 'Ungrouped params (xty)
1365− -> Expression schema from ('Grouped bys) params (yty)
1365+ -> Expression db from 'Ungrouped params (xty)
1366+ -> Expression db from ('Grouped bys) params (yty)
13661367unsafeAggregate fun x = UnsafeExpression $ mconcat
13671368 [fun, "(", renderExpression x, ")"]
13681369
13691370-- | escape hatch to define aggregate functions over distinct values
13701371unsafeAggregateDistinct
13711372 :: ByteString -- ^ aggregate function
1372− -> Expression schema from 'Ungrouped params (xty)
1373− -> Expression schema from ('Grouped bys) params (yty)
1373+ -> Expression db from 'Ungrouped params (xty)
1374+ -> Expression db from ('Grouped bys) params (yty)
13741375unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
13751376 [fun, "(DISTINCT ", renderExpression x, ")"]
13761377
13771378-- | >>> :{
13781379-- let
1379−-- expression :: Expression schema '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
1380+-- expression :: Expression db '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
13801381-- expression = sum_ #col
13811382-- in printSQL expression
13821383-- :}
13831384-- sum("col")
13841385sum_
13851386 :: ty `In` PGNum
1386− => Expression schema from 'Ungrouped params (nullity ty)
1387+ => Expression db from 'Ungrouped params (nullity ty)
13871388 -- ^ what to sum
1388− -> Expression schema from ('Grouped bys) params (nullity ty)
1389+ -> Expression db from ('Grouped bys) params (nullity ty)
13891390sum_ = unsafeAggregate "sum"
13901391
13911392-- | >>> :{
13921393-- let
1393−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
1394+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
13941395-- expression = sumDistinct #col
13951396-- in printSQL expression
13961397-- :}
13971398-- sum(DISTINCT "col")
13981399sumDistinct
13991400 :: ty `In` PGNum
1400− => Expression schema from 'Ungrouped params (nullity ty)
1401+ => Expression db from 'Ungrouped params (nullity ty)
14011402 -- ^ what to sum
1402− -> Expression schema from ('Grouped bys) params (nullity ty)
1403+ -> Expression db from ('Grouped bys) params (nullity ty)
14031404sumDistinct = unsafeAggregateDistinct "sum"
14041405
14051406-- | A constraint for `PGType`s that you can take averages of and the resulting
14061407-- `PGType`.
14071408class PGAvg ty avg | ty -> avg where
14081409 avg, avgDistinct
1409− :: Expression schema from 'Ungrouped params (nullity ty)
1410+ :: Expression db from 'Ungrouped params (nullity ty)
14101411 -- ^ what to average
1411− -> Expression schema from ('Grouped bys) params (nullity avg)
1412+ -> Expression db from ('Grouped bys) params (nullity avg)
14121413 avg = unsafeAggregate "avg"
14131414 avgDistinct = unsafeAggregateDistinct "avg"
14141415instance PGAvg 'PGint2 'PGnumeric
@@ -1421,110 +1422,110 @@ instance PGAvg 'PGinterval 'PGinterval
14211422
14221423-- | >>> :{
14231424-- let
1424−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1425+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14251426-- expression = bitAnd #col
14261427-- in printSQL expression
14271428-- :}
14281429-- bit_and("col")
14291430bitAnd
14301431 :: int `In` PGIntegral
1431− => Expression schema from 'Ungrouped params (nullity int)
1432+ => Expression db from 'Ungrouped params (nullity int)
14321433 -- ^ what to aggregate
1433− -> Expression schema from ('Grouped bys) params (nullity int)
1434+ -> Expression db from ('Grouped bys) params (nullity int)
14341435bitAnd = unsafeAggregate "bit_and"
14351436
14361437-- | >>> :{
14371438-- let
1438−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1439+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14391440-- expression = bitOr #col
14401441-- in printSQL expression
14411442-- :}
14421443-- bit_or("col")
14431444bitOr
14441445 :: int `In` PGIntegral
1445− => Expression schema from 'Ungrouped params (nullity int)
1446+ => Expression db from 'Ungrouped params (nullity int)
14461447 -- ^ what to aggregate
1447− -> Expression schema from ('Grouped bys) params (nullity int)
1448+ -> Expression db from ('Grouped bys) params (nullity int)
14481449bitOr = unsafeAggregate "bit_or"
14491450
14501451-- | >>> :{
14511452-- let
1452−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1453+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14531454-- expression = bitAndDistinct #col
14541455-- in printSQL expression
14551456-- :}
14561457-- bit_and(DISTINCT "col")
14571458bitAndDistinct
14581459 :: int `In` PGIntegral
1459− => Expression schema from 'Ungrouped params (nullity int)
1460+ => Expression db from 'Ungrouped params (nullity int)
14601461 -- ^ what to aggregate
1461− -> Expression schema from ('Grouped bys) params (nullity int)
1462+ -> Expression db from ('Grouped bys) params (nullity int)
14621463bitAndDistinct = unsafeAggregateDistinct "bit_and"
14631464
14641465-- | >>> :{
14651466-- let
1466−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1467+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14671468-- expression = bitOrDistinct #col
14681469-- in printSQL expression
14691470-- :}
14701471-- bit_or(DISTINCT "col")
14711472bitOrDistinct
14721473 :: int `In` PGIntegral
1473− => Expression schema from 'Ungrouped params (nullity int)
1474+ => Expression db from 'Ungrouped params (nullity int)
14741475 -- ^ what to aggregate
1475− -> Expression schema from ('Grouped bys) params (nullity int)
1476+ -> Expression db from ('Grouped bys) params (nullity int)
14761477bitOrDistinct = unsafeAggregateDistinct "bit_or"
14771478
14781479-- | >>> :{
14791480-- let
1480−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1481+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
14811482-- expression = boolAnd #col
14821483-- in printSQL expression
14831484-- :}
14841485-- bool_and("col")
14851486boolAnd
1486− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1487+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
14871488 -- ^ what to aggregate
1488− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1489+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
14891490boolAnd = unsafeAggregate "bool_and"
14901491
14911492-- | >>> :{
14921493-- let
1493−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1494+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
14941495-- expression = boolOr #col
14951496-- in printSQL expression
14961497-- :}
14971498-- bool_or("col")
14981499boolOr
1499− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1500+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15001501 -- ^ what to aggregate
1501− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1502+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15021503boolOr = unsafeAggregate "bool_or"
15031504
15041505-- | >>> :{
15051506-- let
1506−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1507+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15071508-- expression = boolAndDistinct #col
15081509-- in printSQL expression
15091510-- :}
15101511-- bool_and(DISTINCT "col")
15111512boolAndDistinct
1512− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1513+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15131514 -- ^ what to aggregate
1514− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1515+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15151516boolAndDistinct = unsafeAggregateDistinct "bool_and"
15161517
15171518-- | >>> :{
15181519-- let
1519−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1520+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15201521-- expression = boolOrDistinct #col
15211522-- in printSQL expression
15221523-- :}
15231524-- bool_or(DISTINCT "col")
15241525boolOrDistinct
1525− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1526+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15261527 -- ^ what to aggregate
1527− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1528+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15281529boolOrDistinct = unsafeAggregateDistinct "bool_or"
15291530
15301531-- | A special aggregation that does not require an input
@@ -1532,70 +1533,70 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
15321533-- >>> printSQL countStar
15331534-- count(*)
15341535countStar
1535− :: Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1536+ :: Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15361537countStar = UnsafeExpression $ "count(*)"
15371538
15381539-- | >>> :{
15391540-- let
1540−-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1541+-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
15411542-- expression = count #col
15421543-- in printSQL expression
15431544-- :}
15441545-- count("col")
15451546count
1546− :: Expression schema from 'Ungrouped params ty
1547+ :: Expression db from 'Ungrouped params ty
15471548 -- ^ what to count
1548− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1549+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15491550count = unsafeAggregate "count"
15501551
15511552-- | >>> :{
15521553-- let
1553−-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1554+-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
15541555-- expression = countDistinct #col
15551556-- in printSQL expression
15561557-- :}
15571558-- count(DISTINCT "col")
15581559countDistinct
1559− :: Expression schema from 'Ungrouped params ty
1560+ :: Expression db from 'Ungrouped params ty
15601561 -- ^ what to count
1561− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1562+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15621563countDistinct = unsafeAggregateDistinct "count"
15631564
15641565-- | synonym for `boolAnd`
15651566--
15661567-- >>> :{
15671568-- let
1568−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1569+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15691570-- expression = every #col
15701571-- in printSQL expression
15711572-- :}
15721573-- every("col")
15731574every
1574− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1575+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15751576 -- ^ what to aggregate
1576− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1577+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15771578every = unsafeAggregate "every"
15781579
15791580-- | synonym for `boolAndDistinct`
15801581--
15811582-- >>> :{
15821583-- let
1583−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1584+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15841585-- expression = everyDistinct #col
15851586-- in printSQL expression
15861587-- :}
15871588-- every(DISTINCT "col")
15881589everyDistinct
1589− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1590+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15901591 -- ^ what to aggregate
1591− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1592+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15921593everyDistinct = unsafeAggregateDistinct "every"
15931594
15941595-- | minimum and maximum aggregation
15951596max_, min_, maxDistinct, minDistinct
1596− :: Expression schema from 'Ungrouped params (nullity ty)
1597+ :: Expression db from 'Ungrouped params (nullity ty)
15971598 -- ^ what to aggregate
1598− -> Expression schema from ('Grouped bys) params (nullity ty)
1599+ -> Expression db from ('Grouped bys) params (nullity ty)
15991600max_ = unsafeAggregate "max"
16001601min_ = unsafeAggregate "min"
16011602maxDistinct = unsafeAggregateDistinct "max"
@@ -1606,153 +1607,153 @@ type expressions
16061607-----------------------------------------}
16071608
16081609-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1609−newtype TypeExpression (schema :: SchemaType) (ty :: NullityType)
1610+newtype TypeExpression (db :: DBType) (ty :: NullityType)
16101611 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
16111612 deriving (GHC.Generic,Show,Eq,Ord,NFData)
16121613
16131614-- | The enum or composite type in a `Typedef` can be expressed by its alias.
16141615typedef
1615− :: Has alias schema ('Typedef ty)
1616− => Alias alias
1617− -> TypeExpression schema (nullity ty)
1618−typedef = UnsafeTypeExpression . renderAlias
1616+ :: HasQualified sch td db schema ('Typedef ty)
1617+ => QualifiedAlias sch td
1618+ -> TypeExpression db (nullity ty)
1619+typedef = UnsafeTypeExpression . renderQualifiedAlias
16191620
16201621-- | The composite type corresponding to a `Table` definition can be expressed
16211622-- by its alias.
16221623typetable
1623− :: Has alias schema ('Table tab)
1624− => Alias alias
1625− -> TypeExpression schema (nullity ('PGcomposite (TableToRow tab)))
1626−typetable = UnsafeTypeExpression . renderAlias
1624+ :: HasQualified sch tab db schema ('Table table)
1625+ => QualifiedAlias sch tab
1626+ -> TypeExpression db (nullity ('PGcomposite (TableToRow table)))
1627+typetable = UnsafeTypeExpression . renderQualifiedAlias
16271628
16281629-- | The composite type corresponding to a `View` definition can be expressed
16291630-- by its alias.
16301631typeview
1631− :: Has alias schema ('View view)
1632− => Alias alias
1633− -> TypeExpression schema (nullity ('PGcomposite view))
1634−typeview = UnsafeTypeExpression . renderAlias
1632+ :: HasQualified sch vw db schema ('View view)
1633+ => QualifiedAlias sch vw
1634+ -> TypeExpression db (nullity ('PGcomposite view))
1635+typeview = UnsafeTypeExpression . renderQualifiedAlias
16351636
16361637-- | logical Boolean (true/false)
1637−bool :: TypeExpression schema (nullity 'PGbool)
1638+bool :: TypeExpression db (nullity 'PGbool)
16381639bool = UnsafeTypeExpression "bool"
16391640-- | signed two-byte integer
1640−int2, smallint :: TypeExpression schema (nullity 'PGint2)
1641+int2, smallint :: TypeExpression db (nullity 'PGint2)
16411642int2 = UnsafeTypeExpression "int2"
16421643smallint = UnsafeTypeExpression "smallint"
16431644-- | signed four-byte integer
1644−int4, int, integer :: TypeExpression schema (nullity 'PGint4)
1645+int4, int, integer :: TypeExpression db (nullity 'PGint4)
16451646int4 = UnsafeTypeExpression "int4"
16461647int = UnsafeTypeExpression "int"
16471648integer = UnsafeTypeExpression "integer"
16481649-- | signed eight-byte integer
1649−int8, bigint :: TypeExpression schema (nullity 'PGint8)
1650+int8, bigint :: TypeExpression db (nullity 'PGint8)
16501651int8 = UnsafeTypeExpression "int8"
16511652bigint = UnsafeTypeExpression "bigint"
16521653-- | arbitrary precision numeric type
1653−numeric :: TypeExpression schema (nullity 'PGnumeric)
1654+numeric :: TypeExpression db (nullity 'PGnumeric)
16541655numeric = UnsafeTypeExpression "numeric"
16551656-- | single precision floating-point number (4 bytes)
1656−float4, real :: TypeExpression schema (nullity 'PGfloat4)
1657+float4, real :: TypeExpression db (nullity 'PGfloat4)
16571658float4 = UnsafeTypeExpression "float4"
16581659real = UnsafeTypeExpression "real"
16591660-- | double precision floating-point number (8 bytes)
1660−float8, doublePrecision :: TypeExpression schema (nullity 'PGfloat8)
1661+float8, doublePrecision :: TypeExpression db (nullity 'PGfloat8)
16611662float8 = UnsafeTypeExpression "float8"
16621663doublePrecision = UnsafeTypeExpression "double precision"
16631664-- | variable-length character string
1664−text :: TypeExpression schema (nullity 'PGtext)
1665+text :: TypeExpression db (nullity 'PGtext)
16651666text = UnsafeTypeExpression "text"
16661667-- | fixed-length character string
16671668char, character
1668− :: forall n schema nullity. (KnownNat n, 1 <= n)
1669− => TypeExpression schema (nullity ('PGchar n))
1669+ :: forall n db nullity. (KnownNat n, 1 <= n)
1670+ => TypeExpression db (nullity ('PGchar n))
16701671char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
16711672character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
16721673-- | variable-length character string
16731674varchar, characterVarying
1674− :: forall n schema nullity. (KnownNat n, 1 <= n)
1675− => TypeExpression schema (nullity ('PGvarchar n))
1675+ :: forall n db nullity. (KnownNat n, 1 <= n)
1676+ => TypeExpression db (nullity ('PGvarchar n))
16761677varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
16771678characterVarying = UnsafeTypeExpression $
16781679 "character varying(" <> renderNat @n <> ")"
16791680-- | binary data ("byte array")
1680−bytea :: TypeExpression schema (nullity 'PGbytea)
1681+bytea :: TypeExpression db (nullity 'PGbytea)
16811682bytea = UnsafeTypeExpression "bytea"
16821683-- | date and time (no time zone)
1683−timestamp :: TypeExpression schema (nullity 'PGtimestamp)
1684+timestamp :: TypeExpression db (nullity 'PGtimestamp)
16841685timestamp = UnsafeTypeExpression "timestamp"
16851686-- | date and time, including time zone
1686−timestampWithTimeZone :: TypeExpression schema (nullity 'PGtimestamptz)
1687+timestampWithTimeZone :: TypeExpression db (nullity 'PGtimestamptz)
16871688timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
16881689-- | calendar date (year, month, day)
1689−date :: TypeExpression schema (nullity 'PGdate)
1690+date :: TypeExpression db (nullity 'PGdate)
16901691date = UnsafeTypeExpression "date"
16911692-- | time of day (no time zone)
1692−time :: TypeExpression schema (nullity 'PGtime)
1693+time :: TypeExpression db (nullity 'PGtime)
16931694time = UnsafeTypeExpression "time"
16941695-- | time of day, including time zone
1695−timeWithTimeZone :: TypeExpression schema (nullity 'PGtimetz)
1696+timeWithTimeZone :: TypeExpression db (nullity 'PGtimetz)
16961697timeWithTimeZone = UnsafeTypeExpression "time with time zone"
16971698-- | time span
1698−interval :: TypeExpression schema (nullity 'PGinterval)
1699+interval :: TypeExpression db (nullity 'PGinterval)
16991700interval = UnsafeTypeExpression "interval"
17001701-- | universally unique identifier
1701−uuid :: TypeExpression schema (nullity 'PGuuid)
1702+uuid :: TypeExpression db (nullity 'PGuuid)
17021703uuid = UnsafeTypeExpression "uuid"
17031704-- | IPv4 or IPv6 host address
1704−inet :: TypeExpression schema (nullity 'PGinet)
1705+inet :: TypeExpression db (nullity 'PGinet)
17051706inet = UnsafeTypeExpression "inet"
17061707-- | textual JSON data
1707−json :: TypeExpression schema (nullity 'PGjson)
1708+json :: TypeExpression db (nullity 'PGjson)
17081709json = UnsafeTypeExpression "json"
17091710-- | binary JSON data, decomposed
1710−jsonb :: TypeExpression schema (nullity 'PGjsonb)
1711+jsonb :: TypeExpression db (nullity 'PGjsonb)
17111712jsonb = UnsafeTypeExpression "jsonb"
17121713-- | variable length array
17131714vararray
1714− :: TypeExpression schema pg
1715− -> TypeExpression schema (nullity ('PGvararray pg))
1715+ :: TypeExpression db pg
1716+ -> TypeExpression db (nullity ('PGvararray pg))
17161717vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
17171718-- | fixed length array
17181719--
17191720-- >>> renderTypeExpression (fixarray @2 json)
17201721-- "json[2]"
17211722fixarray
1722− :: forall n schema nullity pg. KnownNat n
1723− => TypeExpression schema pg
1724− -> TypeExpression schema (nullity ('PGfixarray n pg))
1723+ :: forall n db nullity pg. KnownNat n
1724+ => TypeExpression db pg
1725+ -> TypeExpression db (nullity ('PGfixarray n pg))
17251726fixarray ty = UnsafeTypeExpression $
17261727 renderTypeExpression ty <> "[" <> renderNat @n <> "]"
17271728
17281729-- | `pgtype` is a demoted version of a `PGType`
1729−class PGTyped schema (ty :: NullityType) where
1730− pgtype :: TypeExpression schema ty
1731−instance PGTyped schema (nullity 'PGbool) where pgtype = bool
1732−instance PGTyped schema (nullity 'PGint2) where pgtype = int2
1733−instance PGTyped schema (nullity 'PGint4) where pgtype = int4
1734−instance PGTyped schema (nullity 'PGint8) where pgtype = int8
1735−instance PGTyped schema (nullity 'PGnumeric) where pgtype = numeric
1736−instance PGTyped schema (nullity 'PGfloat4) where pgtype = float4
1737−instance PGTyped schema (nullity 'PGfloat8) where pgtype = float8
1738−instance PGTyped schema (nullity 'PGtext) where pgtype = text
1730+class PGTyped db (ty :: NullityType) where
1731+ pgtype :: TypeExpression db ty
1732+instance PGTyped db (nullity 'PGbool) where pgtype = bool
1733+instance PGTyped db (nullity 'PGint2) where pgtype = int2
1734+instance PGTyped db (nullity 'PGint4) where pgtype = int4
1735+instance PGTyped db (nullity 'PGint8) where pgtype = int8
1736+instance PGTyped db (nullity 'PGnumeric) where pgtype = numeric
1737+instance PGTyped db (nullity 'PGfloat4) where pgtype = float4
1738+instance PGTyped db (nullity 'PGfloat8) where pgtype = float8
1739+instance PGTyped db (nullity 'PGtext) where pgtype = text
17391740instance (KnownNat n, 1 <= n)
1740− => PGTyped schema (nullity ('PGchar n)) where pgtype = char @n
1741+ => PGTyped db (nullity ('PGchar n)) where pgtype = char @n
17411742instance (KnownNat n, 1 <= n)
1742− => PGTyped schema (nullity ('PGvarchar n)) where pgtype = varchar @n
1743−instance PGTyped schema (nullity 'PGbytea) where pgtype = bytea
1744−instance PGTyped schema (nullity 'PGtimestamp) where pgtype = timestamp
1745−instance PGTyped schema (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1746−instance PGTyped schema (nullity 'PGdate) where pgtype = date
1747−instance PGTyped schema (nullity 'PGtime) where pgtype = time
1748−instance PGTyped schema (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1749−instance PGTyped schema (nullity 'PGinterval) where pgtype = interval
1750−instance PGTyped schema (nullity 'PGuuid) where pgtype = uuid
1751−instance PGTyped schema (nullity 'PGjson) where pgtype = json
1752−instance PGTyped schema (nullity 'PGjsonb) where pgtype = jsonb
1753−instance PGTyped schema ty
1754− => PGTyped schema (nullity ('PGvararray ty)) where
1755− pgtype = vararray (pgtype @schema @ty)
1756−instance (KnownNat n, PGTyped schema ty)
1757− => PGTyped schema (nullity ('PGfixarray n ty)) where
1758− pgtype = fixarray @n (pgtype @schema @ty)
1743+ => PGTyped db (nullity ('PGvarchar n)) where pgtype = varchar @n
1744+instance PGTyped db (nullity 'PGbytea) where pgtype = bytea
1745+instance PGTyped db (nullity 'PGtimestamp) where pgtype = timestamp
1746+instance PGTyped db (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1747+instance PGTyped db (nullity 'PGdate) where pgtype = date
1748+instance PGTyped db (nullity 'PGtime) where pgtype = time
1749+instance PGTyped db (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1750+instance PGTyped db (nullity 'PGinterval) where pgtype = interval
1751+instance PGTyped db (nullity 'PGuuid) where pgtype = uuid
1752+instance PGTyped db (nullity 'PGjson) where pgtype = json
1753+instance PGTyped db (nullity 'PGjsonb) where pgtype = jsonb
1754+instance PGTyped db ty
1755+ => PGTyped db (nullity ('PGvararray ty)) where
1756+ pgtype = vararray (pgtype @db @ty)
1757+instance (KnownNat n, PGTyped db ty)
1758+ => PGTyped db (nullity ('PGfixarray n ty)) where
1759+ pgtype = fixarray @n (pgtype @db @ty)