@@ -218,7 +218,7 @@ values from primitive expression using arithmetic, logical,
218218and other operations.
219219-}
220220newtype Expression
221− (schema :: SchemaType)
221+ (db :: DBType)
222222 (from :: FromType)
223223 (grouping :: Grouping)
224224 (params :: [NullityType])
@@ -226,7 +226,7 @@ newtype Expression
226226 = UnsafeExpression { renderExpression :: ByteString }
227227 deriving (GHC.Generic,Show,Eq,Ord,NFData)
228228
229−instance RenderSQL (Expression schema from grouping params ty) where
229+instance RenderSQL (Expression db from grouping params ty) where
230230 renderSQL = renderExpression
231231
232232{- | A `HasParameter` constraint is used to indicate a value that is
@@ -239,60 +239,59 @@ refer to the out-of-line data values.
239239-}
240240class KnownNat n => HasParameter
241241 (n :: Nat)
242− (schema :: SchemaType)
243242 (params :: [NullityType])
244243 (ty :: NullityType)
245244 | n params -> ty where
246245 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
247246 --
248− -- >>> let expr = parameter @1 int4 :: Expression sch rels grp '[ 'Null 'PGint4] ('Null 'PGint4)
247+ -- >>> let expr = parameter @1 int4 :: Expression (DBof schemas) from grp '[ 'Null 'PGint4] ('Null 'PGint4)
249248 -- >>> printSQL expr
250249 -- ($1 :: int4)
251250 parameter
252− :: TypeExpression schema ty
253− -> Expression schema from grouping params ty
251+ :: TypeExpression schemas ty
252+ -> Expression (commons :=> schemas) from grouping params ty
254253 parameter ty = UnsafeExpression $ parenthesized $
255254 "$" <> renderNat @n <+> "::"
256255 <+> renderTypeExpression ty
257−instance {-# OVERLAPPING #-} HasParameter 1 schema (ty1:tys) ty1
258−instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
259− => HasParameter n schema (ty' : params) ty
256+instance {-# OVERLAPPING #-} HasParameter 1 (ty1:tys) ty1
257+instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
258+ => HasParameter n (ty' : params) ty
260259
261260-- | `param` takes a `Nat` using type application and for basic types,
262261-- infers a `TypeExpression`.
263262--
264−-- >>> let expr = param @1 :: Expression sch rels grp '[ 'Null 'PGint4] ('Null 'PGint4)
263+-- >>> let expr = param @1 :: Expression (commons :=> schemas) from grp '[ 'Null 'PGint4] ('Null 'PGint4)
265264-- >>> printSQL expr
266265-- ($1 :: int4)
267266param
268− :: forall n schema params from grouping ty
269− . (PGTyped schema ty, HasParameter n schema params ty)
270− => Expression schema from grouping params ty -- ^ param
271−param = parameter @n pgtype
267+ :: forall n db commons schemas params from grouping ty
268+ . (db ~ (commons :=> schemas), PGTyped schemas ty, HasParameter n params ty)
269+ => Expression db from grouping params ty -- ^ param
270+param = parameter @n (pgtype @schemas)
272271
273272instance (HasUnique table from columns, Has column columns ty)
274− => IsLabel column (Expression schema from 'Ungrouped params ty) where
273+ => IsLabel column (Expression db from 'Ungrouped params ty) where
275274 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
276275instance (HasUnique table from columns, Has column columns ty)
277276 => IsLabel column
278− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
277+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
279278 fromLabel = fromLabel @column `As` Alias @column
280279instance (HasUnique table from columns, Has column columns ty)
281280 => IsLabel column
282− (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
281+ (NP (Aliased (Expression db from 'Ungrouped params)) '[column ::: ty]) where
283282 fromLabel = fromLabel @column :* Nil
284283
285284instance (Has table from columns, Has column columns ty)
286− => IsQualified table column (Expression schema from 'Ungrouped params ty) where
285+ => IsQualified table column (Expression db from 'Ungrouped params ty) where
287286 table ! column = UnsafeExpression $
288287 renderAlias table <> "." <> renderAlias column
289288instance (Has table from columns, Has column columns ty)
290289 => IsQualified table column
291− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
290+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
292291 table ! column = table ! column `As` column
293292instance (Has table from columns, Has column columns ty)
294293 => IsQualified table column
295− (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
294+ (NP (Aliased (Expression db from 'Ungrouped params)) '[column ::: ty]) where
296295 table ! column = table ! column :* Nil
297296
298297instance
@@ -300,14 +299,14 @@ instance
300299 , Has column columns ty
301300 , GroupedBy table column bys
302301 ) => IsLabel column
303− (Expression schema from ('Grouped bys) params ty) where
302+ (Expression db from ('Grouped bys) params ty) where
304303 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
305304instance
306305 ( HasUnique table from columns
307306 , Has column columns ty
308307 , GroupedBy table column bys
309308 ) => IsLabel column
310− ( Aliased (Expression schema from ('Grouped bys) params)
309+ ( Aliased (Expression db from ('Grouped bys) params)
311310 (column ::: ty) ) where
312311 fromLabel = fromLabel @column `As` Alias @column
313312instance
@@ -315,7 +314,7 @@ instance
315314 , Has column columns ty
316315 , GroupedBy table column bys
317316 ) => IsLabel column
318− ( NP (Aliased (Expression schema from ('Grouped bys) params))
317+ ( NP (Aliased (Expression db from ('Grouped bys) params))
319318 '[column ::: ty] ) where
320319 fromLabel = fromLabel @column :* Nil
321320
@@ -324,7 +323,7 @@ instance
324323 , Has column columns ty
325324 , GroupedBy table column bys
326325 ) => IsQualified table column
327− (Expression schema from ('Grouped bys) params ty) where
326+ (Expression db from ('Grouped bys) params ty) where
328327 table ! column = UnsafeExpression $
329328 renderAlias table <> "." <> renderAlias column
330329instance
@@ -332,7 +331,7 @@ instance
332331 , Has column columns ty
333332 , GroupedBy table column bys
334333 ) => IsQualified table column
335− (Aliased (Expression schema from ('Grouped bys) params)
334+ (Aliased (Expression db from ('Grouped bys) params)
336335 (column ::: ty)) where
337336 table ! column = table ! column `As` column
338337instance
@@ -340,7 +339,7 @@ instance
340339 , Has column columns ty
341340 , GroupedBy table column bys
342341 ) => IsQualified table column
343− ( NP (Aliased (Expression schema from ('Grouped bys) params))
342+ ( NP (Aliased (Expression db from ('Grouped bys) params))
344343 '[column ::: ty]) where
345344 table ! column = table ! column :* Nil
346345
@@ -348,7 +347,7 @@ instance
348347--
349348-- >>> printSQL null_
350349-- NULL
351−null_ :: Expression schema rels grouping params ('Null ty)
350+null_ :: Expression db rels grouping params ('Null ty)
352351null_ = UnsafeExpression "NULL"
353352
354353-- | analagous to `Just`
@@ -356,8 +355,8 @@ null_ = UnsafeExpression "NULL"
356355-- >>> printSQL $ notNull true
357356-- TRUE
358357notNull
359− :: Expression schema rels grouping params ('NotNull ty)
360− -> Expression schema rels grouping params ('Null ty)
358+ :: Expression db rels grouping params ('NotNull ty)
359+ -> Expression db rels grouping params ('Null ty)
361360notNull = UnsafeExpression . renderExpression
362361
363362-- | return the leftmost value which is not NULL
@@ -365,11 +364,11 @@ notNull = UnsafeExpression . renderExpression
365364-- >>> printSQL $ coalesce [null_, true] false
366365-- COALESCE(NULL, TRUE, FALSE)
367366coalesce
368− :: [Expression schema from grouping params ('Null ty)]
367+ :: [Expression db from grouping params ('Null ty)]
369368 -- ^ @NULL@s may be present
370− -> Expression schema from grouping params ('NotNull ty)
369+ -> Expression db from grouping params ('NotNull ty)
371370 -- ^ @NULL@ is absent
372− -> Expression schema from grouping params ('NotNull ty)
371+ -> Expression db from grouping params ('NotNull ty)
373372coalesce nullxs notNullx = UnsafeExpression $
374373 "COALESCE" <> parenthesized (commaSeparated
375374 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -379,26 +378,26 @@ coalesce nullxs notNullx = UnsafeExpression $
379378-- >>> printSQL $ fromNull true null_
380379-- COALESCE(NULL, TRUE)
381380fromNull
382− :: Expression schema from grouping params ('NotNull ty)
381+ :: Expression db from grouping params ('NotNull ty)
383382 -- ^ what to convert @NULL@ to
384− -> Expression schema from grouping params ('Null ty)
385− -> Expression schema from grouping params ('NotNull ty)
383+ -> Expression db from grouping params ('Null ty)
384+ -> Expression db from grouping params ('NotNull ty)
386385fromNull notNullx nullx = coalesce [nullx] notNullx
387386
388387-- | >>> printSQL $ null_ & isNull
389388-- NULL IS NULL
390389isNull
391− :: Expression schema from grouping params ('Null ty)
390+ :: Expression db from grouping params ('Null ty)
392391 -- ^ possibly @NULL@
393− -> Condition schema from grouping params
392+ -> Condition db from grouping params
394393isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
395394
396395-- | >>> printSQL $ null_ & isNotNull
397396-- NULL IS NOT NULL
398397isNotNull
399− :: Expression schema from grouping params ('Null ty)
398+ :: Expression db from grouping params ('Null ty)
400399 -- ^ possibly @NULL@
401− -> Condition schema from grouping params
400+ -> Condition db from grouping params
402401isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
403402
404403-- | analagous to `maybe` using @IS NULL@
@@ -406,13 +405,13 @@ isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
406405-- >>> printSQL $ matchNull true not_ null_
407406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
408407matchNull
409− :: Expression schema from grouping params (nullty)
408+ :: Expression db from grouping params (nullty)
410409 -- ^ what to convert @NULL@ to
411− -> ( Expression schema from grouping params ('NotNull ty)
412− -> Expression schema from grouping params (nullty) )
410+ -> ( Expression db from grouping params ('NotNull ty)
411+ -> Expression db from grouping params (nullty) )
413412 -- ^ function to perform when @NULL@ is absent
414− -> Expression schema from grouping params ('Null ty)
415− -> Expression schema from grouping params (nullty)
413+ -> Expression db from grouping params ('Null ty)
414+ -> Expression db from grouping params (nullty)
416415matchNull y f x = ifThenElse (isNull x) y
417416 (f (UnsafeExpression (renderExpression x)))
418417
@@ -420,25 +419,25 @@ matchNull y f x = ifThenElse (isNull x) y
420419`nullIf` gives @NULL@.
421420
422421>>> :set -XTypeApplications -XDataKinds
423−>>> let expr = nullIf false (param @1) :: Expression schema rels grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
422+>>> let expr = nullIf false (param @1) :: Expression (commons :=> schema) from grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
424423>>> printSQL expr
425424NULL IF (FALSE, ($1 :: bool))
426425-}
427426nullIf
428− :: Expression schema from grouping params ('NotNull ty)
427+ :: Expression db from grouping params ('NotNull ty)
429428 -- ^ @NULL@ is absent
430− -> Expression schema from grouping params ('NotNull ty)
429+ -> Expression db from grouping params ('NotNull ty)
431430 -- ^ @NULL@ is absent
432− -> Expression schema from grouping params ('Null ty)
431+ -> Expression db from grouping params ('Null ty)
433432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
434433 (renderExpression x <> ", " <> renderExpression y)
435434
436435-- | >>> printSQL $ array [null_, false, true]
437436-- ARRAY[NULL, FALSE, TRUE]
438437array
439− :: [Expression schema from grouping params ty]
438+ :: [Expression db from grouping params ty]
440439 -- ^ array elements
441− -> Expression schema from grouping params (nullity ('PGvararray ty))
440+ -> Expression db from grouping params (nullity ('PGvararray ty))
442441array xs = UnsafeExpression $
443442 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
444443
@@ -446,13 +445,13 @@ array xs = UnsafeExpression $
446445-- (ARRAY[NULL, FALSE, TRUE])[2]
447446index
448447 :: Word64 -- ^ index
449− -> Expression schema from grouping params (nullity ('PGvararray ty)) -- ^ array
450− -> 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)
451450index n expr = UnsafeExpression $
452451 parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
453452
454453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
455− (Expression schema from grouping params (nullity ('PGenum labels))) where
454+ (Expression db from grouping params (nullity ('PGenum labels))) where
456455 label = UnsafeExpression $ renderLabel (PGlabel @label)
457456
458457-- | A row constructor is an expression that builds a row value
@@ -464,14 +463,14 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
464463-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
465464-- :}
466465--
467−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
466+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression db from grp params ('NotNull Complex)
468467-- >>> printSQL i
469468-- ROW(0, 1)
470469row
471470 :: SListI row
472− => NP (Aliased (Expression schema from grouping params)) row
471+ => NP (Aliased (Expression db from grouping params)) row
473472 -- ^ zero or more expressions for the row field values
474− -> Expression schema from grouping params (nullity ('PGcomposite row))
473+ -> Expression db from grouping params (nullity ('PGcomposite row))
475474row exprs = UnsafeExpression $ "ROW" <> parenthesized
476475 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
477476
@@ -479,50 +478,54 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
479478-- type Complex = 'PGcomposite
480479-- '[ "real" ::: 'NotNull 'PGfloat8
481480-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
481+-- type Schema = '["complex" ::: 'Typedef Complex]
482+-- type DB = DBof (Public Schema)
482483-- :}
483484--
484−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '["complex" ::: 'Typedef Complex] '[] 'Ungrouped '[] ('NotNull Complex)
485+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression DB from grp params ('NotNull Complex)
485486-- >>> printSQL $ i & field #complex #imaginary
486487-- (ROW(0, 1)::"complex")."imaginary"
487488field
488− :: (Has tydef schema ('Typedef ('PGcomposite row)), Has field row ty)
489− => Alias tydef -- ^ row type
489+ :: ( Has sch schemas schema
490+ , Has tydef schema ('Typedef ('PGcomposite row))
491+ , Has field row ty)
492+ => QualifiedAlias sch tydef -- ^ row type
490493 -> Alias field -- ^ field name
491− -> Expression schema from grouping params ('NotNull ('PGcomposite row))
492− -> Expression schema from grouping params ty
494+ -> Expression (commons :=> schemas) from grouping params ('NotNull ('PGcomposite row))
495+ -> Expression (commons :=> schemas) from grouping params ty
493496field td fld expr = UnsafeExpression $
494− parenthesized (renderExpression expr <> "::" <> renderAlias td)
497+ parenthesized (renderExpression expr <> "::" <> renderQualifiedAlias td)
495498 <> "." <> renderAlias fld
496499
497500instance Semigroup
498− (Expression schema from grouping params (nullity ('PGvararray ty))) where
501+ (Expression db from grouping params (nullity ('PGvararray ty))) where
499502 (<>) = unsafeBinaryOp "||"
500503
501504instance Monoid
502− (Expression schema from grouping params (nullity ('PGvararray ty))) where
505+ (Expression db from grouping params (nullity ('PGvararray ty))) where
503506 mempty = array []
504507 mappend = (<>)
505508
506−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression sch rels grp '[ 'NotNull 'PGtimestamptz] ('NotNull 'PGtimestamptz)
509+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression (commons :=> schemas) rels grp '[ 'NotNull 'PGtimestamptz] ('NotNull 'PGtimestamptz)
507510-- >>> printSQL expr
508511-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
509512greatest
510− :: Expression schema from grouping params (nullty)
513+ :: Expression db from grouping params (nullty)
511514 -- ^ needs at least 1 argument
512− -> [Expression schema from grouping params (nullty)]
515+ -> [Expression db from grouping params (nullty)]
513516 -- ^ or more
514− -> Expression schema from grouping params (nullty)
517+ -> Expression db from grouping params (nullty)
515518greatest x xs = UnsafeExpression $ "GREATEST("
516519 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
517520
518521-- | >>> printSQL $ least currentTimestamp [null_]
519522-- LEAST(CURRENT_TIMESTAMP, NULL)
520523least
521− :: Expression schema from grouping params (nullty)
524+ :: Expression db from grouping params (nullty)
522525 -- ^ needs at least 1 argument
523− -> [Expression schema from grouping params (nullty)]
526+ -> [Expression db from grouping params (nullty)]
524527 -- ^ or more
525− -> Expression schema from grouping params (nullty)
528+ -> Expression db from grouping params (nullty)
526529least x xs = UnsafeExpression $ "LEAST("
527530 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
528531
@@ -531,9 +534,9 @@ least x xs = UnsafeExpression $ "LEAST("
531534unsafeBinaryOp
532535 :: ByteString
533536 -- ^ operator
534− -> Expression schema from grouping params (ty0)
535− -> Expression schema from grouping params (ty1)
536− -> Expression schema from grouping params (ty2)
537+ -> Expression db from grouping params (ty0)
538+ -> Expression db from grouping params (ty1)
539+ -> Expression db from grouping params (ty2)
537540unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
538541 renderExpression x <+> op <+> renderExpression y
539542
@@ -542,8 +545,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
542545unsafeUnaryOp
543546 :: ByteString
544547 -- ^ operator
545− -> Expression schema from grouping params (ty0)
546− -> Expression schema from grouping params (ty1)
548+ -> Expression db from grouping params (ty0)
549+ -> Expression db from grouping params (ty1)
547550unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
548551 op <+> renderExpression x
549552
@@ -552,8 +555,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
552555unsafeFunction
553556 :: ByteString
554557 -- ^ function
555− -> Expression schema from grouping params (xty)
556− -> Expression schema from grouping params (yty)
558+ -> Expression db from grouping params (xty)
559+ -> Expression db from grouping params (yty)
557560unsafeFunction fun x = UnsafeExpression $
558561 fun <> parenthesized (renderExpression x)
559562
@@ -562,13 +565,13 @@ unsafeVariadicFunction
562565 :: SListI elems
563566 => ByteString
564567 -- ^ function
565− -> NP (Expression schema from grouping params) elems
566− -> Expression schema from grouping params ret
568+ -> NP (Expression db from grouping params) elems
569+ -> Expression db from grouping params ret
567570unsafeVariadicFunction fun x = UnsafeExpression $
568571 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
569572
570573instance ty `In` PGNum
571− => Num (Expression schema from grouping params (nullity ty)) where
574+ => Num (Expression db from grouping params (nullity ty)) where
572575 (+) = unsafeBinaryOp "+"
573576 (-) = unsafeBinaryOp "-"
574577 (*) = unsafeBinaryOp "*"
@@ -580,12 +583,12 @@ instance ty `In` PGNum
580583 . show
581584
582585instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
583− (Expression schema from grouping params (nullity ty)) where
586+ (Expression db from grouping params (nullity ty)) where
584587 (/) = unsafeBinaryOp "/"
585588 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
586589
587590instance (ty `In` PGNum, ty `In` PGFloating) => Floating
588− (Expression schema from grouping params (nullity ty)) where
591+ (Expression db from grouping params (nullity ty)) where
589592 pi = UnsafeExpression "pi()"
590593 exp = unsafeFunction "exp"
591594 log = unsafeFunction "ln"
@@ -608,18 +611,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
608611
609612-- | >>> :{
610613-- let
611−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
614+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
612615-- expression = atan2_ pi 2
613616-- in printSQL expression
614617-- :}
615618-- atan2(pi(), 2)
616619atan2_
617620 :: float `In` PGFloating
618− => Expression schema from grouping params (nullity float)
621+ => Expression db from grouping params (nullity float)
619622 -- ^ numerator
620− -> Expression schema from grouping params (nullity float)
623+ -> Expression db from grouping params (nullity float)
621624 -- ^ denominator
622− -> Expression schema from grouping params (nullity float)
625+ -> Expression db from grouping params (nullity float)
623626atan2_ y x = UnsafeExpression $
624627 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
625628
@@ -630,11 +633,11 @@ atan2_ y x = UnsafeExpression $
630633-- | >>> printSQL $ true & cast int4
631634-- (TRUE :: int4)
632635cast
633− :: TypeExpression schema ty1
636+ :: TypeExpression schemas ty1
634637 -- ^ type to cast as
635− -> Expression schema from grouping params ty0
638+ -> Expression (commons :=> schemas) from grouping params ty0
636639 -- ^ value to convert
637− -> Expression schema from grouping params ty1
640+ -> Expression (commons :=> schemas) from grouping params ty1
638641cast ty x = UnsafeExpression $ parenthesized $
639642 renderExpression x <+> "::" <+> renderTypeExpression ty
640643
@@ -642,136 +645,136 @@ cast ty x = UnsafeExpression $ parenthesized $
642645--
643646-- >>> :{
644647-- let
645−-- expression :: Expression schema from grouping params (nullity 'PGint2)
648+-- expression :: Expression db from grouping params (nullity 'PGint2)
646649-- expression = 5 `quot_` 2
647650-- in printSQL expression
648651-- :}
649652-- (5 / 2)
650653quot_
651654 :: int `In` PGIntegral
652− => Expression schema from grouping params (nullity int)
655+ => Expression db from grouping params (nullity int)
653656 -- ^ numerator
654− -> Expression schema from grouping params (nullity int)
657+ -> Expression db from grouping params (nullity int)
655658 -- ^ denominator
656− -> Expression schema from grouping params (nullity int)
659+ -> Expression db from grouping params (nullity int)
657660quot_ = unsafeBinaryOp "/"
658661
659662-- | remainder upon integer division
660663--
661664-- >>> :{
662665-- let
663−-- expression :: Expression schema from grouping params (nullity 'PGint2)
666+-- expression :: Expression db from grouping params (nullity 'PGint2)
664667-- expression = 5 `rem_` 2
665668-- in printSQL expression
666669-- :}
667670-- (5 % 2)
668671rem_
669672 :: int `In` PGIntegral
670− => Expression schema from grouping params (nullity int)
673+ => Expression db from grouping params (nullity int)
671674 -- ^ numerator
672− -> Expression schema from grouping params (nullity int)
675+ -> Expression db from grouping params (nullity int)
673676 -- ^ denominator
674− -> Expression schema from grouping params (nullity int)
677+ -> Expression db from grouping params (nullity int)
675678rem_ = unsafeBinaryOp "%"
676679
677680-- | >>> :{
678681-- let
679−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
682+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
680683-- expression = trunc pi
681684-- in printSQL expression
682685-- :}
683686-- trunc(pi())
684687trunc
685688 :: frac `In` PGFloating
686− => Expression schema from grouping params (nullity frac)
689+ => Expression db from grouping params (nullity frac)
687690 -- ^ fractional number
688− -> Expression schema from grouping params (nullity frac)
691+ -> Expression db from grouping params (nullity frac)
689692trunc = unsafeFunction "trunc"
690693
691694-- | >>> :{
692695-- let
693−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
696+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
694697-- expression = round_ pi
695698-- in printSQL expression
696699-- :}
697700-- round(pi())
698701round_
699702 :: frac `In` PGFloating
700− => Expression schema from grouping params (nullity frac)
703+ => Expression db from grouping params (nullity frac)
701704 -- ^ fractional number
702− -> Expression schema from grouping params (nullity frac)
705+ -> Expression db from grouping params (nullity frac)
703706round_ = unsafeFunction "round"
704707
705708-- | >>> :{
706709-- let
707−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
710+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
708711-- expression = ceiling_ pi
709712-- in printSQL expression
710713-- :}
711714-- ceiling(pi())
712715ceiling_
713716 :: frac `In` PGFloating
714− => Expression schema from grouping params (nullity frac)
717+ => Expression db from grouping params (nullity frac)
715718 -- ^ fractional number
716− -> Expression schema from grouping params (nullity frac)
719+ -> Expression db from grouping params (nullity frac)
717720ceiling_ = unsafeFunction "ceiling"
718721
719722-- | A `Condition` is an `Expression`, which can evaluate
720723-- to `true`, `false` or `null_`. This is because SQL uses
721724-- a three valued logic.
722−type Condition schema from grouping params =
723− Expression schema from grouping params ('Null 'PGbool)
725+type Condition db from grouping params =
726+ Expression db from grouping params ('Null 'PGbool)
724727
725728-- | >>> printSQL true
726729-- TRUE
727−true :: Expression schema from grouping params (nullity 'PGbool)
730+true :: Expression db from grouping params (nullity 'PGbool)
728731true = UnsafeExpression "TRUE"
729732
730733-- | >>> printSQL false
731734-- FALSE
732−false :: Expression schema from grouping params (nullity 'PGbool)
735+false :: Expression db from grouping params (nullity 'PGbool)
733736false = UnsafeExpression "FALSE"
734737
735738-- | >>> printSQL $ not_ true
736739-- (NOT TRUE)
737740not_
738− :: Expression schema from grouping params (nullity 'PGbool)
739− -> Expression schema from grouping params (nullity 'PGbool)
741+ :: Expression db from grouping params (nullity 'PGbool)
742+ -> Expression db from grouping params (nullity 'PGbool)
740743not_ = unsafeUnaryOp "NOT"
741744
742745-- | >>> printSQL $ true .&& false
743746-- (TRUE AND FALSE)
744747(.&&)
745− :: Expression schema from grouping params (nullity 'PGbool)
746− -> Expression schema from grouping params (nullity 'PGbool)
747− -> Expression schema from grouping params (nullity 'PGbool)
748+ :: Expression db from grouping params (nullity 'PGbool)
749+ -> Expression db from grouping params (nullity 'PGbool)
750+ -> Expression db from grouping params (nullity 'PGbool)
748751infixr 3 .&&
749752(.&&) = unsafeBinaryOp "AND"
750753
751754-- | >>> printSQL $ true .|| false
752755-- (TRUE OR FALSE)
753756(.||)
754− :: Expression schema from grouping params (nullity 'PGbool)
755− -> Expression schema from grouping params (nullity 'PGbool)
756− -> Expression schema from grouping params (nullity 'PGbool)
757+ :: Expression db from grouping params (nullity 'PGbool)
758+ -> Expression db from grouping params (nullity 'PGbool)
759+ -> Expression db from grouping params (nullity 'PGbool)
757760infixr 2 .||
758761(.||) = unsafeBinaryOp "OR"
759762
760763-- | >>> :{
761764-- let
762−-- expression :: Expression schema from grouping params (nullity 'PGint2)
765+-- expression :: Expression db from grouping params (nullity 'PGint2)
763766-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
764767-- in printSQL expression
765768-- :}
766769-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
767770caseWhenThenElse
768− :: [ ( Condition schema from grouping params
769− , Expression schema from grouping params ty
771+ :: [ ( Condition db from grouping params
772+ , Expression db from grouping params ty
770773 ) ]
771774 -- ^ whens and thens
772− -> Expression schema from grouping params ty
775+ -> Expression db from grouping params ty
773776 -- ^ else
774− -> Expression schema from grouping params ty
777+ -> Expression db from grouping params ty
775778caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
776779 [ "CASE"
777780 , mconcat
@@ -787,16 +790,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
787790
788791-- | >>> :{
789792-- let
790−-- expression :: Expression schema from grouping params (nullity 'PGint2)
793+-- expression :: Expression db from grouping params (nullity 'PGint2)
791794-- expression = ifThenElse true 1 0
792795-- in printSQL expression
793796-- :}
794797-- CASE WHEN TRUE THEN 1 ELSE 0 END
795798ifThenElse
796− :: Condition schema from grouping params
797− -> Expression schema from grouping params ty -- ^ then
798− -> Expression schema from grouping params ty -- ^ else
799− -> Expression schema from grouping params ty
799+ :: Condition db from grouping params
800+ -> Expression db from grouping params ty -- ^ then
801+ -> Expression db from grouping params ty -- ^ else
802+ -> Expression db from grouping params ty
800803ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
801804
802805-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -805,85 +808,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
805808-- >>> printSQL $ true .== null_
806809-- (TRUE = NULL)
807810(.==)
808− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
809− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
810− -> Condition schema from grouping params
811+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
812+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
813+ -> Condition db from grouping params
811814(.==) = unsafeBinaryOp "="
812815infix 4 .==
813816
814817-- | >>> printSQL $ true ./= null_
815818-- (TRUE <> NULL)
816819(./=)
817− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
818− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
819− -> Condition schema from grouping params
820+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
821+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
822+ -> Condition db from grouping params
820823(./=) = unsafeBinaryOp "<>"
821824infix 4 ./=
822825
823826-- | >>> printSQL $ true .>= null_
824827-- (TRUE >= NULL)
825828(.>=)
826− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
827− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
828− -> Condition schema from grouping params
829+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
830+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
831+ -> Condition db from grouping params
829832(.>=) = unsafeBinaryOp ">="
830833infix 4 .>=
831834
832835-- | >>> printSQL $ true .< null_
833836-- (TRUE < NULL)
834837(.<)
835− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
836− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
837− -> Condition schema from grouping params
838+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
839+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
840+ -> Condition db from grouping params
838841(.<) = unsafeBinaryOp "<"
839842infix 4 .<
840843
841844-- | >>> printSQL $ true .<= null_
842845-- (TRUE <= NULL)
843846(.<=)
844− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
845− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
846− -> Condition schema from grouping params
847+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
848+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
849+ -> Condition db from grouping params
847850(.<=) = unsafeBinaryOp "<="
848851infix 4 .<=
849852
850853-- | >>> printSQL $ true .> null_
851854-- (TRUE > NULL)
852855(.>)
853− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
854− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
855− -> Condition schema from grouping params
856+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
857+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
858+ -> Condition db from grouping params
856859(.>) = unsafeBinaryOp ">"
857860infix 4 .>
858861
859862-- | >>> printSQL currentDate
860863-- CURRENT_DATE
861864currentDate
862− :: Expression schema from grouping params (nullity 'PGdate)
865+ :: Expression db from grouping params (nullity 'PGdate)
863866currentDate = UnsafeExpression "CURRENT_DATE"
864867
865868-- | >>> printSQL currentTime
866869-- CURRENT_TIME
867870currentTime
868− :: Expression schema from grouping params (nullity 'PGtimetz)
871+ :: Expression db from grouping params (nullity 'PGtimetz)
869872currentTime = UnsafeExpression "CURRENT_TIME"
870873
871874-- | >>> printSQL currentTimestamp
872875-- CURRENT_TIMESTAMP
873876currentTimestamp
874− :: Expression schema from grouping params (nullity 'PGtimestamptz)
877+ :: Expression db from grouping params (nullity 'PGtimestamptz)
875878currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
876879
877880-- | >>> printSQL localTime
878881-- LOCALTIME
879882localTime
880− :: Expression schema from grouping params (nullity 'PGtime)
883+ :: Expression db from grouping params (nullity 'PGtime)
881884localTime = UnsafeExpression "LOCALTIME"
882885
883886-- | >>> printSQL localTimestamp
884887-- LOCALTIMESTAMP
885888localTimestamp
886− :: Expression schema from grouping params (nullity 'PGtimestamp)
889+ :: Expression db from grouping params (nullity 'PGtimestamp)
887890localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
888891
889892{-----------------------------------------
@@ -891,7 +894,7 @@ text
891894-----------------------------------------}
892895
893896instance IsString
894− (Expression schema from grouping params (nullity 'PGtext)) where
897+ (Expression db from grouping params (nullity 'PGtext)) where
895898 fromString str = UnsafeExpression $
896899 "E\'" <> fromString (escape =<< str) <> "\'"
897900 where
@@ -907,36 +910,36 @@ instance IsString
907910 c -> [c]
908911
909912instance Semigroup
910− (Expression schema from grouping params (nullity 'PGtext)) where
913+ (Expression db from grouping params (nullity 'PGtext)) where
911914 (<>) = unsafeBinaryOp "||"
912915
913916instance Monoid
914− (Expression schema from grouping params (nullity 'PGtext)) where
917+ (Expression db from grouping params (nullity 'PGtext)) where
915918 mempty = fromString ""
916919 mappend = (<>)
917920
918921-- | >>> printSQL $ lower "ARRRGGG"
919922-- lower(E'ARRRGGG')
920923lower
921− :: Expression schema from grouping params (nullity 'PGtext)
924+ :: Expression db from grouping params (nullity 'PGtext)
922925 -- ^ string to lower case
923− -> Expression schema from grouping params (nullity 'PGtext)
926+ -> Expression db from grouping params (nullity 'PGtext)
924927lower = unsafeFunction "lower"
925928
926929-- | >>> printSQL $ upper "eeee"
927930-- upper(E'eeee')
928931upper
929− :: Expression schema from grouping params (nullity 'PGtext)
932+ :: Expression db from grouping params (nullity 'PGtext)
930933 -- ^ string to upper case
931− -> Expression schema from grouping params (nullity 'PGtext)
934+ -> Expression db from grouping params (nullity 'PGtext)
932935upper = unsafeFunction "upper"
933936
934937-- | >>> printSQL $ charLength "four"
935938-- char_length(E'four')
936939charLength
937− :: Expression schema from grouping params (nullity 'PGtext)
940+ :: Expression db from grouping params (nullity 'PGtext)
938941 -- ^ string to measure
939− -> Expression schema from grouping params (nullity 'PGint4)
942+ -> Expression db from grouping params (nullity 'PGint4)
940943charLength = unsafeFunction "char_length"
941944
942945-- | The `like` expression returns true if the @string@ matches
@@ -949,11 +952,11 @@ charLength = unsafeFunction "char_length"
949952-- >>> printSQL $ "abc" `like` "a%"
950953-- (E'abc' LIKE E'a%')
951954like
952− :: Expression schema from grouping params (nullity 'PGtext)
955+ :: Expression db from grouping params (nullity 'PGtext)
953956 -- ^ string
954− -> Expression schema from grouping params (nullity 'PGtext)
957+ -> Expression db from grouping params (nullity 'PGtext)
955958 -- ^ pattern
956− -> Expression schema from grouping params (nullity 'PGbool)
959+ -> Expression db from grouping params (nullity 'PGbool)
957960like = unsafeBinaryOp "LIKE"
958961
959962-- | The key word ILIKE can be used instead of LIKE to make the
@@ -981,36 +984,36 @@ Table 9.44: json and jsonb operators
981984-- | Get JSON value (object field or array element) at a key.
982985(.->)
983986 :: (json `In` PGJsonType, key `In` PGJsonKey)
984− => Expression schema from grouping params (nullity json)
985− -> Expression schema from grouping params (nullity key)
986− -> Expression schema from grouping params ('Null json)
987+ => Expression db from grouping params (nullity json)
988+ -> Expression db from grouping params (nullity key)
989+ -> Expression db from grouping params ('Null json)
987990infixl 8 .->
988991(.->) = unsafeBinaryOp "->"
989992
990993-- | Get JSON value (object field or array element) at a key, as text.
991994(.->>)
992995 :: (json `In` PGJsonType, key `In` PGJsonKey)
993− => Expression schema from grouping params (nullity json)
994− -> Expression schema from grouping params (nullity key)
995− -> Expression schema from grouping params ('Null 'PGtext)
996+ => Expression db from grouping params (nullity json)
997+ -> Expression db from grouping params (nullity key)
998+ -> Expression db from grouping params ('Null 'PGtext)
996999infixl 8 .->>
9971000(.->>) = unsafeBinaryOp "->>"
9981001
9991002-- | Get JSON value at a specified path.
10001003(.#>)
10011004 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1002− => Expression schema from grouping params (nullity json)
1003− -> Expression schema from grouping params (nullity path)
1004− -> Expression schema from grouping params ('Null json)
1005+ => Expression db from grouping params (nullity json)
1006+ -> Expression db from grouping params (nullity path)
1007+ -> Expression db from grouping params ('Null json)
10051008infixl 8 .#>
10061009(.#>) = unsafeBinaryOp "#>"
10071010
10081011-- | Get JSON value at a specified path as text.
10091012(.#>>)
10101013 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1011− => Expression schema from grouping params (nullity json)
1012− -> Expression schema from grouping params (nullity path)
1013− -> Expression schema from grouping params ('Null 'PGtext)
1014+ => Expression db from grouping params (nullity json)
1015+ -> Expression db from grouping params (nullity path)
1016+ -> Expression db from grouping params ('Null 'PGtext)
10141017infixl 8 .#>>
10151018(.#>>) = unsafeBinaryOp "#>>"
10161019
@@ -1019,48 +1022,48 @@ infixl 8 .#>>
10191022-- | Does the left JSON value contain the right JSON path/value entries at the
10201023-- top level?
10211024(.@>)
1022− :: Expression schema from grouping params (nullity 'PGjsonb)
1023− -> Expression schema from grouping params (nullity 'PGjsonb)
1024− -> Condition schema from grouping params
1025+ :: Expression db from grouping params (nullity 'PGjsonb)
1026+ -> Expression db from grouping params (nullity 'PGjsonb)
1027+ -> Condition db from grouping params
10251028infixl 9 .@>
10261029(.@>) = unsafeBinaryOp "@>"
10271030
10281031-- | Are the left JSON path/value entries contained at the top level within the
10291032-- right JSON value?
10301033(.<@)
1031− :: Expression schema from grouping params (nullity 'PGjsonb)
1032− -> Expression schema from grouping params (nullity 'PGjsonb)
1033− -> Condition schema from grouping params
1034+ :: Expression db from grouping params (nullity 'PGjsonb)
1035+ -> Expression db from grouping params (nullity 'PGjsonb)
1036+ -> Condition db from grouping params
10341037infixl 9 .<@
10351038(.<@) = unsafeBinaryOp "<@"
10361039
10371040-- | Does the string exist as a top-level key within the JSON value?
10381041(.?)
1039− :: Expression schema from grouping params (nullity 'PGjsonb)
1040− -> Expression schema from grouping params (nullity 'PGtext)
1041− -> Condition schema from grouping params
1042+ :: Expression db from grouping params (nullity 'PGjsonb)
1043+ -> Expression db from grouping params (nullity 'PGtext)
1044+ -> Condition db from grouping params
10421045infixl 9 .?
10431046(.?) = unsafeBinaryOp "?"
10441047
10451048-- | Do any of these array strings exist as top-level keys?
10461049(.?|)
1047− :: Expression schema from grouping params (nullity 'PGjsonb)
1048− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1049− -> Condition schema from grouping params
1050+ :: Expression db from grouping params (nullity 'PGjsonb)
1051+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1052+ -> Condition db from grouping params
10501053infixl 9 .?|
10511054(.?|) = unsafeBinaryOp "?|"
10521055
10531056-- | Do all of these array strings exist as top-level keys?
10541057(.?&)
1055− :: Expression schema from grouping params (nullity 'PGjsonb)
1056− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1057− -> Condition schema from grouping params
1058+ :: Expression db from grouping params (nullity 'PGjsonb)
1059+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1060+ -> Condition db from grouping params
10581061infixl 9 .?&
10591062(.?&) = unsafeBinaryOp "?&"
10601063
10611064-- | Concatenate two jsonb values into a new jsonb value.
10621065instance
1063− Semigroup (Expression schema from grouping param (nullity 'PGjsonb)) where
1066+ Semigroup (Expression db from grouping param (nullity 'PGjsonb)) where
10641067 (<>) = unsafeBinaryOp "||"
10651068
10661069-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1077,9 +1080,9 @@ instance
10771080-- count from the end). Throws an error if top level container is not an array.
10781081(.-.)
10791082 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1080− => Expression schema from grouping params (nullity 'PGjsonb)
1081− -> Expression schema from grouping params (nullity key)
1082− -> Expression schema from grouping params (nullity 'PGjsonb)
1083+ => Expression db from grouping params (nullity 'PGjsonb)
1084+ -> Expression db from grouping params (nullity key)
1085+ -> Expression db from grouping params (nullity 'PGjsonb)
10831086infixl 6 .-.
10841087(.-.) = unsafeBinaryOp "-"
10851088
@@ -1087,9 +1090,9 @@ infixl 6 .-.
10871090-- integers count from the end)
10881091(#-.)
10891092 :: PGTextArray "(#-.)" arrayty
1090− => Expression schema from grouping params (nullity 'PGjsonb)
1091− -> Expression schema from grouping params (nullity arrayty)
1092− -> Expression schema from grouping params (nullity 'PGjsonb)
1093+ => Expression db from grouping params (nullity 'PGjsonb)
1094+ -> Expression db from grouping params (nullity arrayty)
1095+ -> Expression db from grouping params (nullity 'PGjsonb)
10931096infixl 6 #-.
10941097(#-.) = unsafeBinaryOp "#-"
10951098
@@ -1100,14 +1103,14 @@ Table 9.45: JSON creation functions
11001103-- | Literal binary JSON
11011104jsonbLit
11021105 :: JSON.ToJSON x
1103− => x -> Expression schema from grouping params (nullity 'PGjsonb)
1106+ => x -> Expression (commons :=> schemas) from grouping params (nullity 'PGjsonb)
11041107jsonbLit = cast jsonb . UnsafeExpression
11051108 . singleQuotedUtf8 . toStrict . JSON.encode
11061109
11071110-- | Literal JSON
11081111jsonLit
11091112 :: JSON.ToJSON x
1110− => x -> Expression schema from grouping params (nullity 'PGjson)
1113+ => x -> Expression (commons :=> schemas) from grouping params (nullity 'PGjson)
11111114jsonLit = cast json . UnsafeExpression
11121115 . singleQuotedUtf8 . toStrict . JSON.encode
11131116
@@ -1118,8 +1121,8 @@ jsonLit = cast json . UnsafeExpression
11181121-- number, a Boolean, or a null value, the text representation will be used, in
11191122-- such a fashion that it is a valid json value.
11201123toJson
1121− :: Expression schema from grouping params (nullity ty)
1122− -> Expression schema from grouping params (nullity 'PGjson)
1124+ :: Expression db from grouping params (nullity ty)
1125+ -> Expression db from grouping params (nullity 'PGjson)
11231126toJson = unsafeFunction "to_json"
11241127
11251128-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1129,43 +1132,43 @@ toJson = unsafeFunction "to_json"
11291132-- number, a Boolean, or a null value, the text representation will be used, in
11301133-- such a fashion that it is a valid jsonb value.
11311134toJsonb
1132− :: Expression schema from grouping params (nullity ty)
1133− -> Expression schema from grouping params (nullity 'PGjsonb)
1135+ :: Expression db from grouping params (nullity ty)
1136+ -> Expression db from grouping params (nullity 'PGjsonb)
11341137toJsonb = unsafeFunction "to_jsonb"
11351138
11361139-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
11371140-- becomes a JSON array of arrays.
11381141arrayToJson
11391142 :: PGArray "arrayToJson" arr
1140− => Expression schema from grouping params (nullity arr)
1141− -> Expression schema from grouping params (nullity 'PGjson)
1143+ => Expression db from grouping params (nullity arr)
1144+ -> Expression db from grouping params (nullity 'PGjson)
11421145arrayToJson = unsafeFunction "array_to_json"
11431146
11441147-- | Returns the row as a JSON object.
11451148rowToJson
1146− :: Expression schema from grouping params (nullity ('PGcomposite ty))
1147− -> Expression schema from grouping params (nullity 'PGjson)
1149+ :: Expression db from grouping params (nullity ('PGcomposite ty))
1150+ -> Expression db from grouping params (nullity 'PGjson)
11481151rowToJson = unsafeFunction "row_to_json"
11491152
11501153-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
11511154-- argument list.
11521155jsonBuildArray
11531156 :: SListI elems
1154− => NP (Expression schema from grouping params) elems
1155− -> Expression schema from grouping params (nullity 'PGjson)
1157+ => NP (Expression db from grouping params) elems
1158+ -> Expression db from grouping params (nullity 'PGjson)
11561159jsonBuildArray = unsafeVariadicFunction "json_build_array"
11571160
11581161-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
11591162-- variadic argument list.
11601163jsonbBuildArray
11611164 :: SListI elems
1162− => NP (Expression schema from grouping params) elems
1163− -> Expression schema from grouping params (nullity 'PGjsonb)
1165+ => NP (Expression db from grouping params) elems
1166+ -> Expression db from grouping params (nullity 'PGjsonb)
11641167jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
11651168
11661169unsafeRowFunction
11671170 :: All Top elems
1168− => NP (Aliased (Expression schema from grouping params)) elems
1171+ => NP (Aliased (Expression db from grouping params)) elems
11691172 -> [ByteString]
11701173unsafeRowFunction =
11711174 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1177,8 +1180,8 @@ unsafeRowFunction =
11771180-- and values.
11781181jsonBuildObject
11791182 :: All Top elems
1180− => NP (Aliased (Expression schema from grouping params)) elems
1181− -> Expression schema from grouping params (nullity 'PGjson)
1183+ => NP (Aliased (Expression db from grouping params)) elems
1184+ -> Expression db from grouping params (nullity 'PGjson)
11821185jsonBuildObject
11831186 = unsafeFunction "json_build_object"
11841187 . UnsafeExpression
@@ -1190,8 +1193,8 @@ jsonBuildObject
11901193-- between text and values.
11911194jsonbBuildObject
11921195 :: All Top elems
1193− => NP (Aliased (Expression schema from grouping params)) elems
1194− -> Expression schema from grouping params (nullity 'PGjsonb)
1196+ => NP (Aliased (Expression db from grouping params)) elems
1197+ -> Expression db from grouping params (nullity 'PGjsonb)
11951198jsonbBuildObject
11961199 = unsafeFunction "jsonb_build_object"
11971200 . UnsafeExpression
@@ -1204,8 +1207,8 @@ jsonbBuildObject
12041207-- array has exactly two elements, which are taken as a key/value pair.
12051208jsonObject
12061209 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1207− => Expression schema from grouping params (nullity arr)
1208− -> Expression schema from grouping params (nullity 'PGjson)
1210+ => Expression db from grouping params (nullity arr)
1211+ -> Expression db from grouping params (nullity 'PGjson)
12091212jsonObject = unsafeFunction "json_object"
12101213
12111214-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1214,8 +1217,8 @@ jsonObject = unsafeFunction "json_object"
12141217-- array has exactly two elements, which are taken as a key/value pair.
12151218jsonbObject
12161219 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1217− => Expression schema from grouping params (nullity arr)
1218− -> Expression schema from grouping params (nullity 'PGjsonb)
1220+ => Expression db from grouping params (nullity arr)
1221+ -> Expression db from grouping params (nullity 'PGjsonb)
12191222jsonbObject = unsafeFunction "jsonb_object"
12201223
12211224-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1223,9 +1226,9 @@ jsonbObject = unsafeFunction "jsonb_object"
12231226jsonZipObject
12241227 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
12251228 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1226− => Expression schema from grouping params (nullity keysArray)
1227− -> Expression schema from grouping params (nullity valuesArray)
1228− -> Expression schema from grouping params (nullity 'PGjson)
1229+ => Expression db from grouping params (nullity keysArray)
1230+ -> Expression db from grouping params (nullity valuesArray)
1231+ -> Expression db from grouping params (nullity 'PGjson)
12291232jsonZipObject ks vs =
12301233 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
12311234
@@ -1235,9 +1238,9 @@ jsonZipObject ks vs =
12351238jsonbZipObject
12361239 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
12371240 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1238− => Expression schema from grouping params (nullity keysArray)
1239− -> Expression schema from grouping params (nullity valuesArray)
1240− -> Expression schema from grouping params (nullity 'PGjsonb)
1241+ => Expression db from grouping params (nullity keysArray)
1242+ -> Expression db from grouping params (nullity valuesArray)
1243+ -> Expression db from grouping params (nullity 'PGjsonb)
12411244jsonbZipObject ks vs =
12421245 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
12431246
@@ -1247,23 +1250,23 @@ Table 9.46: JSON processing functions
12471250
12481251-- | Returns the number of elements in the outermost JSON array.
12491252jsonArrayLength
1250− :: Expression schema from grouping params (nullity 'PGjson)
1251− -> Expression schema from grouping params (nullity 'PGint4)
1253+ :: Expression db from grouping params (nullity 'PGjson)
1254+ -> Expression db from grouping params (nullity 'PGint4)
12521255jsonArrayLength = unsafeFunction "json_array_length"
12531256
12541257-- | Returns the number of elements in the outermost binary JSON array.
12551258jsonbArrayLength
1256− :: Expression schema from grouping params (nullity 'PGjsonb)
1257− -> Expression schema from grouping params (nullity 'PGint4)
1259+ :: Expression db from grouping params (nullity 'PGjsonb)
1260+ -> Expression db from grouping params (nullity 'PGint4)
12581261jsonbArrayLength = unsafeFunction "jsonb_array_length"
12591262
12601263-- | Returns JSON value pointed to by the given path (equivalent to #>
12611264-- operator).
12621265jsonExtractPath
12631266 :: SListI elems
1264− => Expression schema from grouping params (nullity 'PGjson)
1265− -> NP (Expression schema from grouping params) elems
1266− -> Expression schema from grouping params (nullity 'PGjsonb)
1267+ => Expression db from grouping params (nullity 'PGjson)
1268+ -> NP (Expression db from grouping params) elems
1269+ -> Expression db from grouping params (nullity 'PGjsonb)
12671270jsonExtractPath x xs =
12681271 unsafeVariadicFunction "json_extract_path" (x :* xs)
12691272
@@ -1271,9 +1274,9 @@ jsonExtractPath x xs =
12711274-- operator).
12721275jsonbExtractPath
12731276 :: SListI elems
1274− => Expression schema from grouping params (nullity 'PGjsonb)
1275− -> NP (Expression schema from grouping params) elems
1276− -> Expression schema from grouping params (nullity 'PGjsonb)
1277+ => Expression db from grouping params (nullity 'PGjsonb)
1278+ -> NP (Expression db from grouping params) elems
1279+ -> Expression db from grouping params (nullity 'PGjsonb)
12771280jsonbExtractPath x xs =
12781281 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
12791282
@@ -1281,9 +1284,9 @@ jsonbExtractPath x xs =
12811284-- operator), as text.
12821285jsonExtractPathAsText
12831286 :: SListI elems
1284− => Expression schema from grouping params (nullity 'PGjson)
1285− -> NP (Expression schema from grouping params) elems
1286− -> Expression schema from grouping params (nullity 'PGjson)
1287+ => Expression db from grouping params (nullity 'PGjson)
1288+ -> NP (Expression db from grouping params) elems
1289+ -> Expression db from grouping params (nullity 'PGjson)
12871290jsonExtractPathAsText x xs =
12881291 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
12891292
@@ -1291,38 +1294,38 @@ jsonExtractPathAsText x xs =
12911294-- operator), as text.
12921295jsonbExtractPathAsText
12931296 :: SListI elems
1294− => Expression schema from grouping params (nullity 'PGjsonb)
1295− -> NP (Expression schema from grouping params) elems
1296− -> Expression schema from grouping params (nullity 'PGjsonb)
1297+ => Expression db from grouping params (nullity 'PGjsonb)
1298+ -> NP (Expression db from grouping params) elems
1299+ -> Expression db from grouping params (nullity 'PGjsonb)
12971300jsonbExtractPathAsText x xs =
12981301 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
12991302
13001303-- | Returns the type of the outermost JSON value as a text string. Possible
13011304-- types are object, array, string, number, boolean, and null.
13021305jsonTypeof
1303− :: Expression schema from grouping params (nullity 'PGjson)
1304− -> Expression schema from grouping params (nullity 'PGtext)
1306+ :: Expression db from grouping params (nullity 'PGjson)
1307+ -> Expression db from grouping params (nullity 'PGtext)
13051308jsonTypeof = unsafeFunction "json_typeof"
13061309
13071310-- | Returns the type of the outermost binary JSON value as a text string.
13081311-- Possible types are object, array, string, number, boolean, and null.
13091312jsonbTypeof
1310− :: Expression schema from grouping params (nullity 'PGjsonb)
1311− -> Expression schema from grouping params (nullity 'PGtext)
1313+ :: Expression db from grouping params (nullity 'PGjsonb)
1314+ -> Expression db from grouping params (nullity 'PGtext)
13121315jsonbTypeof = unsafeFunction "jsonb_typeof"
13131316
13141317-- | Returns its argument with all object fields that have null values omitted.
13151318-- Other null values are untouched.
13161319jsonStripNulls
1317− :: Expression schema from grouping params (nullity 'PGjson)
1318− -> Expression schema from grouping params (nullity 'PGjson)
1320+ :: Expression db from grouping params (nullity 'PGjson)
1321+ -> Expression db from grouping params (nullity 'PGjson)
13191322jsonStripNulls = unsafeFunction "json_strip_nulls"
13201323
13211324-- | Returns its argument with all object fields that have null values omitted.
13221325-- Other null values are untouched.
13231326jsonbStripNulls
1324− :: Expression schema from grouping params (nullity 'PGjsonb)
1325− -> Expression schema from grouping params (nullity 'PGjsonb)
1327+ :: Expression db from grouping params (nullity 'PGjsonb)
1328+ -> Expression db from grouping params (nullity 'PGjsonb)
13261329jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13271330
13281331-- | @ jsonbSet target path new_value create_missing @
@@ -1334,11 +1337,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13341337-- arrays.
13351338jsonbSet
13361339 :: PGTextArray "jsonbSet" arr
1337− => Expression schema from grouping params (nullity 'PGjsonb)
1338− -> Expression schema from grouping params (nullity arr)
1339− -> Expression schema from grouping params (nullity 'PGjsonb)
1340− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1341− -> Expression schema from grouping params (nullity 'PGjsonb)
1340+ => Expression db from grouping params (nullity 'PGjsonb)
1341+ -> Expression db from grouping params (nullity arr)
1342+ -> Expression db from grouping params (nullity 'PGjsonb)
1343+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1344+ -> Expression db from grouping params (nullity 'PGjsonb)
13421345jsonbSet tgt path val createMissing = case createMissing of
13431346 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
13441347 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1353,19 +1356,19 @@ jsonbSet tgt path val createMissing = case createMissing of
13531356-- in path count from the end of JSON arrays.
13541357jsonbInsert
13551358 :: PGTextArray "jsonbInsert" arr
1356− => Expression schema from grouping params (nullity 'PGjsonb)
1357− -> Expression schema from grouping params (nullity arr)
1358− -> Expression schema from grouping params (nullity 'PGjsonb)
1359− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1360− -> Expression schema from grouping params (nullity 'PGjsonb)
1359+ => Expression db from grouping params (nullity 'PGjsonb)
1360+ -> Expression db from grouping params (nullity arr)
1361+ -> Expression db from grouping params (nullity 'PGjsonb)
1362+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1363+ -> Expression db from grouping params (nullity 'PGjsonb)
13611364jsonbInsert tgt path val insertAfter = case insertAfter of
13621365 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
13631366 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
13641367
13651368-- | Returns its argument as indented JSON text.
13661369jsonbPretty
1367− :: Expression schema from grouping params (nullity 'PGjsonb)
1368− -> Expression schema from grouping params (nullity 'PGtext)
1370+ :: Expression db from grouping params (nullity 'PGjsonb)
1371+ -> Expression db from grouping params (nullity 'PGtext)
13691372jsonbPretty = unsafeFunction "jsonb_pretty"
13701373
13711374{-----------------------------------------
@@ -1375,54 +1378,54 @@ aggregation
13751378-- | escape hatch to define aggregate functions
13761379unsafeAggregate
13771380 :: ByteString -- ^ aggregate function
1378− -> Expression schema from 'Ungrouped params (xty)
1379− -> Expression schema from ('Grouped bys) params (yty)
1381+ -> Expression db from 'Ungrouped params (xty)
1382+ -> Expression db from ('Grouped bys) params (yty)
13801383unsafeAggregate fun x = UnsafeExpression $ mconcat
13811384 [fun, "(", renderExpression x, ")"]
13821385
13831386-- | escape hatch to define aggregate functions over distinct values
13841387unsafeAggregateDistinct
13851388 :: ByteString -- ^ aggregate function
1386− -> Expression schema from 'Ungrouped params (xty)
1387− -> Expression schema from ('Grouped bys) params (yty)
1389+ -> Expression db from 'Ungrouped params (xty)
1390+ -> Expression db from ('Grouped bys) params (yty)
13881391unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
13891392 [fun, "(DISTINCT ", renderExpression x, ")"]
13901393
13911394-- | >>> :{
13921395-- let
1393−-- expression :: Expression schema '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
1396+-- expression :: Expression db '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
13941397-- expression = sum_ #col
13951398-- in printSQL expression
13961399-- :}
13971400-- sum("col")
13981401sum_
13991402 :: ty `In` PGNum
1400− => Expression schema from 'Ungrouped params (nullity ty)
1403+ => Expression db from 'Ungrouped params (nullity ty)
14011404 -- ^ what to sum
1402− -> Expression schema from ('Grouped bys) params (nullity ty)
1405+ -> Expression db from ('Grouped bys) params (nullity ty)
14031406sum_ = unsafeAggregate "sum"
14041407
14051408-- | >>> :{
14061409-- let
1407−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
1410+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
14081411-- expression = sumDistinct #col
14091412-- in printSQL expression
14101413-- :}
14111414-- sum(DISTINCT "col")
14121415sumDistinct
14131416 :: ty `In` PGNum
1414− => Expression schema from 'Ungrouped params (nullity ty)
1417+ => Expression db from 'Ungrouped params (nullity ty)
14151418 -- ^ what to sum
1416− -> Expression schema from ('Grouped bys) params (nullity ty)
1419+ -> Expression db from ('Grouped bys) params (nullity ty)
14171420sumDistinct = unsafeAggregateDistinct "sum"
14181421
14191422-- | A constraint for `PGType`s that you can take averages of and the resulting
14201423-- `PGType`.
14211424class PGAvg ty avg | ty -> avg where
14221425 avg, avgDistinct
1423− :: Expression schema from 'Ungrouped params (nullity ty)
1426+ :: Expression db from 'Ungrouped params (nullity ty)
14241427 -- ^ what to average
1425− -> Expression schema from ('Grouped bys) params (nullity avg)
1428+ -> Expression db from ('Grouped bys) params (nullity avg)
14261429 avg = unsafeAggregate "avg"
14271430 avgDistinct = unsafeAggregateDistinct "avg"
14281431instance PGAvg 'PGint2 'PGnumeric
@@ -1435,110 +1438,110 @@ instance PGAvg 'PGinterval 'PGinterval
14351438
14361439-- | >>> :{
14371440-- let
1438−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1441+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14391442-- expression = bitAnd #col
14401443-- in printSQL expression
14411444-- :}
14421445-- bit_and("col")
14431446bitAnd
14441447 :: int `In` PGIntegral
1445− => Expression schema from 'Ungrouped params (nullity int)
1448+ => Expression db from 'Ungrouped params (nullity int)
14461449 -- ^ what to aggregate
1447− -> Expression schema from ('Grouped bys) params (nullity int)
1450+ -> Expression db from ('Grouped bys) params (nullity int)
14481451bitAnd = unsafeAggregate "bit_and"
14491452
14501453-- | >>> :{
14511454-- let
1452−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1455+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14531456-- expression = bitOr #col
14541457-- in printSQL expression
14551458-- :}
14561459-- bit_or("col")
14571460bitOr
14581461 :: int `In` PGIntegral
1459− => Expression schema from 'Ungrouped params (nullity int)
1462+ => Expression db from 'Ungrouped params (nullity int)
14601463 -- ^ what to aggregate
1461− -> Expression schema from ('Grouped bys) params (nullity int)
1464+ -> Expression db from ('Grouped bys) params (nullity int)
14621465bitOr = unsafeAggregate "bit_or"
14631466
14641467-- | >>> :{
14651468-- let
1466−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1469+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14671470-- expression = bitAndDistinct #col
14681471-- in printSQL expression
14691472-- :}
14701473-- bit_and(DISTINCT "col")
14711474bitAndDistinct
14721475 :: int `In` PGIntegral
1473− => Expression schema from 'Ungrouped params (nullity int)
1476+ => Expression db from 'Ungrouped params (nullity int)
14741477 -- ^ what to aggregate
1475− -> Expression schema from ('Grouped bys) params (nullity int)
1478+ -> Expression db from ('Grouped bys) params (nullity int)
14761479bitAndDistinct = unsafeAggregateDistinct "bit_and"
14771480
14781481-- | >>> :{
14791482-- let
1480−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1483+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14811484-- expression = bitOrDistinct #col
14821485-- in printSQL expression
14831486-- :}
14841487-- bit_or(DISTINCT "col")
14851488bitOrDistinct
14861489 :: int `In` PGIntegral
1487− => Expression schema from 'Ungrouped params (nullity int)
1490+ => Expression db from 'Ungrouped params (nullity int)
14881491 -- ^ what to aggregate
1489− -> Expression schema from ('Grouped bys) params (nullity int)
1492+ -> Expression db from ('Grouped bys) params (nullity int)
14901493bitOrDistinct = unsafeAggregateDistinct "bit_or"
14911494
14921495-- | >>> :{
14931496-- let
1494−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1497+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
14951498-- expression = boolAnd #col
14961499-- in printSQL expression
14971500-- :}
14981501-- bool_and("col")
14991502boolAnd
1500− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1503+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15011504 -- ^ what to aggregate
1502− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1505+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15031506boolAnd = unsafeAggregate "bool_and"
15041507
15051508-- | >>> :{
15061509-- let
1507−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1510+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15081511-- expression = boolOr #col
15091512-- in printSQL expression
15101513-- :}
15111514-- bool_or("col")
15121515boolOr
1513− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1516+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15141517 -- ^ what to aggregate
1515− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1518+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15161519boolOr = unsafeAggregate "bool_or"
15171520
15181521-- | >>> :{
15191522-- let
1520−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1523+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15211524-- expression = boolAndDistinct #col
15221525-- in printSQL expression
15231526-- :}
15241527-- bool_and(DISTINCT "col")
15251528boolAndDistinct
1526− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1529+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15271530 -- ^ what to aggregate
1528− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1531+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15291532boolAndDistinct = unsafeAggregateDistinct "bool_and"
15301533
15311534-- | >>> :{
15321535-- let
1533−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1536+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15341537-- expression = boolOrDistinct #col
15351538-- in printSQL expression
15361539-- :}
15371540-- bool_or(DISTINCT "col")
15381541boolOrDistinct
1539− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1542+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15401543 -- ^ what to aggregate
1541− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1544+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15421545boolOrDistinct = unsafeAggregateDistinct "bool_or"
15431546
15441547-- | A special aggregation that does not require an input
@@ -1546,70 +1549,70 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
15461549-- >>> printSQL countStar
15471550-- count(*)
15481551countStar
1549− :: Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1552+ :: Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15501553countStar = UnsafeExpression $ "count(*)"
15511554
15521555-- | >>> :{
15531556-- let
1554−-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1557+-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
15551558-- expression = count #col
15561559-- in printSQL expression
15571560-- :}
15581561-- count("col")
15591562count
1560− :: Expression schema from 'Ungrouped params ty
1563+ :: Expression db from 'Ungrouped params ty
15611564 -- ^ what to count
1562− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1565+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15631566count = unsafeAggregate "count"
15641567
15651568-- | >>> :{
15661569-- let
1567−-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1570+-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
15681571-- expression = countDistinct #col
15691572-- in printSQL expression
15701573-- :}
15711574-- count(DISTINCT "col")
15721575countDistinct
1573− :: Expression schema from 'Ungrouped params ty
1576+ :: Expression db from 'Ungrouped params ty
15741577 -- ^ what to count
1575− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1578+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15761579countDistinct = unsafeAggregateDistinct "count"
15771580
15781581-- | synonym for `boolAnd`
15791582--
15801583-- >>> :{
15811584-- let
1582−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1585+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15831586-- expression = every #col
15841587-- in printSQL expression
15851588-- :}
15861589-- every("col")
15871590every
1588− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1591+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15891592 -- ^ what to aggregate
1590− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1593+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15911594every = unsafeAggregate "every"
15921595
15931596-- | synonym for `boolAndDistinct`
15941597--
15951598-- >>> :{
15961599-- let
1597−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1600+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15981601-- expression = everyDistinct #col
15991602-- in printSQL expression
16001603-- :}
16011604-- every(DISTINCT "col")
16021605everyDistinct
1603− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1606+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
16041607 -- ^ what to aggregate
1605− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1608+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
16061609everyDistinct = unsafeAggregateDistinct "every"
16071610
16081611-- | minimum and maximum aggregation
16091612max_, min_, maxDistinct, minDistinct
1610− :: Expression schema from 'Ungrouped params (nullity ty)
1613+ :: Expression db from 'Ungrouped params (nullity ty)
16111614 -- ^ what to aggregate
1612− -> Expression schema from ('Grouped bys) params (nullity ty)
1615+ -> Expression db from ('Grouped bys) params (nullity ty)
16131616max_ = unsafeAggregate "max"
16141617min_ = unsafeAggregate "min"
16151618maxDistinct = unsafeAggregateDistinct "max"
@@ -1620,153 +1623,153 @@ type expressions
16201623-----------------------------------------}
16211624
16221625-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1623−newtype TypeExpression (schema :: SchemaType) (ty :: NullityType)
1626+newtype TypeExpression (schemas :: SchemasType) (ty :: NullityType)
16241627 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
16251628 deriving (GHC.Generic,Show,Eq,Ord,NFData)
16261629
16271630-- | The enum or composite type in a `Typedef` can be expressed by its alias.
16281631typedef
1629− :: Has alias schema ('Typedef ty)
1630− => Alias alias
1631− -> TypeExpression schema (nullity ty)
1632−typedef = UnsafeTypeExpression . renderAlias
1632+ :: (Has sch schemas schema, Has td schema ('Typedef ty))
1633+ => QualifiedAlias sch td
1634+ -> TypeExpression schemas (nullity ty)
1635+typedef = UnsafeTypeExpression . renderQualifiedAlias
16331636
16341637-- | The composite type corresponding to a `Table` definition can be expressed
16351638-- by its alias.
16361639typetable
1637− :: Has alias schema ('Table tab)
1638− => Alias alias
1639− -> TypeExpression schema (nullity ('PGcomposite (TableToRow tab)))
1640−typetable = UnsafeTypeExpression . renderAlias
1640+ :: (Has sch schemas schema, Has tab schema ('Table table))
1641+ => QualifiedAlias sch tab
1642+ -> TypeExpression schemas (nullity ('PGcomposite (TableToRow table)))
1643+typetable = UnsafeTypeExpression . renderQualifiedAlias
16411644
16421645-- | The composite type corresponding to a `View` definition can be expressed
16431646-- by its alias.
16441647typeview
1645− :: Has alias schema ('View view)
1646− => Alias alias
1647− -> TypeExpression schema (nullity ('PGcomposite view))
1648−typeview = UnsafeTypeExpression . renderAlias
1648+ :: (Has sch schemas schema, Has vw schema ('View view))
1649+ => QualifiedAlias sch vw
1650+ -> TypeExpression schemas (nullity ('PGcomposite view))
1651+typeview = UnsafeTypeExpression . renderQualifiedAlias
16491652
16501653-- | logical Boolean (true/false)
1651−bool :: TypeExpression schema (nullity 'PGbool)
1654+bool :: TypeExpression schemas (nullity 'PGbool)
16521655bool = UnsafeTypeExpression "bool"
16531656-- | signed two-byte integer
1654−int2, smallint :: TypeExpression schema (nullity 'PGint2)
1657+int2, smallint :: TypeExpression schemas (nullity 'PGint2)
16551658int2 = UnsafeTypeExpression "int2"
16561659smallint = UnsafeTypeExpression "smallint"
16571660-- | signed four-byte integer
1658−int4, int, integer :: TypeExpression schema (nullity 'PGint4)
1661+int4, int, integer :: TypeExpression schemas (nullity 'PGint4)
16591662int4 = UnsafeTypeExpression "int4"
16601663int = UnsafeTypeExpression "int"
16611664integer = UnsafeTypeExpression "integer"
16621665-- | signed eight-byte integer
1663−int8, bigint :: TypeExpression schema (nullity 'PGint8)
1666+int8, bigint :: TypeExpression schemas (nullity 'PGint8)
16641667int8 = UnsafeTypeExpression "int8"
16651668bigint = UnsafeTypeExpression "bigint"
16661669-- | arbitrary precision numeric type
1667−numeric :: TypeExpression schema (nullity 'PGnumeric)
1670+numeric :: TypeExpression schemas (nullity 'PGnumeric)
16681671numeric = UnsafeTypeExpression "numeric"
16691672-- | single precision floating-point number (4 bytes)
1670−float4, real :: TypeExpression schema (nullity 'PGfloat4)
1673+float4, real :: TypeExpression schemas (nullity 'PGfloat4)
16711674float4 = UnsafeTypeExpression "float4"
16721675real = UnsafeTypeExpression "real"
16731676-- | double precision floating-point number (8 bytes)
1674−float8, doublePrecision :: TypeExpression schema (nullity 'PGfloat8)
1677+float8, doublePrecision :: TypeExpression schemas (nullity 'PGfloat8)
16751678float8 = UnsafeTypeExpression "float8"
16761679doublePrecision = UnsafeTypeExpression "double precision"
16771680-- | variable-length character string
1678−text :: TypeExpression schema (nullity 'PGtext)
1681+text :: TypeExpression schemas (nullity 'PGtext)
16791682text = UnsafeTypeExpression "text"
16801683-- | fixed-length character string
16811684char, character
1682− :: forall n schema nullity. (KnownNat n, 1 <= n)
1683− => TypeExpression schema (nullity ('PGchar n))
1685+ :: forall n schemas nullity. (KnownNat n, 1 <= n)
1686+ => TypeExpression schemas (nullity ('PGchar n))
16841687char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
16851688character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
16861689-- | variable-length character string
16871690varchar, characterVarying
1688− :: forall n schema nullity. (KnownNat n, 1 <= n)
1689− => TypeExpression schema (nullity ('PGvarchar n))
1691+ :: forall n schemas nullity. (KnownNat n, 1 <= n)
1692+ => TypeExpression schemas (nullity ('PGvarchar n))
16901693varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
16911694characterVarying = UnsafeTypeExpression $
16921695 "character varying(" <> renderNat @n <> ")"
16931696-- | binary data ("byte array")
1694−bytea :: TypeExpression schema (nullity 'PGbytea)
1697+bytea :: TypeExpression schemas (nullity 'PGbytea)
16951698bytea = UnsafeTypeExpression "bytea"
16961699-- | date and time (no time zone)
1697−timestamp :: TypeExpression schema (nullity 'PGtimestamp)
1700+timestamp :: TypeExpression schemas (nullity 'PGtimestamp)
16981701timestamp = UnsafeTypeExpression "timestamp"
16991702-- | date and time, including time zone
1700−timestampWithTimeZone :: TypeExpression schema (nullity 'PGtimestamptz)
1703+timestampWithTimeZone :: TypeExpression schemas (nullity 'PGtimestamptz)
17011704timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
17021705-- | calendar date (year, month, day)
1703−date :: TypeExpression schema (nullity 'PGdate)
1706+date :: TypeExpression schemas (nullity 'PGdate)
17041707date = UnsafeTypeExpression "date"
17051708-- | time of day (no time zone)
1706−time :: TypeExpression schema (nullity 'PGtime)
1709+time :: TypeExpression schemas (nullity 'PGtime)
17071710time = UnsafeTypeExpression "time"
17081711-- | time of day, including time zone
1709−timeWithTimeZone :: TypeExpression schema (nullity 'PGtimetz)
1712+timeWithTimeZone :: TypeExpression schemas (nullity 'PGtimetz)
17101713timeWithTimeZone = UnsafeTypeExpression "time with time zone"
17111714-- | time span
1712−interval :: TypeExpression schema (nullity 'PGinterval)
1715+interval :: TypeExpression schemas (nullity 'PGinterval)
17131716interval = UnsafeTypeExpression "interval"
17141717-- | universally unique identifier
1715−uuid :: TypeExpression schema (nullity 'PGuuid)
1718+uuid :: TypeExpression schemas (nullity 'PGuuid)
17161719uuid = UnsafeTypeExpression "uuid"
17171720-- | IPv4 or IPv6 host address
1718−inet :: TypeExpression schema (nullity 'PGinet)
1721+inet :: TypeExpression schemas (nullity 'PGinet)
17191722inet = UnsafeTypeExpression "inet"
17201723-- | textual JSON data
1721−json :: TypeExpression schema (nullity 'PGjson)
1724+json :: TypeExpression schemas (nullity 'PGjson)
17221725json = UnsafeTypeExpression "json"
17231726-- | binary JSON data, decomposed
1724−jsonb :: TypeExpression schema (nullity 'PGjsonb)
1727+jsonb :: TypeExpression schemas (nullity 'PGjsonb)
17251728jsonb = UnsafeTypeExpression "jsonb"
17261729-- | variable length array
17271730vararray
1728− :: TypeExpression schema pg
1729− -> TypeExpression schema (nullity ('PGvararray pg))
1731+ :: TypeExpression schemas pg
1732+ -> TypeExpression schemas (nullity ('PGvararray pg))
17301733vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
17311734-- | fixed length array
17321735--
17331736-- >>> renderTypeExpression (fixarray @2 json)
17341737-- "json[2]"
17351738fixarray
1736− :: forall n schema nullity pg. KnownNat n
1737− => TypeExpression schema pg
1738− -> TypeExpression schema (nullity ('PGfixarray n pg))
1739+ :: forall n schemas nullity pg. KnownNat n
1740+ => TypeExpression schemas pg
1741+ -> TypeExpression schemas (nullity ('PGfixarray n pg))
17391742fixarray ty = UnsafeTypeExpression $
17401743 renderTypeExpression ty <> "[" <> renderNat @n <> "]"
17411744
17421745-- | `pgtype` is a demoted version of a `PGType`
1743−class PGTyped schema (ty :: NullityType) where
1744− pgtype :: TypeExpression schema ty
1745−instance PGTyped schema (nullity 'PGbool) where pgtype = bool
1746−instance PGTyped schema (nullity 'PGint2) where pgtype = int2
1747−instance PGTyped schema (nullity 'PGint4) where pgtype = int4
1748−instance PGTyped schema (nullity 'PGint8) where pgtype = int8
1749−instance PGTyped schema (nullity 'PGnumeric) where pgtype = numeric
1750−instance PGTyped schema (nullity 'PGfloat4) where pgtype = float4
1751−instance PGTyped schema (nullity 'PGfloat8) where pgtype = float8
1752−instance PGTyped schema (nullity 'PGtext) where pgtype = text
1746+class PGTyped schemas (ty :: NullityType) where
1747+ pgtype :: TypeExpression schemas ty
1748+instance PGTyped schemas (nullity 'PGbool) where pgtype = bool
1749+instance PGTyped schemas (nullity 'PGint2) where pgtype = int2
1750+instance PGTyped schemas (nullity 'PGint4) where pgtype = int4
1751+instance PGTyped schemas (nullity 'PGint8) where pgtype = int8
1752+instance PGTyped schemas (nullity 'PGnumeric) where pgtype = numeric
1753+instance PGTyped schemas (nullity 'PGfloat4) where pgtype = float4
1754+instance PGTyped schemas (nullity 'PGfloat8) where pgtype = float8
1755+instance PGTyped schemas (nullity 'PGtext) where pgtype = text
17531756instance (KnownNat n, 1 <= n)
1754− => PGTyped schema (nullity ('PGchar n)) where pgtype = char @n
1757+ => PGTyped schemas (nullity ('PGchar n)) where pgtype = char @n
17551758instance (KnownNat n, 1 <= n)
1756− => PGTyped schema (nullity ('PGvarchar n)) where pgtype = varchar @n
1757−instance PGTyped schema (nullity 'PGbytea) where pgtype = bytea
1758−instance PGTyped schema (nullity 'PGtimestamp) where pgtype = timestamp
1759−instance PGTyped schema (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1760−instance PGTyped schema (nullity 'PGdate) where pgtype = date
1761−instance PGTyped schema (nullity 'PGtime) where pgtype = time
1762−instance PGTyped schema (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1763−instance PGTyped schema (nullity 'PGinterval) where pgtype = interval
1764−instance PGTyped schema (nullity 'PGuuid) where pgtype = uuid
1765−instance PGTyped schema (nullity 'PGjson) where pgtype = json
1766−instance PGTyped schema (nullity 'PGjsonb) where pgtype = jsonb
1767−instance PGTyped schema ty
1768− => PGTyped schema (nullity ('PGvararray ty)) where
1769− pgtype = vararray (pgtype @schema @ty)
1770−instance (KnownNat n, PGTyped schema ty)
1771− => PGTyped schema (nullity ('PGfixarray n ty)) where
1772− pgtype = fixarray @n (pgtype @schema @ty)
1759+ => PGTyped schemas (nullity ('PGvarchar n)) where pgtype = varchar @n
1760+instance PGTyped schemas (nullity 'PGbytea) where pgtype = bytea
1761+instance PGTyped schemas (nullity 'PGtimestamp) where pgtype = timestamp
1762+instance PGTyped schemas (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1763+instance PGTyped schemas (nullity 'PGdate) where pgtype = date
1764+instance PGTyped schemas (nullity 'PGtime) where pgtype = time
1765+instance PGTyped schemas (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1766+instance PGTyped schemas (nullity 'PGinterval) where pgtype = interval
1767+instance PGTyped schemas (nullity 'PGuuid) where pgtype = uuid
1768+instance PGTyped schemas (nullity 'PGjson) where pgtype = json
1769+instance PGTyped schemas (nullity 'PGjsonb) where pgtype = jsonb
1770+instance PGTyped schemas ty
1771+ => PGTyped schemas (nullity ('PGvararray ty)) where
1772+ pgtype = vararray (pgtype @schemas @ty)
1773+instance (KnownNat n, PGTyped schemas ty)
1774+ => PGTyped schemas (nullity ('PGfixarray n ty)) where
1775+ pgtype = fixarray @n (pgtype @schemas @ty)