@@ -31,7 +31,7 @@ Squeal expressions are the atoms used to build statements.
3131
3232module Squeal.PostgreSQL.Expression
3333 ( -- * Expression
34− Expression (UnsafeExpression, renderExpression)
34+ Expression (..)
3535 , HasParameter (parameter)
3636 , param
3737 -- ** Null
@@ -142,8 +142,8 @@ module Squeal.PostgreSQL.Expression
142142 , every, everyDistinct
143143 , max_, maxDistinct, min_, minDistinct
144144 -- * Types
145− , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
146− , PGTyped (pgtype)
145+ , TypeExpression (..)
146+ , PGTyped (..)
147147 , typedef
148148 , typetable
149149 , typeview
@@ -219,14 +219,14 @@ and other operations.
219219-}
220220newtype Expression
221221 (db :: DBType)
222− (from :: FromType)
223− (grouping :: Grouping)
224222 (params :: [NullityType])
223+ (grp :: Grouping)
224+ (from :: FromType)
225225 (ty :: NullityType)
226226 = UnsafeExpression { renderExpression :: ByteString }
227227 deriving (GHC.Generic,Show,Eq,Ord,NFData)
228228
229−instance RenderSQL (Expression db from grouping params ty) where
229+instance RenderSQL (Expression db params grp from ty) where
230230 renderSQL = renderExpression
231231
232232{- | A `HasParameter` constraint is used to indicate a value that is
@@ -244,15 +244,15 @@ class KnownNat n => HasParameter
244244 | n params -> ty where
245245 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
246246 --
247− -- >>> let expr = parameter @1 int4 :: Expression (DBof schemas) from grp '[ 'Null 'PGint4] ('Null 'PGint4)
247+ -- >>> let expr = parameter @1 int4 :: Expression (DBof schemas) '[ 'Null 'PGint4] grp from ('Null 'PGint4)
248248 -- >>> printSQL expr
249249 -- ($1 :: int4)
250250 parameter
251251 :: TypeExpression schemas ty
252− -> Expression (commons :=> schemas) from grouping params ty
252+ -> Expression (commons :=> schemas) params grp from ty
253253 parameter ty = UnsafeExpression $ parenthesized $
254254 "$" <> renderNat @n <+> "::"
255− <+> renderTypeExpression ty
255+ <+> renderSQL ty
256256instance {-# OVERLAPPING #-} HasParameter 1 (ty1:tys) ty1
257257instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
258258 => HasParameter n (ty' : params) ty
@@ -260,88 +260,88 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
260260-- | `param` takes a `Nat` using type application and for basic types,
261261-- infers a `TypeExpression`.
262262--
263−-- >>> let expr = param @1 :: Expression (commons :=> schemas) from grp '[ 'Null 'PGint4] ('Null 'PGint4)
263+-- >>> let expr = param @1 :: Expression (commons :=> schemas) '[ 'Null 'PGint4] grp from ('Null 'PGint4)
264264-- >>> printSQL expr
265265-- ($1 :: int4)
266266param
267− :: forall n db commons schemas params from grouping ty
267+ :: forall n db commons schemas params from grp ty
268268 . (db ~ (commons :=> schemas), PGTyped schemas ty, HasParameter n params ty)
269− => Expression db from grouping params ty -- ^ param
269+ => Expression db params grp from ty -- ^ param
270270param = parameter @n (pgtype @schemas)
271271
272272instance (HasUnique tab from row, Has col row ty)
273− => IsLabel col (Expression db from 'Ungrouped params ty) where
274− fromLabel = UnsafeExpression $ renderAlias (Alias @col)
273+ => IsLabel col (Expression db params 'Ungrouped from ty) where
274+ fromLabel = UnsafeExpression $ renderSQL (Alias @col)
275275instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
276276 => IsLabel col
277− (Aliased (Expression db from 'Ungrouped params) column) where
277+ (Aliased (Expression db params 'Ungrouped from) column) where
278278 fromLabel = fromLabel @col `As` Alias
279279instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: ty])
280280 => IsLabel col
281− (NP (Aliased (Expression db from 'Ungrouped params)) columns) where
281+ (NP (Aliased (Expression db params 'Ungrouped from)) columns) where
282282 fromLabel = fromLabel @col :* Nil
283283
284284instance (Has tab from row, Has col row ty)
285− => IsQualified tab col (Expression db from 'Ungrouped params ty) where
285+ => IsQualified tab col (Expression db params 'Ungrouped from ty) where
286286 tab ! col = UnsafeExpression $
287− renderAlias tab <> "." <> renderAlias col
287+ renderSQL tab <> "." <> renderSQL col
288288instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
289289 => IsQualified tab col
290− (Aliased (Expression db from 'Ungrouped params) column) where
290+ (Aliased (Expression db params 'Ungrouped from) column) where
291291 tab ! col = tab ! col `As` col
292292instance (Has tab from row, Has col row ty, columns ~ '[col ::: ty])
293293 => IsQualified tab col
294− (NP (Aliased (Expression db from 'Ungrouped params)) columns) where
294+ (NP (Aliased (Expression db params 'Ungrouped from)) columns) where
295295 tab ! col = tab ! col :* Nil
296296
297297instance
298− ( HasUnique table from columns
299− , Has column columns ty
300− , GroupedBy table column bys
301− ) => IsLabel column
302− (Expression db from ('Grouped bys) params ty) where
303− fromLabel = UnsafeExpression $ renderAlias (Alias @column)
298+ ( HasUnique tab from row
299+ , Has col row ty
300+ , GroupedBy tab col bys
301+ ) => IsLabel col
302+ (Expression db params ('Grouped bys) from ty) where
303+ fromLabel = UnsafeExpression $ renderSQL (Alias @col)
304304instance
305− ( HasUnique table from columns
306− , Has column columns ty
307− , GroupedBy table column bys
308− ) => IsLabel column
309− ( Aliased (Expression db from ('Grouped bys) params)
310− (column ::: ty) ) where
311− fromLabel = fromLabel @column `As` Alias @column
305+ ( HasUnique tab from row
306+ , Has col row ty
307+ , GroupedBy tab col bys
308+ , column ~ (col ::: ty)
309+ ) => IsLabel col
310+ (Aliased (Expression db params ('Grouped bys) from) column) where
311+ fromLabel = fromLabel @col `As` Alias
312312instance
313− ( HasUnique table from columns
314− , Has column columns ty
315− , GroupedBy table column bys
316− ) => IsLabel column
317− ( NP (Aliased (Expression db from ('Grouped bys) params))
318− '[column ::: ty] ) where
319− fromLabel = fromLabel @column :* Nil
313+ ( HasUnique tab from row
314+ , Has col row ty
315+ , GroupedBy tab col bys
316+ , columns ~ '[col ::: ty]
317+ ) => IsLabel col
318+ (NP (Aliased (Expression db params ('Grouped bys) from)) columns) where
319+ fromLabel = fromLabel @col :* Nil
320320
321321instance
322− ( Has table from columns
323− , Has column columns ty
324− , GroupedBy table column bys
325− ) => IsQualified table column
326− (Expression db from ('Grouped bys) params ty) where
327− table ! column = UnsafeExpression $
328− renderAlias table <> "." <> renderAlias column
322+ ( Has tab from row
323+ , Has col row ty
324+ , GroupedBy tab col bys
325+ ) => IsQualified tab col
326+ (Expression db params ('Grouped bys) from ty) where
327+ tab ! col = UnsafeExpression $
328+ renderSQL tab <> "." <> renderSQL col
329329instance
330− ( Has table from columns
331− , Has column columns ty
332− , GroupedBy table column bys
333− ) => IsQualified table column
334− (Aliased (Expression db from ('Grouped bys) params)
335− (column ::: ty)) where
336− table ! column = table ! column `As` column
330+ ( Has tab from row
331+ , Has col row ty
332+ , GroupedBy tab col bys
333+ , column ~ (col ::: ty)
334+ ) => IsQualified tab col
335+ (Aliased (Expression db params ('Grouped bys) from) column) where
336+ tab ! col = tab ! col `As` col
337337instance
338− ( Has table from columns
339− , Has column columns ty
340− , GroupedBy table column bys
341− ) => IsQualified table column
342− ( NP (Aliased (Expression db from ('Grouped bys) params))
343− '[column ::: ty]) where
344− table ! column = table ! column :* Nil
338+ ( Has tab from row
339+ , Has col row ty
340+ , GroupedBy tab col bys
341+ , columns ~ '[col ::: ty]
342+ ) => IsQualified tab col
343+ (NP (Aliased (Expression db params ('Grouped bys) from)) columns) where
344+ tab ! col = tab ! col :* Nil
345345
346346-- | analagous to `Nothing`
347347--
@@ -357,102 +357,102 @@ null_ = UnsafeExpression "NULL"
357357notNull
358358 :: Expression db rels grouping params ('NotNull ty)
359359 -> Expression db rels grouping params ('Null ty)
360−notNull = UnsafeExpression . renderExpression
360+notNull = UnsafeExpression . renderSQL
361361
362362-- | return the leftmost value which is not NULL
363363--
364364-- >>> printSQL $ coalesce [null_, true] false
365365-- COALESCE(NULL, TRUE, FALSE)
366366coalesce
367− :: [Expression db from grouping params ('Null ty)]
367+ :: [Expression db params grp from ('Null ty)]
368368 -- ^ @NULL@s may be present
369− -> Expression db from grouping params ('NotNull ty)
369+ -> Expression db params grp from ('NotNull ty)
370370 -- ^ @NULL@ is absent
371− -> Expression db from grouping params ('NotNull ty)
371+ -> Expression db params grp from ('NotNull ty)
372372coalesce nullxs notNullx = UnsafeExpression $
373373 "COALESCE" <> parenthesized (commaSeparated
374− ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
374+ ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
375375
376376-- | analagous to `Data.Maybe.fromMaybe` using @COALESCE@
377377--
378378-- >>> printSQL $ fromNull true null_
379379-- COALESCE(NULL, TRUE)
380380fromNull
381− :: Expression db from grouping params ('NotNull ty)
381+ :: Expression db params grp from ('NotNull ty)
382382 -- ^ what to convert @NULL@ to
383− -> Expression db from grouping params ('Null ty)
384− -> Expression db from grouping params ('NotNull ty)
383+ -> Expression db params grp from ('Null ty)
384+ -> Expression db params grp from ('NotNull ty)
385385fromNull notNullx nullx = coalesce [nullx] notNullx
386386
387387-- | >>> printSQL $ null_ & isNull
388388-- NULL IS NULL
389389isNull
390− :: Expression db from grouping params ('Null ty)
390+ :: Expression db params grp from ('Null ty)
391391 -- ^ possibly @NULL@
392− -> Condition db from grouping params
393−isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
392+ -> Condition db params grp from
393+isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
394394
395395-- | >>> printSQL $ null_ & isNotNull
396396-- NULL IS NOT NULL
397397isNotNull
398− :: Expression db from grouping params ('Null ty)
398+ :: Expression db params grp from ('Null ty)
399399 -- ^ possibly @NULL@
400− -> Condition db from grouping params
401−isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
400+ -> Condition db params grp from
401+isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
402402
403403-- | analagous to `maybe` using @IS NULL@
404404--
405405-- >>> printSQL $ matchNull true not_ null_
406406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407407matchNull
408− :: Expression db from grouping params (nullty)
408+ :: Expression db params grp from (nullty)
409409 -- ^ what to convert @NULL@ to
410− -> ( Expression db from grouping params ('NotNull ty)
411− -> Expression db from grouping params (nullty) )
410+ -> ( Expression db params grp from ('NotNull ty)
411+ -> Expression db params grp from (nullty) )
412412 -- ^ function to perform when @NULL@ is absent
413− -> Expression db from grouping params ('Null ty)
414− -> Expression db from grouping params (nullty)
413+ -> Expression db params grp from ('Null ty)
414+ -> Expression db params grp from (nullty)
415415matchNull y f x = ifThenElse (isNull x) y
416− (f (UnsafeExpression (renderExpression x)))
416+ (f (UnsafeExpression (renderSQL x)))
417417
418418{-| right inverse to `fromNull`, if its arguments are equal then
419419`nullIf` gives @NULL@.
420420
421421>>> :set -XTypeApplications -XDataKinds
422−>>> let expr = nullIf false (param @1) :: Expression (commons :=> schema) from grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
422+>>> let expr = nullIf false (param @1) :: Expression (commons :=> schema) '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
423423>>> printSQL expr
424424NULL IF (FALSE, ($1 :: bool))
425425-}
426426nullIf
427− :: Expression db from grouping params ('NotNull ty)
427+ :: Expression db params grp from ('NotNull ty)
428428 -- ^ @NULL@ is absent
429− -> Expression db from grouping params ('NotNull ty)
429+ -> Expression db params grp from ('NotNull ty)
430430 -- ^ @NULL@ is absent
431− -> Expression db from grouping params ('Null ty)
431+ -> Expression db params grp from ('Null ty)
432432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
433− (renderExpression x <> ", " <> renderExpression y)
433+ (renderSQL x <> ", " <> renderSQL y)
434434
435435-- | >>> printSQL $ array [null_, false, true]
436436-- ARRAY[NULL, FALSE, TRUE]
437437array
438− :: [Expression db from grouping params ty]
438+ :: [Expression db params grp from ty]
439439 -- ^ array elements
440− -> Expression db from grouping params (nullity ('PGvararray ty))
440+ -> Expression db params grp from (nullity ('PGvararray ty))
441441array xs = UnsafeExpression $
442− "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
442+ "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
443443
444444-- | >>> printSQL $ array [null_, false, true] & index 2
445445-- (ARRAY[NULL, FALSE, TRUE])[2]
446446index
447447 :: Word64 -- ^ index
448− -> Expression db from grouping params (nullity ('PGvararray ty)) -- ^ array
449− -> Expression db from grouping params (NullifyType ty)
448+ -> Expression db params grp from (nullity ('PGvararray ty)) -- ^ array
449+ -> Expression db params grp from (NullifyType ty)
450450index n expr = UnsafeExpression $
451− parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
451+ parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
452452
453453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
454− (Expression db from grouping params (nullity ('PGenum labels))) where
455− label = UnsafeExpression $ renderLabel (PGlabel @label)
454+ (Expression db params grp from (nullity ('PGenum labels))) where
455+ label = UnsafeExpression $ renderSQL (PGlabel @label)
456456
457457-- | A row constructor is an expression that builds a row value
458458-- (also called a composite value) using values for its member fields.
@@ -468,11 +468,11 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
468468-- ROW(0, 1)
469469row
470470 :: SListI row
471− => NP (Aliased (Expression db from grouping params)) row
471+ => NP (Aliased (Expression db params grp from)) row
472472 -- ^ zero or more expressions for the row field values
473− -> Expression db from grouping params (nullity ('PGcomposite row))
473+ -> Expression db params grp from (nullity ('PGcomposite row))
474474row exprs = UnsafeExpression $ "ROW" <> parenthesized
475− (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
475+ (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
476476
477477-- | >>> :{
478478-- type Complex = 'PGcomposite
@@ -491,87 +491,87 @@ field
491491 , Has field row ty)
492492 => QualifiedAlias sch tydef -- ^ row type
493493 -> Alias field -- ^ field name
494− -> Expression (commons :=> schemas) from grouping params ('NotNull ('PGcomposite row))
495− -> Expression (commons :=> schemas) from grouping params ty
494+ -> Expression (commons :=> schemas) params grp from ('NotNull ('PGcomposite row))
495+ -> Expression (commons :=> schemas) params grp from ty
496496field td fld expr = UnsafeExpression $
497− parenthesized (renderExpression expr <> "::" <> renderQualifiedAlias td)
498− <> "." <> renderAlias fld
497+ parenthesized (renderSQL expr <> "::" <> renderSQL td)
498+ <> "." <> renderSQL fld
499499
500500instance Semigroup
501− (Expression db from grouping params (nullity ('PGvararray ty))) where
501+ (Expression db params grp from (nullity ('PGvararray ty))) where
502502 (<>) = unsafeBinaryOp "||"
503503
504504instance Monoid
505− (Expression db from grouping params (nullity ('PGvararray ty))) where
505+ (Expression db params grp from (nullity ('PGvararray ty))) where
506506 mempty = array []
507507 mappend = (<>)
508508
509−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression (commons :=> schemas) rels grp '[ 'NotNull 'PGtimestamptz] ('NotNull 'PGtimestamptz)
509+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression (commons :=> schemas) '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
510510-- >>> printSQL expr
511511-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
512512greatest
513− :: Expression db from grouping params (nullty)
513+ :: Expression db params grp from (nullty)
514514 -- ^ needs at least 1 argument
515− -> [Expression db from grouping params (nullty)]
515+ -> [Expression db params grp from (nullty)]
516516 -- ^ or more
517− -> Expression db from grouping params (nullty)
517+ -> Expression db params grp from (nullty)
518518greatest x xs = UnsafeExpression $ "GREATEST("
519− <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
519+ <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
520520
521521-- | >>> printSQL $ least currentTimestamp [null_]
522522-- LEAST(CURRENT_TIMESTAMP, NULL)
523523least
524− :: Expression db from grouping params (nullty)
524+ :: Expression db params grp from (nullty)
525525 -- ^ needs at least 1 argument
526− -> [Expression db from grouping params (nullty)]
526+ -> [Expression db params grp from (nullty)]
527527 -- ^ or more
528− -> Expression db from grouping params (nullty)
528+ -> Expression db params grp from (nullty)
529529least x xs = UnsafeExpression $ "LEAST("
530− <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
530+ <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
531531
532532-- | >>> printSQL $ unsafeBinaryOp "OR" true false
533533-- (TRUE OR FALSE)
534534unsafeBinaryOp
535535 :: ByteString
536536 -- ^ operator
537− -> Expression db from grouping params (ty0)
538− -> Expression db from grouping params (ty1)
539− -> Expression db from grouping params (ty2)
537+ -> Expression db params grp from (ty0)
538+ -> Expression db params grp from (ty1)
539+ -> Expression db params grp from (ty2)
540540unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
541− renderExpression x <+> op <+> renderExpression y
541+ renderSQL x <+> op <+> renderSQL y
542542
543543-- | >>> printSQL $ unsafeUnaryOp "NOT" true
544544-- (NOT TRUE)
545545unsafeUnaryOp
546546 :: ByteString
547547 -- ^ operator
548− -> Expression db from grouping params (ty0)
549− -> Expression db from grouping params (ty1)
548+ -> Expression db params grp from (ty0)
549+ -> Expression db params grp from (ty1)
550550unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
551− op <+> renderExpression x
551+ op <+> renderSQL x
552552
553553-- | >>> printSQL $ unsafeFunction "f" true
554554-- f(TRUE)
555555unsafeFunction
556556 :: ByteString
557557 -- ^ function
558− -> Expression db from grouping params (xty)
559− -> Expression db from grouping params (yty)
558+ -> Expression db params grp from (xty)
559+ -> Expression db params grp from (yty)
560560unsafeFunction fun x = UnsafeExpression $
561− fun <> parenthesized (renderExpression x)
561+ fun <> parenthesized (renderSQL x)
562562
563563-- | Helper for defining variadic functions.
564564unsafeVariadicFunction
565565 :: SListI elems
566566 => ByteString
567567 -- ^ function
568− -> NP (Expression db from grouping params) elems
569− -> Expression db from grouping params ret
568+ -> NP (Expression db params grp from) elems
569+ -> Expression db params grp from ret
570570unsafeVariadicFunction fun x = UnsafeExpression $
571− fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
571+ fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
572572
573573instance ty `In` PGNum
574− => Num (Expression db from grouping params (nullity ty)) where
574+ => Num (Expression db params grp from (nullity ty)) where
575575 (+) = unsafeBinaryOp "+"
576576 (-) = unsafeBinaryOp "-"
577577 (*) = unsafeBinaryOp "*"
@@ -583,18 +583,18 @@ instance ty `In` PGNum
583583 . show
584584
585585instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
586− (Expression db from grouping params (nullity ty)) where
586+ (Expression db params grp from (nullity ty)) where
587587 (/) = unsafeBinaryOp "/"
588588 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
589589
590590instance (ty `In` PGNum, ty `In` PGFloating) => Floating
591− (Expression db from grouping params (nullity ty)) where
591+ (Expression db params grp from (nullity ty)) where
592592 pi = UnsafeExpression "pi()"
593593 exp = unsafeFunction "exp"
594594 log = unsafeFunction "ln"
595595 sqrt = unsafeFunction "sqrt"
596596 b ** x = UnsafeExpression $
597− "power(" <> renderExpression b <> ", " <> renderExpression x <> ")"
597+ "power(" <> renderSQL b <> ", " <> renderSQL x <> ")"
598598 logBase b y = log y / log b
599599 sin = unsafeFunction "sin"
600600 cos = unsafeFunction "cos"
@@ -611,20 +611,20 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
611611
612612-- | >>> :{
613613-- let
614−-- expression :: Expression db from grouping params (nullity 'PGfloat4)
614+-- expression :: Expression db params grp from (nullity 'PGfloat4)
615615-- expression = atan2_ pi 2
616616-- in printSQL expression
617617-- :}
618618-- atan2(pi(), 2)
619619atan2_
620620 :: float `In` PGFloating
621− => Expression db from grouping params (nullity float)
621+ => Expression db params grp from (nullity float)
622622 -- ^ numerator
623− -> Expression db from grouping params (nullity float)
623+ -> Expression db params grp from (nullity float)
624624 -- ^ denominator
625− -> Expression db from grouping params (nullity float)
625+ -> Expression db params grp from (nullity float)
626626atan2_ y x = UnsafeExpression $
627− "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
627+ "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
628628
629629-- When a `cast` is applied to an `Expression` of a known type, it
630630-- represents a run-time type conversion. The cast will succeed only if a
@@ -635,171 +635,171 @@ atan2_ y x = UnsafeExpression $
635635cast
636636 :: TypeExpression schemas ty1
637637 -- ^ type to cast as
638− -> Expression (commons :=> schemas) from grouping params ty0
638+ -> Expression (commons :=> schemas) params grp from ty0
639639 -- ^ value to convert
640− -> Expression (commons :=> schemas) from grouping params ty1
640+ -> Expression (commons :=> schemas) params grp from ty1
641641cast ty x = UnsafeExpression $ parenthesized $
642− renderExpression x <+> "::" <+> renderTypeExpression ty
642+ renderSQL x <+> "::" <+> renderSQL ty
643643
644644-- | integer division, truncates the result
645645--
646646-- >>> :{
647647-- let
648−-- expression :: Expression db from grouping params (nullity 'PGint2)
648+-- expression :: Expression db params grp from (nullity 'PGint2)
649649-- expression = 5 `quot_` 2
650650-- in printSQL expression
651651-- :}
652652-- (5 / 2)
653653quot_
654654 :: int `In` PGIntegral
655− => Expression db from grouping params (nullity int)
655+ => Expression db params grp from (nullity int)
656656 -- ^ numerator
657− -> Expression db from grouping params (nullity int)
657+ -> Expression db params grp from (nullity int)
658658 -- ^ denominator
659− -> Expression db from grouping params (nullity int)
659+ -> Expression db params grp from (nullity int)
660660quot_ = unsafeBinaryOp "/"
661661
662662-- | remainder upon integer division
663663--
664664-- >>> :{
665665-- let
666−-- expression :: Expression db from grouping params (nullity 'PGint2)
666+-- expression :: Expression db params grp from (nullity 'PGint2)
667667-- expression = 5 `rem_` 2
668668-- in printSQL expression
669669-- :}
670670-- (5 % 2)
671671rem_
672672 :: int `In` PGIntegral
673− => Expression db from grouping params (nullity int)
673+ => Expression db params grp from (nullity int)
674674 -- ^ numerator
675− -> Expression db from grouping params (nullity int)
675+ -> Expression db params grp from (nullity int)
676676 -- ^ denominator
677− -> Expression db from grouping params (nullity int)
677+ -> Expression db params grp from (nullity int)
678678rem_ = unsafeBinaryOp "%"
679679
680680-- | >>> :{
681681-- let
682−-- expression :: Expression db from grouping params (nullity 'PGfloat4)
682+-- expression :: Expression db params grp from (nullity 'PGfloat4)
683683-- expression = trunc pi
684684-- in printSQL expression
685685-- :}
686686-- trunc(pi())
687687trunc
688688 :: frac `In` PGFloating
689− => Expression db from grouping params (nullity frac)
689+ => Expression db params grp from (nullity frac)
690690 -- ^ fractional number
691− -> Expression db from grouping params (nullity frac)
691+ -> Expression db params grp from (nullity frac)
692692trunc = unsafeFunction "trunc"
693693
694694-- | >>> :{
695695-- let
696−-- expression :: Expression db from grouping params (nullity 'PGfloat4)
696+-- expression :: Expression db params grp from (nullity 'PGfloat4)
697697-- expression = round_ pi
698698-- in printSQL expression
699699-- :}
700700-- round(pi())
701701round_
702702 :: frac `In` PGFloating
703− => Expression db from grouping params (nullity frac)
703+ => Expression db params grp from (nullity frac)
704704 -- ^ fractional number
705− -> Expression db from grouping params (nullity frac)
705+ -> Expression db params grp from (nullity frac)
706706round_ = unsafeFunction "round"
707707
708708-- | >>> :{
709709-- let
710−-- expression :: Expression db from grouping params (nullity 'PGfloat4)
710+-- expression :: Expression db params grp from (nullity 'PGfloat4)
711711-- expression = ceiling_ pi
712712-- in printSQL expression
713713-- :}
714714-- ceiling(pi())
715715ceiling_
716716 :: frac `In` PGFloating
717− => Expression db from grouping params (nullity frac)
717+ => Expression db params grp from (nullity frac)
718718 -- ^ fractional number
719− -> Expression db from grouping params (nullity frac)
719+ -> Expression db params grp from (nullity frac)
720720ceiling_ = unsafeFunction "ceiling"
721721
722722-- | A `Condition` is an `Expression`, which can evaluate
723723-- to `true`, `false` or `null_`. This is because SQL uses
724724-- a three valued logic.
725−type Condition db from grouping params =
726− Expression db from grouping params ('Null 'PGbool)
725+type Condition db params grp from =
726+ Expression db params grp from ('Null 'PGbool)
727727
728728-- | >>> printSQL true
729729-- TRUE
730−true :: Expression db from grouping params (nullity 'PGbool)
730+true :: Expression db params grp from (nullity 'PGbool)
731731true = UnsafeExpression "TRUE"
732732
733733-- | >>> printSQL false
734734-- FALSE
735−false :: Expression db from grouping params (nullity 'PGbool)
735+false :: Expression db params grp from (nullity 'PGbool)
736736false = UnsafeExpression "FALSE"
737737
738738-- | >>> printSQL $ not_ true
739739-- (NOT TRUE)
740740not_
741− :: Expression db from grouping params (nullity 'PGbool)
742− -> Expression db from grouping params (nullity 'PGbool)
741+ :: Expression db params grp from (nullity 'PGbool)
742+ -> Expression db params grp from (nullity 'PGbool)
743743not_ = unsafeUnaryOp "NOT"
744744
745745-- | >>> printSQL $ true .&& false
746746-- (TRUE AND FALSE)
747747(.&&)
748− :: Expression db from grouping params (nullity 'PGbool)
749− -> Expression db from grouping params (nullity 'PGbool)
750− -> Expression db from grouping params (nullity 'PGbool)
748+ :: Expression db params grp from (nullity 'PGbool)
749+ -> Expression db params grp from (nullity 'PGbool)
750+ -> Expression db params grp from (nullity 'PGbool)
751751infixr 3 .&&
752752(.&&) = unsafeBinaryOp "AND"
753753
754754-- | >>> printSQL $ true .|| false
755755-- (TRUE OR FALSE)
756756(.||)
757− :: Expression db from grouping params (nullity 'PGbool)
758− -> Expression db from grouping params (nullity 'PGbool)
759− -> Expression db from grouping params (nullity 'PGbool)
757+ :: Expression db params grp from (nullity 'PGbool)
758+ -> Expression db params grp from (nullity 'PGbool)
759+ -> Expression db params grp from (nullity 'PGbool)
760760infixr 2 .||
761761(.||) = unsafeBinaryOp "OR"
762762
763763-- | >>> :{
764764-- let
765−-- expression :: Expression db from grouping params (nullity 'PGint2)
765+-- expression :: Expression db params grp from (nullity 'PGint2)
766766-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
767767-- in printSQL expression
768768-- :}
769769-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
770770caseWhenThenElse
771− :: [ ( Condition db from grouping params
772− , Expression db from grouping params ty
771+ :: [ ( Condition db params grp from
772+ , Expression db params grp from ty
773773 ) ]
774774 -- ^ whens and thens
775− -> Expression db from grouping params ty
775+ -> Expression db params grp from ty
776776 -- ^ else
777− -> Expression db from grouping params ty
777+ -> Expression db params grp from ty
778778caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
779779 [ "CASE"
780780 , mconcat
781781 [ mconcat
782− [ " WHEN ", renderExpression when_
783− , " THEN ", renderExpression then_
782+ [ " WHEN ", renderSQL when_
783+ , " THEN ", renderSQL then_
784784 ]
785785 | (when_,then_) <- whenThens
786786 ]
787− , " ELSE ", renderExpression else_
787+ , " ELSE ", renderSQL else_
788788 , " END"
789789 ]
790790
791791-- | >>> :{
792792-- let
793−-- expression :: Expression db from grouping params (nullity 'PGint2)
793+-- expression :: Expression db params grp from (nullity 'PGint2)
794794-- expression = ifThenElse true 1 0
795795-- in printSQL expression
796796-- :}
797797-- CASE WHEN TRUE THEN 1 ELSE 0 END
798798ifThenElse
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
799+ :: Condition db params grp from
800+ -> Expression db params grp from ty -- ^ then
801+ -> Expression db params grp from ty -- ^ else
802+ -> Expression db params grp from ty
803803ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
804804
805805-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -808,85 +808,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
808808-- >>> printSQL $ true .== null_
809809-- (TRUE = NULL)
810810(.==)
811− :: Expression db from grouping params (nullity0 ty) -- ^ lhs
812− -> Expression db from grouping params (nullity1 ty) -- ^ rhs
813− -> Condition db from grouping params
811+ :: Expression db params grp from (nullity0 ty) -- ^ lhs
812+ -> Expression db params grp from (nullity1 ty) -- ^ rhs
813+ -> Condition db params grp from
814814(.==) = unsafeBinaryOp "="
815815infix 4 .==
816816
817817-- | >>> printSQL $ true ./= null_
818818-- (TRUE <> NULL)
819819(./=)
820− :: Expression db from grouping params (nullity0 ty) -- ^ lhs
821− -> Expression db from grouping params (nullity1 ty) -- ^ rhs
822− -> Condition db from grouping params
820+ :: Expression db params grp from (nullity0 ty) -- ^ lhs
821+ -> Expression db params grp from (nullity1 ty) -- ^ rhs
822+ -> Condition db params grp from
823823(./=) = unsafeBinaryOp "<>"
824824infix 4 ./=
825825
826826-- | >>> printSQL $ true .>= null_
827827-- (TRUE >= NULL)
828828(.>=)
829− :: Expression db from grouping params (nullity0 ty) -- ^ lhs
830− -> Expression db from grouping params (nullity1 ty) -- ^ rhs
831− -> Condition db from grouping params
829+ :: Expression db params grp from (nullity0 ty) -- ^ lhs
830+ -> Expression db params grp from (nullity1 ty) -- ^ rhs
831+ -> Condition db params grp from
832832(.>=) = unsafeBinaryOp ">="
833833infix 4 .>=
834834
835835-- | >>> printSQL $ true .< null_
836836-- (TRUE < NULL)
837837(.<)
838− :: Expression db from grouping params (nullity0 ty) -- ^ lhs
839− -> Expression db from grouping params (nullity1 ty) -- ^ rhs
840− -> Condition db from grouping params
838+ :: Expression db params grp from (nullity0 ty) -- ^ lhs
839+ -> Expression db params grp from (nullity1 ty) -- ^ rhs
840+ -> Condition db params grp from
841841(.<) = unsafeBinaryOp "<"
842842infix 4 .<
843843
844844-- | >>> printSQL $ true .<= null_
845845-- (TRUE <= NULL)
846846(.<=)
847− :: Expression db from grouping params (nullity0 ty) -- ^ lhs
848− -> Expression db from grouping params (nullity1 ty) -- ^ rhs
849− -> Condition db from grouping params
847+ :: Expression db params grp from (nullity0 ty) -- ^ lhs
848+ -> Expression db params grp from (nullity1 ty) -- ^ rhs
849+ -> Condition db params grp from
850850(.<=) = unsafeBinaryOp "<="
851851infix 4 .<=
852852
853853-- | >>> printSQL $ true .> null_
854854-- (TRUE > NULL)
855855(.>)
856− :: Expression db from grouping params (nullity0 ty) -- ^ lhs
857− -> Expression db from grouping params (nullity1 ty) -- ^ rhs
858− -> Condition db from grouping params
856+ :: Expression db params grp from (nullity0 ty) -- ^ lhs
857+ -> Expression db params grp from (nullity1 ty) -- ^ rhs
858+ -> Condition db params grp from
859859(.>) = unsafeBinaryOp ">"
860860infix 4 .>
861861
862862-- | >>> printSQL currentDate
863863-- CURRENT_DATE
864864currentDate
865− :: Expression db from grouping params (nullity 'PGdate)
865+ :: Expression db params grp from (nullity 'PGdate)
866866currentDate = UnsafeExpression "CURRENT_DATE"
867867
868868-- | >>> printSQL currentTime
869869-- CURRENT_TIME
870870currentTime
871− :: Expression db from grouping params (nullity 'PGtimetz)
871+ :: Expression db params grp from (nullity 'PGtimetz)
872872currentTime = UnsafeExpression "CURRENT_TIME"
873873
874874-- | >>> printSQL currentTimestamp
875875-- CURRENT_TIMESTAMP
876876currentTimestamp
877− :: Expression db from grouping params (nullity 'PGtimestamptz)
877+ :: Expression db params grp from (nullity 'PGtimestamptz)
878878currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
879879
880880-- | >>> printSQL localTime
881881-- LOCALTIME
882882localTime
883− :: Expression db from grouping params (nullity 'PGtime)
883+ :: Expression db params grp from (nullity 'PGtime)
884884localTime = UnsafeExpression "LOCALTIME"
885885
886886-- | >>> printSQL localTimestamp
887887-- LOCALTIMESTAMP
888888localTimestamp
889− :: Expression db from grouping params (nullity 'PGtimestamp)
889+ :: Expression db params grp from (nullity 'PGtimestamp)
890890localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
891891
892892{-----------------------------------------
@@ -894,7 +894,7 @@ text
894894-----------------------------------------}
895895
896896instance IsString
897− (Expression db from grouping params (nullity 'PGtext)) where
897+ (Expression db params grp from (nullity 'PGtext)) where
898898 fromString str = UnsafeExpression $
899899 "E\'" <> fromString (escape =<< str) <> "\'"
900900 where
@@ -910,36 +910,36 @@ instance IsString
910910 c -> [c]
911911
912912instance Semigroup
913− (Expression db from grouping params (nullity 'PGtext)) where
913+ (Expression db params grp from (nullity 'PGtext)) where
914914 (<>) = unsafeBinaryOp "||"
915915
916916instance Monoid
917− (Expression db from grouping params (nullity 'PGtext)) where
917+ (Expression db params grp from (nullity 'PGtext)) where
918918 mempty = fromString ""
919919 mappend = (<>)
920920
921921-- | >>> printSQL $ lower "ARRRGGG"
922922-- lower(E'ARRRGGG')
923923lower
924− :: Expression db from grouping params (nullity 'PGtext)
924+ :: Expression db params grp from (nullity 'PGtext)
925925 -- ^ string to lower case
926− -> Expression db from grouping params (nullity 'PGtext)
926+ -> Expression db params grp from (nullity 'PGtext)
927927lower = unsafeFunction "lower"
928928
929929-- | >>> printSQL $ upper "eeee"
930930-- upper(E'eeee')
931931upper
932− :: Expression db from grouping params (nullity 'PGtext)
932+ :: Expression db params grp from (nullity 'PGtext)
933933 -- ^ string to upper case
934− -> Expression db from grouping params (nullity 'PGtext)
934+ -> Expression db params grp from (nullity 'PGtext)
935935upper = unsafeFunction "upper"
936936
937937-- | >>> printSQL $ charLength "four"
938938-- char_length(E'four')
939939charLength
940− :: Expression db from grouping params (nullity 'PGtext)
940+ :: Expression db params grp from (nullity 'PGtext)
941941 -- ^ string to measure
942− -> Expression db from grouping params (nullity 'PGint4)
942+ -> Expression db params grp from (nullity 'PGint4)
943943charLength = unsafeFunction "char_length"
944944
945945-- | The `like` expression returns true if the @string@ matches
@@ -952,11 +952,11 @@ charLength = unsafeFunction "char_length"
952952-- >>> printSQL $ "abc" `like` "a%"
953953-- (E'abc' LIKE E'a%')
954954like
955− :: Expression db from grouping params (nullity 'PGtext)
955+ :: Expression db params grp from (nullity 'PGtext)
956956 -- ^ string
957− -> Expression db from grouping params (nullity 'PGtext)
957+ -> Expression db params grp from (nullity 'PGtext)
958958 -- ^ pattern
959− -> Expression db from grouping params (nullity 'PGbool)
959+ -> Expression db params grp from (nullity 'PGbool)
960960like = unsafeBinaryOp "LIKE"
961961
962962-- | The key word ILIKE can be used instead of LIKE to make the
@@ -965,11 +965,11 @@ like = unsafeBinaryOp "LIKE"
965965-- >>> printSQL $ "abc" `ilike` "a%"
966966-- (E'abc' ILIKE E'a%')
967967ilike
968− :: Expression db from grouping params (nullity 'PGtext)
968+ :: Expression db params grp from (nullity 'PGtext)
969969 -- ^ string
970− -> Expression db from grouping params (nullity 'PGtext)
970+ -> Expression db params grp from (nullity 'PGtext)
971971 -- ^ pattern
972− -> Expression db from grouping params (nullity 'PGbool)
972+ -> Expression db params grp from (nullity 'PGbool)
973973ilike = unsafeBinaryOp "ILIKE"
974974
975975{-----------------------------------------
@@ -984,36 +984,36 @@ Table 9.44: json and jsonb operators
984984-- | Get JSON value (object field or array element) at a key.
985985(.->)
986986 :: (json `In` PGJsonType, key `In` PGJsonKey)
987− => Expression db from grouping params (nullity json)
988− -> Expression db from grouping params (nullity key)
989− -> Expression db from grouping params ('Null json)
987+ => Expression db params grp from (nullity json)
988+ -> Expression db params grp from (nullity key)
989+ -> Expression db params grp from ('Null json)
990990infixl 8 .->
991991(.->) = unsafeBinaryOp "->"
992992
993993-- | Get JSON value (object field or array element) at a key, as text.
994994(.->>)
995995 :: (json `In` PGJsonType, key `In` PGJsonKey)
996− => Expression db from grouping params (nullity json)
997− -> Expression db from grouping params (nullity key)
998− -> Expression db from grouping params ('Null 'PGtext)
996+ => Expression db params grp from (nullity json)
997+ -> Expression db params grp from (nullity key)
998+ -> Expression db params grp from ('Null 'PGtext)
999999infixl 8 .->>
10001000(.->>) = unsafeBinaryOp "->>"
10011001
10021002-- | Get JSON value at a specified path.
10031003(.#>)
10041004 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1005− => Expression db from grouping params (nullity json)
1006− -> Expression db from grouping params (nullity path)
1007− -> Expression db from grouping params ('Null json)
1005+ => Expression db params grp from (nullity json)
1006+ -> Expression db params grp from (nullity path)
1007+ -> Expression db params grp from ('Null json)
10081008infixl 8 .#>
10091009(.#>) = unsafeBinaryOp "#>"
10101010
10111011-- | Get JSON value at a specified path as text.
10121012(.#>>)
10131013 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1014− => Expression db from grouping params (nullity json)
1015− -> Expression db from grouping params (nullity path)
1016− -> Expression db from grouping params ('Null 'PGtext)
1014+ => Expression db params grp from (nullity json)
1015+ -> Expression db params grp from (nullity path)
1016+ -> Expression db params grp from ('Null 'PGtext)
10171017infixl 8 .#>>
10181018(.#>>) = unsafeBinaryOp "#>>"
10191019
@@ -1022,42 +1022,42 @@ infixl 8 .#>>
10221022-- | Does the left JSON value contain the right JSON path/value entries at the
10231023-- top level?
10241024(.@>)
1025− :: Expression db from grouping params (nullity 'PGjsonb)
1026− -> Expression db from grouping params (nullity 'PGjsonb)
1027− -> Condition db from grouping params
1025+ :: Expression db params grp from (nullity 'PGjsonb)
1026+ -> Expression db params grp from (nullity 'PGjsonb)
1027+ -> Condition db params grp from
10281028infixl 9 .@>
10291029(.@>) = unsafeBinaryOp "@>"
10301030
10311031-- | Are the left JSON path/value entries contained at the top level within the
10321032-- right JSON value?
10331033(.<@)
1034− :: Expression db from grouping params (nullity 'PGjsonb)
1035− -> Expression db from grouping params (nullity 'PGjsonb)
1036− -> Condition db from grouping params
1034+ :: Expression db params grp from (nullity 'PGjsonb)
1035+ -> Expression db params grp from (nullity 'PGjsonb)
1036+ -> Condition db params grp from
10371037infixl 9 .<@
10381038(.<@) = unsafeBinaryOp "<@"
10391039
10401040-- | Does the string exist as a top-level key within the JSON value?
10411041(.?)
1042− :: Expression db from grouping params (nullity 'PGjsonb)
1043− -> Expression db from grouping params (nullity 'PGtext)
1044− -> Condition db from grouping params
1042+ :: Expression db params grp from (nullity 'PGjsonb)
1043+ -> Expression db params grp from (nullity 'PGtext)
1044+ -> Condition db params grp from
10451045infixl 9 .?
10461046(.?) = unsafeBinaryOp "?"
10471047
10481048-- | Do any of these array strings exist as top-level keys?
10491049(.?|)
1050− :: Expression db from grouping params (nullity 'PGjsonb)
1051− -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1052− -> Condition db from grouping params
1050+ :: Expression db params grp from (nullity 'PGjsonb)
1051+ -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1052+ -> Condition db params grp from
10531053infixl 9 .?|
10541054(.?|) = unsafeBinaryOp "?|"
10551055
10561056-- | Do all of these array strings exist as top-level keys?
10571057(.?&)
1058− :: Expression db from grouping params (nullity 'PGjsonb)
1059− -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1060− -> Condition db from grouping params
1058+ :: Expression db params grp from (nullity 'PGjsonb)
1059+ -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1060+ -> Condition db params grp from
10611061infixl 9 .?&
10621062(.?&) = unsafeBinaryOp "?&"
10631063
@@ -1080,9 +1080,9 @@ instance
10801080-- count from the end). Throws an error if top level container is not an array.
10811081(.-.)
10821082 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1083− => Expression db from grouping params (nullity 'PGjsonb)
1084− -> Expression db from grouping params (nullity key)
1085− -> Expression db from grouping params (nullity 'PGjsonb)
1083+ => Expression db params grp from (nullity 'PGjsonb)
1084+ -> Expression db params grp from (nullity key)
1085+ -> Expression db params grp from (nullity 'PGjsonb)
10861086infixl 6 .-.
10871087(.-.) = unsafeBinaryOp "-"
10881088
@@ -1090,9 +1090,9 @@ infixl 6 .-.
10901090-- integers count from the end)
10911091(#-.)
10921092 :: PGTextArray "(#-.)" arrayty
1093− => Expression db from grouping params (nullity 'PGjsonb)
1094− -> Expression db from grouping params (nullity arrayty)
1095− -> Expression db from grouping params (nullity 'PGjsonb)
1093+ => Expression db params grp from (nullity 'PGjsonb)
1094+ -> Expression db params grp from (nullity arrayty)
1095+ -> Expression db params grp from (nullity 'PGjsonb)
10961096infixl 6 #-.
10971097(#-.) = unsafeBinaryOp "#-"
10981098
@@ -1103,14 +1103,14 @@ Table 9.45: JSON creation functions
11031103-- | Literal binary JSON
11041104jsonbLit
11051105 :: JSON.ToJSON x
1106− => x -> Expression (commons :=> schemas) from grouping params (nullity 'PGjsonb)
1106+ => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjsonb)
11071107jsonbLit = cast jsonb . UnsafeExpression
11081108 . singleQuotedUtf8 . toStrict . JSON.encode
11091109
11101110-- | Literal JSON
11111111jsonLit
11121112 :: JSON.ToJSON x
1113− => x -> Expression (commons :=> schemas) from grouping params (nullity 'PGjson)
1113+ => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjson)
11141114jsonLit = cast json . UnsafeExpression
11151115 . singleQuotedUtf8 . toStrict . JSON.encode
11161116
@@ -1121,8 +1121,8 @@ jsonLit = cast json . UnsafeExpression
11211121-- number, a Boolean, or a null value, the text representation will be used, in
11221122-- such a fashion that it is a valid json value.
11231123toJson
1124− :: Expression db from grouping params (nullity ty)
1125− -> Expression db from grouping params (nullity 'PGjson)
1124+ :: Expression db params grp from (nullity ty)
1125+ -> Expression db params grp from (nullity 'PGjson)
11261126toJson = unsafeFunction "to_json"
11271127
11281128-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1132,56 +1132,59 @@ toJson = unsafeFunction "to_json"
11321132-- number, a Boolean, or a null value, the text representation will be used, in
11331133-- such a fashion that it is a valid jsonb value.
11341134toJsonb
1135− :: Expression db from grouping params (nullity ty)
1136− -> Expression db from grouping params (nullity 'PGjsonb)
1135+ :: Expression db params grp from (nullity ty)
1136+ -> Expression db params grp from (nullity 'PGjsonb)
11371137toJsonb = unsafeFunction "to_jsonb"
11381138
11391139-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
11401140-- becomes a JSON array of arrays.
11411141arrayToJson
11421142 :: PGArray "arrayToJson" arr
1143− => Expression db from grouping params (nullity arr)
1144− -> Expression db from grouping params (nullity 'PGjson)
1143+ => Expression db params grp from (nullity arr)
1144+ -> Expression db params grp from (nullity 'PGjson)
11451145arrayToJson = unsafeFunction "array_to_json"
11461146
11471147-- | Returns the row as a JSON object.
11481148rowToJson
1149− :: Expression db from grouping params (nullity ('PGcomposite ty))
1150− -> Expression db from grouping params (nullity 'PGjson)
1149+ :: Expression db params grp from (nullity ('PGcomposite ty))
1150+ -> Expression db params grp from (nullity 'PGjson)
11511151rowToJson = unsafeFunction "row_to_json"
11521152
11531153-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
11541154-- argument list.
11551155jsonBuildArray
11561156 :: SListI elems
1157− => NP (Expression db from grouping params) elems
1158− -> Expression db from grouping params (nullity 'PGjson)
1157+ => NP (Expression db params grp from) elems
1158+ -> Expression db params grp from (nullity 'PGjson)
11591159jsonBuildArray = unsafeVariadicFunction "json_build_array"
11601160
11611161-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
11621162-- variadic argument list.
11631163jsonbBuildArray
11641164 :: SListI elems
1165− => NP (Expression db from grouping params) elems
1166− -> Expression db from grouping params (nullity 'PGjsonb)
1165+ => NP (Expression db params grp from) elems
1166+ -> Expression db params grp from (nullity 'PGjsonb)
11671167jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
11681168
11691169unsafeRowFunction
11701170 :: All Top elems
1171− => NP (Aliased (Expression db from grouping params)) elems
1171+ => NP (Aliased (Expression db params grp from)) elems
11721172 -> [ByteString]
11731173unsafeRowFunction =
11741174 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
11751175 (\(col `As` name) -> Endo $ \xs ->
1176− renderAliasString name : renderExpression col : xs)
1176+ renderAliasString name : renderSQL col : xs)
1177+ where
1178+ renderAliasString :: KnownSymbol alias => Alias alias -> ByteString
1179+ renderAliasString = singleQuotedText . fromString . symbolVal
11771180
11781181-- | Builds a possibly-heterogeneously-typed JSON object out of a variadic
11791182-- argument list. The elements of the argument list must alternate between text
11801183-- and values.
11811184jsonBuildObject
11821185 :: All Top elems
1183− => NP (Aliased (Expression db from grouping params)) elems
1184− -> Expression db from grouping params (nullity 'PGjson)
1186+ => NP (Aliased (Expression db params grp from)) elems
1187+ -> Expression db params grp from (nullity 'PGjson)
11851188jsonBuildObject
11861189 = unsafeFunction "json_build_object"
11871190 . UnsafeExpression
@@ -1193,8 +1196,8 @@ jsonBuildObject
11931196-- between text and values.
11941197jsonbBuildObject
11951198 :: All Top elems
1196− => NP (Aliased (Expression db from grouping params)) elems
1197− -> Expression db from grouping params (nullity 'PGjsonb)
1199+ => NP (Aliased (Expression db params grp from)) elems
1200+ -> Expression db params grp from (nullity 'PGjsonb)
11981201jsonbBuildObject
11991202 = unsafeFunction "jsonb_build_object"
12001203 . UnsafeExpression
@@ -1207,8 +1210,8 @@ jsonbBuildObject
12071210-- array has exactly two elements, which are taken as a key/value pair.
12081211jsonObject
12091212 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1210− => Expression db from grouping params (nullity arr)
1211− -> Expression db from grouping params (nullity 'PGjson)
1213+ => Expression db params grp from (nullity arr)
1214+ -> Expression db params grp from (nullity 'PGjson)
12121215jsonObject = unsafeFunction "json_object"
12131216
12141217-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1217,8 +1220,8 @@ jsonObject = unsafeFunction "json_object"
12171220-- array has exactly two elements, which are taken as a key/value pair.
12181221jsonbObject
12191222 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1220− => Expression db from grouping params (nullity arr)
1221− -> Expression db from grouping params (nullity 'PGjsonb)
1223+ => Expression db params grp from (nullity arr)
1224+ -> Expression db params grp from (nullity 'PGjsonb)
12221225jsonbObject = unsafeFunction "jsonb_object"
12231226
12241227-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1226,9 +1229,9 @@ jsonbObject = unsafeFunction "jsonb_object"
12261229jsonZipObject
12271230 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
12281231 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1229− => Expression db from grouping params (nullity keysArray)
1230− -> Expression db from grouping params (nullity valuesArray)
1231− -> Expression db from grouping params (nullity 'PGjson)
1232+ => Expression db params grp from (nullity keysArray)
1233+ -> Expression db params grp from (nullity valuesArray)
1234+ -> Expression db params grp from (nullity 'PGjson)
12321235jsonZipObject ks vs =
12331236 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
12341237
@@ -1238,9 +1241,9 @@ jsonZipObject ks vs =
12381241jsonbZipObject
12391242 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
12401243 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1241− => Expression db from grouping params (nullity keysArray)
1242− -> Expression db from grouping params (nullity valuesArray)
1243− -> Expression db from grouping params (nullity 'PGjsonb)
1244+ => Expression db params grp from (nullity keysArray)
1245+ -> Expression db params grp from (nullity valuesArray)
1246+ -> Expression db params grp from (nullity 'PGjsonb)
12441247jsonbZipObject ks vs =
12451248 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
12461249
@@ -1250,23 +1253,23 @@ Table 9.46: JSON processing functions
12501253
12511254-- | Returns the number of elements in the outermost JSON array.
12521255jsonArrayLength
1253− :: Expression db from grouping params (nullity 'PGjson)
1254− -> Expression db from grouping params (nullity 'PGint4)
1256+ :: Expression db params grp from (nullity 'PGjson)
1257+ -> Expression db params grp from (nullity 'PGint4)
12551258jsonArrayLength = unsafeFunction "json_array_length"
12561259
12571260-- | Returns the number of elements in the outermost binary JSON array.
12581261jsonbArrayLength
1259− :: Expression db from grouping params (nullity 'PGjsonb)
1260− -> Expression db from grouping params (nullity 'PGint4)
1262+ :: Expression db params grp from (nullity 'PGjsonb)
1263+ -> Expression db params grp from (nullity 'PGint4)
12611264jsonbArrayLength = unsafeFunction "jsonb_array_length"
12621265
12631266-- | Returns JSON value pointed to by the given path (equivalent to #>
12641267-- operator).
12651268jsonExtractPath
12661269 :: SListI elems
1267− => Expression db from grouping params (nullity 'PGjson)
1268− -> NP (Expression db from grouping params) elems
1269− -> Expression db from grouping params (nullity 'PGjsonb)
1270+ => Expression db params grp from (nullity 'PGjson)
1271+ -> NP (Expression db params grp from) elems
1272+ -> Expression db params grp from (nullity 'PGjsonb)
12701273jsonExtractPath x xs =
12711274 unsafeVariadicFunction "json_extract_path" (x :* xs)
12721275
@@ -1274,9 +1277,9 @@ jsonExtractPath x xs =
12741277-- operator).
12751278jsonbExtractPath
12761279 :: SListI elems
1277− => Expression db from grouping params (nullity 'PGjsonb)
1278− -> NP (Expression db from grouping params) elems
1279− -> Expression db from grouping params (nullity 'PGjsonb)
1280+ => Expression db params grp from (nullity 'PGjsonb)
1281+ -> NP (Expression db params grp from) elems
1282+ -> Expression db params grp from (nullity 'PGjsonb)
12801283jsonbExtractPath x xs =
12811284 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
12821285
@@ -1284,9 +1287,9 @@ jsonbExtractPath x xs =
12841287-- operator), as text.
12851288jsonExtractPathAsText
12861289 :: SListI elems
1287− => Expression db from grouping params (nullity 'PGjson)
1288− -> NP (Expression db from grouping params) elems
1289− -> Expression db from grouping params (nullity 'PGjson)
1290+ => Expression db params grp from (nullity 'PGjson)
1291+ -> NP (Expression db params grp from) elems
1292+ -> Expression db params grp from (nullity 'PGjson)
12901293jsonExtractPathAsText x xs =
12911294 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
12921295
@@ -1294,38 +1297,38 @@ jsonExtractPathAsText x xs =
12941297-- operator), as text.
12951298jsonbExtractPathAsText
12961299 :: SListI elems
1297− => Expression db from grouping params (nullity 'PGjsonb)
1298− -> NP (Expression db from grouping params) elems
1299− -> Expression db from grouping params (nullity 'PGjsonb)
1300+ => Expression db params grp from (nullity 'PGjsonb)
1301+ -> NP (Expression db params grp from) elems
1302+ -> Expression db params grp from (nullity 'PGjsonb)
13001303jsonbExtractPathAsText x xs =
13011304 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
13021305
13031306-- | Returns the type of the outermost JSON value as a text string. Possible
13041307-- types are object, array, string, number, boolean, and null.
13051308jsonTypeof
1306− :: Expression db from grouping params (nullity 'PGjson)
1307− -> Expression db from grouping params (nullity 'PGtext)
1309+ :: Expression db params grp from (nullity 'PGjson)
1310+ -> Expression db params grp from (nullity 'PGtext)
13081311jsonTypeof = unsafeFunction "json_typeof"
13091312
13101313-- | Returns the type of the outermost binary JSON value as a text string.
13111314-- Possible types are object, array, string, number, boolean, and null.
13121315jsonbTypeof
1313− :: Expression db from grouping params (nullity 'PGjsonb)
1314− -> Expression db from grouping params (nullity 'PGtext)
1316+ :: Expression db params grp from (nullity 'PGjsonb)
1317+ -> Expression db params grp from (nullity 'PGtext)
13151318jsonbTypeof = unsafeFunction "jsonb_typeof"
13161319
13171320-- | Returns its argument with all object fields that have null values omitted.
13181321-- Other null values are untouched.
13191322jsonStripNulls
1320− :: Expression db from grouping params (nullity 'PGjson)
1321− -> Expression db from grouping params (nullity 'PGjson)
1323+ :: Expression db params grp from (nullity 'PGjson)
1324+ -> Expression db params grp from (nullity 'PGjson)
13221325jsonStripNulls = unsafeFunction "json_strip_nulls"
13231326
13241327-- | Returns its argument with all object fields that have null values omitted.
13251328-- Other null values are untouched.
13261329jsonbStripNulls
1327− :: Expression db from grouping params (nullity 'PGjsonb)
1328− -> Expression db from grouping params (nullity 'PGjsonb)
1330+ :: Expression db params grp from (nullity 'PGjsonb)
1331+ -> Expression db params grp from (nullity 'PGjsonb)
13291332jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13301333
13311334-- | @ jsonbSet target path new_value create_missing @
@@ -1337,11 +1340,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13371340-- arrays.
13381341jsonbSet
13391342 :: PGTextArray "jsonbSet" arr
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)
1343+ => Expression db params grp from (nullity 'PGjsonb)
1344+ -> Expression db params grp from (nullity arr)
1345+ -> Expression db params grp from (nullity 'PGjsonb)
1346+ -> Maybe (Expression db params grp from (nullity 'PGbool))
1347+ -> Expression db params grp from (nullity 'PGjsonb)
13451348jsonbSet tgt path val createMissing = case createMissing of
13461349 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
13471350 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1356,19 +1359,19 @@ jsonbSet tgt path val createMissing = case createMissing of
13561359-- in path count from the end of JSON arrays.
13571360jsonbInsert
13581361 :: PGTextArray "jsonbInsert" arr
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)
1362+ => Expression db params grp from (nullity 'PGjsonb)
1363+ -> Expression db params grp from (nullity arr)
1364+ -> Expression db params grp from (nullity 'PGjsonb)
1365+ -> Maybe (Expression db params grp from (nullity 'PGbool))
1366+ -> Expression db params grp from (nullity 'PGjsonb)
13641367jsonbInsert tgt path val insertAfter = case insertAfter of
13651368 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
13661369 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
13671370
13681371-- | Returns its argument as indented JSON text.
13691372jsonbPretty
1370− :: Expression db from grouping params (nullity 'PGjsonb)
1371− -> Expression db from grouping params (nullity 'PGtext)
1373+ :: Expression db params grp from (nullity 'PGjsonb)
1374+ -> Expression db params grp from (nullity 'PGtext)
13721375jsonbPretty = unsafeFunction "jsonb_pretty"
13731376
13741377{-----------------------------------------
@@ -1381,7 +1384,7 @@ unsafeAggregate
13811384 -> Expression db from 'Ungrouped params (xty)
13821385 -> Expression db from ('Grouped bys) params (yty)
13831386unsafeAggregate fun x = UnsafeExpression $ mconcat
1384− [fun, "(", renderExpression x, ")"]
1387+ [fun, "(", renderSQL x, ")"]
13851388
13861389-- | escape hatch to define aggregate functions over distinct values
13871390unsafeAggregateDistinct
@@ -1389,11 +1392,11 @@ unsafeAggregateDistinct
13891392 -> Expression db from 'Ungrouped params (xty)
13901393 -> Expression db from ('Grouped bys) params (yty)
13911394unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1392− [fun, "(DISTINCT ", renderExpression x, ")"]
1395+ [fun, "(DISTINCT ", renderSQL x, ")"]
13931396
13941397-- | >>> :{
13951398-- let
1396−-- expression :: Expression db '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
1399+-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
13971400-- expression = sum_ #col
13981401-- in printSQL expression
13991402-- :}
@@ -1407,7 +1410,7 @@ sum_ = unsafeAggregate "sum"
14071410
14081411-- | >>> :{
14091412-- let
1410−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
1413+-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
14111414-- expression = sumDistinct #col
14121415-- in printSQL expression
14131416-- :}
@@ -1438,7 +1441,7 @@ instance PGAvg 'PGinterval 'PGinterval
14381441
14391442-- | >>> :{
14401443-- let
1441−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1444+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14421445-- expression = bitAnd #col
14431446-- in printSQL expression
14441447-- :}
@@ -1452,7 +1455,7 @@ bitAnd = unsafeAggregate "bit_and"
14521455
14531456-- | >>> :{
14541457-- let
1455−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1458+-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14561459-- expression = bitOr #col
14571460-- in printSQL expression
14581461-- :}
@@ -1466,7 +1469,7 @@ bitOr = unsafeAggregate "bit_or"
14661469
14671470-- | >>> :{
14681471-- let
1469−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1472+-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14701473-- expression = bitAndDistinct #col
14711474-- in printSQL expression
14721475-- :}
@@ -1480,7 +1483,7 @@ bitAndDistinct = unsafeAggregateDistinct "bit_and"
14801483
14811484-- | >>> :{
14821485-- let
1483−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1486+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14841487-- expression = bitOrDistinct #col
14851488-- in printSQL expression
14861489-- :}
@@ -1494,7 +1497,7 @@ bitOrDistinct = unsafeAggregateDistinct "bit_or"
14941497
14951498-- | >>> :{
14961499-- let
1497−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1500+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
14981501-- expression = boolAnd #col
14991502-- in printSQL expression
15001503-- :}
@@ -1507,7 +1510,7 @@ boolAnd = unsafeAggregate "bool_and"
15071510
15081511-- | >>> :{
15091512-- let
1510−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1513+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15111514-- expression = boolOr #col
15121515-- in printSQL expression
15131516-- :}
@@ -1520,7 +1523,7 @@ boolOr = unsafeAggregate "bool_or"
15201523
15211524-- | >>> :{
15221525-- let
1523−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1526+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15241527-- expression = boolAndDistinct #col
15251528-- in printSQL expression
15261529-- :}
@@ -1533,7 +1536,7 @@ boolAndDistinct = unsafeAggregateDistinct "bool_and"
15331536
15341537-- | >>> :{
15351538-- let
1536−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1539+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15371540-- expression = boolOrDistinct #col
15381541-- in printSQL expression
15391542-- :}
@@ -1554,7 +1557,7 @@ countStar = UnsafeExpression $ "count(*)"
15541557
15551558-- | >>> :{
15561559-- let
1557−-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1560+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
15581561-- expression = count #col
15591562-- in printSQL expression
15601563-- :}
@@ -1567,7 +1570,7 @@ count = unsafeAggregate "count"
15671570
15681571-- | >>> :{
15691572-- let
1570−-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1573+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
15711574-- expression = countDistinct #col
15721575-- in printSQL expression
15731576-- :}
@@ -1582,7 +1585,7 @@ countDistinct = unsafeAggregateDistinct "count"
15821585--
15831586-- >>> :{
15841587-- let
1585−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1588+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15861589-- expression = every #col
15871590-- in printSQL expression
15881591-- :}
@@ -1597,7 +1600,7 @@ every = unsafeAggregate "every"
15971600--
15981601-- >>> :{
15991602-- let
1600−-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1603+-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
16011604-- expression = everyDistinct #col
16021605-- in printSQL expression
16031606-- :}
@@ -1626,13 +1629,15 @@ type expressions
16261629newtype TypeExpression (schemas :: SchemasType) (ty :: NullityType)
16271630 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
16281631 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1632+instance RenderSQL (TypeExpression schemas ty) where
1633+ renderSQL = renderTypeExpression
16291634
16301635-- | The enum or composite type in a `Typedef` can be expressed by its alias.
16311636typedef
16321637 :: (Has sch schemas schema, Has td schema ('Typedef ty))
16331638 => QualifiedAlias sch td
16341639 -> TypeExpression schemas (nullity ty)
1635−typedef = UnsafeTypeExpression . renderQualifiedAlias
1640+typedef = UnsafeTypeExpression . renderSQL
16361641
16371642-- | The composite type corresponding to a `Table` definition can be expressed
16381643-- by its alias.
@@ -1640,7 +1645,7 @@ typetable
16401645 :: (Has sch schemas schema, Has tab schema ('Table table))
16411646 => QualifiedAlias sch tab
16421647 -> TypeExpression schemas (nullity ('PGcomposite (TableToRow table)))
1643−typetable = UnsafeTypeExpression . renderQualifiedAlias
1648+typetable = UnsafeTypeExpression . renderSQL
16441649
16451650-- | The composite type corresponding to a `View` definition can be expressed
16461651-- by its alias.
@@ -1648,7 +1653,7 @@ typeview
16481653 :: (Has sch schemas schema, Has vw schema ('View view))
16491654 => QualifiedAlias sch vw
16501655 -> TypeExpression schemas (nullity ('PGcomposite view))
1651−typeview = UnsafeTypeExpression . renderQualifiedAlias
1656+typeview = UnsafeTypeExpression . renderSQL
16521657
16531658-- | logical Boolean (true/false)
16541659bool :: TypeExpression schemas (nullity 'PGbool)
@@ -1730,17 +1735,17 @@ jsonb = UnsafeTypeExpression "jsonb"
17301735vararray
17311736 :: TypeExpression schemas pg
17321737 -> TypeExpression schemas (nullity ('PGvararray pg))
1733−vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1738+vararray ty = UnsafeTypeExpression $ renderSQL ty <> "[]"
17341739-- | fixed length array
17351740--
1736−-- >>> renderTypeExpression (fixarray @2 json)
1741+-- >>> renderSQL (fixarray @2 json)
17371742-- "json[2]"
17381743fixarray
17391744 :: forall n schemas nullity pg. KnownNat n
17401745 => TypeExpression schemas pg
17411746 -> TypeExpression schemas (nullity ('PGfixarray n pg))
17421747fixarray ty = UnsafeTypeExpression $
1743− renderTypeExpression ty <> "[" <> renderNat @n <> "]"
1748+ renderSQL ty <> "[" <> renderNat @n <> "]"
17441749
17451750-- | `pgtype` is a demoted version of a `PGType`
17461751class PGTyped schemas (ty :: NullityType) where