@@ -45,7 +45,9 @@ module Squeal.PostgreSQL.Expression
46 -- ** Collections
46 -- ** Collections
49 -- ** Functions
51 -- ** Functions
50 , unsafeBinaryOp
52 , unsafeBinaryOp
51 , unsafeUnaryOp
53 , unsafeUnaryOp
@@ -61,12 +63,12 @@ module Squeal.PostgreSQL.Expression
61 , greatest
63 , greatest
63 -- ** Conditions
65 -- ** Conditions
70 , caseWhenThenElse
72 , caseWhenThenElse
71 , ifThenElse
73 , ifThenElse
@@ -86,16 +88,13 @@ module Squeal.PostgreSQL.Expression
87 , charLength
89 , charLength
89− -- ** json or jsonb operators
92+ -- *** Json and Jsonb operators
98− -- *** jsonb only operators
97+ -- *** Jsonb operators
@@ -124,8 +123,6 @@ module Squeal.PostgreSQL.Expression
124 , jsonbExtractPath
123 , jsonbExtractPath
125 , jsonExtractPathAsText
124 , jsonExtractPathAsText
126 , jsonbExtractPathAsText
125 , jsonbExtractPathAsText
129 , jsonTypeof
126 , jsonTypeof
130 , jsonbTypeof
127 , jsonbTypeof
131 , jsonStripNulls
128 , jsonStripNulls
@@ -146,6 +143,9 @@ module Squeal.PostgreSQL.Expression
146 -- * Types
143 -- * Types
147 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
144 , TypeExpression (UnsafeTypeExpression, renderTypeExpression)
148 , PGTyped (pgtype)
145 , PGTyped (pgtype)
151 , smallint
151 , smallint
@@ -191,6 +191,7 @@ import Data.Semigroup hiding (All)
191import qualified Data.Aeson as JSON
191import qualified Data.Aeson as JSON
192import Data.Ratio
192import Data.Ratio
193import Data.String
193import Data.String
194import Generics.SOP hiding (from)
195import Generics.SOP hiding (from)
195import GHC.OverloadedLabels
196import GHC.OverloadedLabels
196import GHC.TypeLits
197import GHC.TypeLits
@@ -217,14 +218,14 @@ and other operations.
218newtype Expression
219newtype Expression
219 (schema :: SchemaType)
220 (schema :: SchemaType)
220− (relations :: RelationsType)
221+ (from :: FromType)
221 (grouping :: Grouping)
222 (grouping :: Grouping)
222 (params :: [NullityType])
223 (params :: [NullityType])
223 (ty :: NullityType)
224 (ty :: NullityType)
224 = UnsafeExpression { renderExpression :: ByteString }
225 = UnsafeExpression { renderExpression :: ByteString }
225 deriving (GHC.Generic,Show,Eq,Ord,NFData)
226 deriving (GHC.Generic,Show,Eq,Ord,NFData)
227−instance RenderSQL (Expression schema relations grouping params ty) where
228+instance RenderSQL (Expression schema from grouping params ty) where
228 renderSQL = renderExpression
229 renderSQL = renderExpression
230{- | A `HasParameter` constraint is used to indicate a value that is
231{- | A `HasParameter` constraint is used to indicate a value that is
@@ -247,10 +248,10 @@ class KnownNat n => HasParameter
247 -- >>> printSQL expr
248 -- >>> printSQL expr
248 -- ($1 :: int4)
249 -- ($1 :: int4)
249 parameter
250 parameter
250− :: TypeExpression schema (PGTypeOf ty)
251+ :: TypeExpression schema ty
251− -> Expression schema relations grouping params ty
252+ -> Expression schema from grouping params ty
252 parameter ty = UnsafeExpression $ parenthesized $
253 parameter ty = UnsafeExpression $ parenthesized $
253− "$" <> renderNat (Proxy @n) <+> "::"
254+ "$" <> renderNat @n <+> "::"
254 <+> renderTypeExpression ty
255 <+> renderTypeExpression ty
255instance {-# OVERLAPPING #-} HasParameter 1 schema (ty1:tys) ty1
256instance {-# OVERLAPPING #-} HasParameter 1 schema (ty1:tys) ty1
256instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
257instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
@@ -263,84 +264,84 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
263-- >>> printSQL expr
264-- >>> printSQL expr
264-- ($1 :: int4)
265-- ($1 :: int4)
266− :: forall n schema params relations grouping ty
267+ :: forall n schema params from grouping ty
267− . (PGTyped schema (PGTypeOf ty), HasParameter n schema params ty)
268+ . (PGTyped schema ty, HasParameter n schema params ty)
268− => Expression schema relations grouping params ty -- ^ param
269+ => Expression schema from grouping params ty -- ^ param
269param = parameter @n pgtype
270param = parameter @n pgtype
271−instance (HasUnique relation relations columns, Has column columns ty)
272+instance (HasUnique table from columns, Has column columns ty)
272− => IsLabel column (Expression schema relations 'Ungrouped params ty) where
273+ => IsLabel column (Expression schema from 'Ungrouped params ty) where
273 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
274 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
274−instance (HasUnique relation relations columns, Has column columns ty)
275+instance (HasUnique table from columns, Has column columns ty)
275 => IsLabel column
276 => IsLabel column
276− (Aliased (Expression schema relations 'Ungrouped params) (column ::: ty)) where
277+ (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
277 fromLabel = fromLabel @column `As` Alias @column
278 fromLabel = fromLabel @column `As` Alias @column
278−instance (HasUnique relation relations columns, Has column columns ty)
279+instance (HasUnique table from columns, Has column columns ty)
279 => IsLabel column
280 => IsLabel column
280− (NP (Aliased (Expression schema relations 'Ungrouped params)) '[column ::: ty]) where
281+ (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
281 fromLabel = fromLabel @column :* Nil
282 fromLabel = fromLabel @column :* Nil
283−instance (Has relation relations columns, Has column columns ty)
284+instance (Has table from columns, Has column columns ty)
284− => IsQualified relation column (Expression schema relations 'Ungrouped params ty) where
285+ => IsQualified table column (Expression schema from 'Ungrouped params ty) where
285− relation ! column = UnsafeExpression $
286+ table ! column = UnsafeExpression $
286− renderAlias relation <> "." <> renderAlias column
287+ renderAlias table <> "." <> renderAlias column
287−instance (Has relation relations columns, Has column columns ty)
288+instance (Has table from columns, Has column columns ty)
288− => IsQualified relation column
289+ => IsQualified table column
289− (Aliased (Expression schema relations 'Ungrouped params) (column ::: ty)) where
290+ (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
290− relation ! column = relation ! column `As` column
291+ table ! column = table ! column `As` column
291−instance (Has relation relations columns, Has column columns ty)
292+instance (Has table from columns, Has column columns ty)
292− => IsQualified relation column
293+ => IsQualified table column
293− (NP (Aliased (Expression schema relations 'Ungrouped params)) '[column ::: ty]) where
294+ (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
294− relation ! column = relation ! column :* Nil
295+ table ! column = table ! column :* Nil
297− ( HasUnique relation relations columns
298+ ( HasUnique table from columns
298 , Has column columns ty
299 , Has column columns ty
299− , GroupedBy relation column bys
300+ , GroupedBy table column bys
300 ) => IsLabel column
301 ) => IsLabel column
301− (Expression schema relations ('Grouped bys) params ty) where
302+ (Expression schema from ('Grouped bys) params ty) where
302 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
303 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
304− ( HasUnique relation relations columns
305+ ( HasUnique table from columns
305 , Has column columns ty
306 , Has column columns ty
306− , GroupedBy relation column bys
307+ , GroupedBy table column bys
307 ) => IsLabel column
308 ) => IsLabel column
308− ( Aliased (Expression schema relations ('Grouped bys) params)
309+ ( Aliased (Expression schema from ('Grouped bys) params)
309 (column ::: ty) ) where
310 (column ::: ty) ) where
310 fromLabel = fromLabel @column `As` Alias @column
311 fromLabel = fromLabel @column `As` Alias @column
312− ( HasUnique relation relations columns
313+ ( HasUnique table from columns
313 , Has column columns ty
314 , Has column columns ty
314− , GroupedBy relation column bys
315+ , GroupedBy table column bys
315 ) => IsLabel column
316 ) => IsLabel column
316− ( NP (Aliased (Expression schema relations ('Grouped bys) params))
317+ ( NP (Aliased (Expression schema from ('Grouped bys) params))
317 '[column ::: ty] ) where
318 '[column ::: ty] ) where
318 fromLabel = fromLabel @column :* Nil
319 fromLabel = fromLabel @column :* Nil
321− ( Has relation relations columns
322+ ( Has table from columns
322 , Has column columns ty
323 , Has column columns ty
323− , GroupedBy relation column bys
324+ , GroupedBy table column bys
324− ) => IsQualified relation column
325+ ) => IsQualified table column
325− (Expression schema relations ('Grouped bys) params ty) where
326+ (Expression schema from ('Grouped bys) params ty) where
326− relation ! column = UnsafeExpression $
327+ table ! column = UnsafeExpression $
327− renderAlias relation <> "." <> renderAlias column
328+ renderAlias table <> "." <> renderAlias column
329− ( Has relation relations columns
330+ ( Has table from columns
330 , Has column columns ty
331 , Has column columns ty
331− , GroupedBy relation column bys
332+ , GroupedBy table column bys
332− ) => IsQualified relation column
333+ ) => IsQualified table column
333− (Aliased (Expression schema relations ('Grouped bys) params)
334+ (Aliased (Expression schema from ('Grouped bys) params)
334 (column ::: ty)) where
335 (column ::: ty)) where
335− relation ! column = relation ! column `As` column
336+ table ! column = table ! column `As` column
337− ( Has relation relations columns
338+ ( Has table from columns
338 , Has column columns ty
339 , Has column columns ty
339− , GroupedBy relation column bys
340+ , GroupedBy table column bys
340− ) => IsQualified relation column
341+ ) => IsQualified table column
341− ( NP (Aliased (Expression schema relations ('Grouped bys) params))
342+ ( NP (Aliased (Expression schema from ('Grouped bys) params))
342 '[column ::: ty]) where
343 '[column ::: ty]) where
343− relation ! column = relation ! column :* Nil
344+ table ! column = table ! column :* Nil
345-- | analagous to `Nothing`
346-- | analagous to `Nothing`
@@ -360,14 +361,14 @@ notNull = UnsafeExpression . renderExpression
361-- | return the leftmost value which is not NULL
362-- | return the leftmost value which is not NULL
363−-- >>> printSQL $ coalesce [null_, notNull true] false
364+-- >>> printSQL $ coalesce [null_, true] false
364-- COALESCE(NULL, TRUE, FALSE)
365-- COALESCE(NULL, TRUE, FALSE)
366− :: [Expression schema relations grouping params ('Null ty)]
367+ :: [Expression schema from grouping params ('Null ty)]
367 -- ^ @NULL@s may be present
368 -- ^ @NULL@s may be present
368− -> Expression schema relations grouping params ('NotNull ty)
369+ -> Expression schema from grouping params ('NotNull ty)
369 -- ^ @NULL@ is absent
370 -- ^ @NULL@ is absent
370− -> Expression schema relations grouping params ('NotNull ty)
371+ -> Expression schema from grouping params ('NotNull ty)
371coalesce nullxs notNullx = UnsafeExpression $
372coalesce nullxs notNullx = UnsafeExpression $
372 "COALESCE" <> parenthesized (commaSeparated
373 "COALESCE" <> parenthesized (commaSeparated
373 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
374 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -377,26 +378,26 @@ coalesce nullxs notNullx = UnsafeExpression $
377-- >>> printSQL $ fromNull true null_
378-- >>> printSQL $ fromNull true null_
378-- COALESCE(NULL, TRUE)
379-- COALESCE(NULL, TRUE)
380− :: Expression schema relations grouping params ('NotNull ty)
381+ :: Expression schema from grouping params ('NotNull ty)
381 -- ^ what to convert @NULL@ to
382 -- ^ what to convert @NULL@ to
382− -> Expression schema relations grouping params ('Null ty)
383+ -> Expression schema from grouping params ('Null ty)
383− -> Expression schema relations grouping params ('NotNull ty)
384+ -> Expression schema from grouping params ('NotNull ty)
384fromNull notNullx nullx = coalesce [nullx] notNullx
385fromNull notNullx nullx = coalesce [nullx] notNullx
386-- | >>> printSQL $ null_ & isNull
387-- | >>> printSQL $ null_ & isNull
387-- NULL IS NULL
388-- NULL IS NULL
389− :: Expression schema relations grouping params ('Null ty)
390+ :: Expression schema from grouping params ('Null ty)
390 -- ^ possibly @NULL@
391 -- ^ possibly @NULL@
391− -> Condition schema relations grouping params
392+ -> Condition schema from grouping params
392isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
393isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
394-- | >>> printSQL $ null_ & isNotNull
395-- | >>> printSQL $ null_ & isNotNull
395-- NULL IS NOT NULL
396-- NULL IS NOT NULL
397− :: Expression schema relations grouping params ('Null ty)
398+ :: Expression schema from grouping params ('Null ty)
398 -- ^ possibly @NULL@
399 -- ^ possibly @NULL@
399− -> Condition schema relations grouping params
400+ -> Condition schema from grouping params
400isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
401isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
402-- | analagous to `maybe` using @IS NULL@
403-- | analagous to `maybe` using @IS NULL@
@@ -404,13 +405,13 @@ isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
404-- >>> printSQL $ matchNull true not_ null_
405-- >>> printSQL $ matchNull true not_ null_
405-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407− :: Expression schema relations grouping params (nullty)
408+ :: Expression schema from grouping params (nullty)
408 -- ^ what to convert @NULL@ to
409 -- ^ what to convert @NULL@ to
409− -> ( Expression schema relations grouping params ('NotNull ty)
410+ -> ( Expression schema from grouping params ('NotNull ty)
410− -> Expression schema relations grouping params (nullty) )
411+ -> Expression schema from grouping params (nullty) )
411 -- ^ function to perform when @NULL@ is absent
412 -- ^ function to perform when @NULL@ is absent
412− -> Expression schema relations grouping params ('Null ty)
413+ -> Expression schema from grouping params ('Null ty)
413− -> Expression schema relations grouping params (nullty)
414+ -> Expression schema from grouping params (nullty)
414matchNull y f x = ifThenElse (isNull x) y
415matchNull y f x = ifThenElse (isNull x) y
415 (f (UnsafeExpression (renderExpression x)))
416 (f (UnsafeExpression (renderExpression x)))
@@ -423,55 +424,81 @@ matchNull y f x = ifThenElse (isNull x) y
423NULL IF (FALSE, ($1 :: bool))
424NULL IF (FALSE, ($1 :: bool))
426− :: Expression schema relations grouping params ('NotNull ty)
427+ :: Expression schema from grouping params ('NotNull ty)
427 -- ^ @NULL@ is absent
428 -- ^ @NULL@ is absent
428− -> Expression schema relations grouping params ('NotNull ty)
429+ -> Expression schema from grouping params ('NotNull ty)
429 -- ^ @NULL@ is absent
430 -- ^ @NULL@ is absent
430− -> Expression schema relations grouping params ('Null ty)
431+ -> Expression schema from grouping params ('Null ty)
431nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
432 (renderExpression x <> ", " <> renderExpression y)
433 (renderExpression x <> ", " <> renderExpression y)
434−-- | >>> printSQL $ array [null_, notNull false, notNull true]
435+-- | >>> printSQL $ array [null_, false, true]
435-- ARRAY[NULL, FALSE, TRUE]
436-- ARRAY[NULL, FALSE, TRUE]
437− :: [Expression schema relations grouping params ('Null ty)]
438+ :: [Expression schema from grouping params ty]
438 -- ^ array elements
439 -- ^ array elements
439− -> Expression schema relations grouping params (nullity ('PGvararray ty))
440+ -> Expression schema from grouping params (nullity ('PGvararray ty))
440array xs = UnsafeExpression $
441array xs = UnsafeExpression $
441 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
442 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
444+-- | >>> printSQL $ array [null_, false, true] & index 2
445+-- (ARRAY[NULL, FALSE, TRUE])[2]
447+ :: Word64 -- ^ index
448+ -> Expression schema from grouping params (nullity ('PGvararray ty)) -- ^ array
449+ -> Expression schema from grouping params (NullifyType ty)
450+index n expr = UnsafeExpression $
451+ parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
443instance (KnownSymbol label, label `In` labels) => IsPGlabel label
453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
444− (Expression schema relations grouping params (nullity ('PGenum labels))) where
454+ (Expression schema from grouping params (nullity ('PGenum labels))) where
445 label = UnsafeExpression $ renderLabel (PGlabel @label)
455 label = UnsafeExpression $ renderLabel (PGlabel @label)
447-- | A row constructor is an expression that builds a row value
457-- | A row constructor is an expression that builds a row value
448-- (also called a composite value) using values for its member fields.
458-- (also called a composite value) using values for its member fields.
450−-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
461+-- type Complex = 'PGcomposite
462+-- '[ "real" ::: 'NotNull 'PGfloat8
463+-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
451-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
466-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
452-- >>> printSQL i
467-- >>> printSQL i
453-- ROW(0, 1)
468-- ROW(0, 1)
455− :: SListI (Nulls fields)
470+ :: SListI row
456− => NP (Aliased (Expression schema relations grouping params)) (Nulls fields)
471+ => NP (Aliased (Expression schema from grouping params)) row
457 -- ^ zero or more expressions for the row field values
472 -- ^ zero or more expressions for the row field values
458− -> Expression schema relations grouping params (nullity ('PGcomposite fields))
473+ -> Expression schema from grouping params (nullity ('PGcomposite row))
459row exprs = UnsafeExpression $ "ROW" <> parenthesized
474row exprs = UnsafeExpression $ "ROW" <> parenthesized
460 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
475 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
462−instance Has field fields ty => IsLabel field
477+-- | >>> :{
478+-- type Complex = 'PGcomposite
479+-- '[ "real" ::: 'NotNull 'PGfloat8
480+-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
483+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '["complex" ::: 'Typedef Complex] '[] 'Ungrouped '[] ('NotNull Complex)
484+-- >>> printSQL $ i & field #complex #imaginary
485+-- (ROW(0, 1)::"complex")."imaginary"
487+ :: (Has tydef schema ('Typedef ('PGcomposite row)), Has field row ty)
488+ => Alias tydef -- ^ row type
489+ -> Alias field -- ^ field name
463− ( Expression schema relation grouping params (nullity ('PGcomposite fields))
490+ -> Expression schema from grouping params ('NotNull ('PGcomposite row))
464− -> Expression schema relation grouping params ('Null ty) ) where
491+ -> Expression schema from grouping params ty
465− fromLabel expr = UnsafeExpression $
492+field td fld expr = UnsafeExpression $
466− parenthesized (renderExpression expr) <> "." <>
493+ parenthesized (renderExpression expr <> "::" <> renderAlias td)
467− fromString (symbolVal (Proxy @field))
494+ <> "." <> renderAlias fld
469instance Semigroup
496instance Semigroup
470− (Expression schema relations grouping params (nullity ('PGvararray ty))) where
497+ (Expression schema from grouping params (nullity ('PGvararray ty))) where
471 (<>) = unsafeBinaryOp "||"
498 (<>) = unsafeBinaryOp "||"
473instance Monoid
500instance Monoid
474− (Expression schema relations grouping params (nullity ('PGvararray ty))) where
501+ (Expression schema from grouping params (nullity ('PGvararray ty))) where
475 mempty = array []
502 mempty = array []
476 mappend = (<>)
503 mappend = (<>)
@@ -479,22 +506,22 @@ instance Monoid
479-- >>> printSQL expr
506-- >>> printSQL expr
480-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
507-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
482− :: Expression schema relations grouping params (nullty)
509+ :: Expression schema from grouping params (nullty)
483 -- ^ needs at least 1 argument
510 -- ^ needs at least 1 argument
484− -> [Expression schema relations grouping params (nullty)]
511+ -> [Expression schema from grouping params (nullty)]
485 -- ^ or more
512 -- ^ or more
486− -> Expression schema relations grouping params (nullty)
513+ -> Expression schema from grouping params (nullty)
487greatest x xs = UnsafeExpression $ "GREATEST("
514greatest x xs = UnsafeExpression $ "GREATEST("
488 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
515 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
490-- | >>> printSQL $ least currentTimestamp [null_]
517-- | >>> printSQL $ least currentTimestamp [null_]
491-- LEAST(CURRENT_TIMESTAMP, NULL)
518-- LEAST(CURRENT_TIMESTAMP, NULL)
493− :: Expression schema relations grouping params (nullty)
520+ :: Expression schema from grouping params (nullty)
494 -- ^ needs at least 1 argument
521 -- ^ needs at least 1 argument
495− -> [Expression schema relations grouping params (nullty)]
522+ -> [Expression schema from grouping params (nullty)]
496 -- ^ or more
523 -- ^ or more
497− -> Expression schema relations grouping params (nullty)
524+ -> Expression schema from grouping params (nullty)
498least x xs = UnsafeExpression $ "LEAST("
525least x xs = UnsafeExpression $ "LEAST("
499 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
526 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
@@ -503,9 +530,9 @@ least x xs = UnsafeExpression $ "LEAST("
503unsafeBinaryOp
530unsafeBinaryOp
504 :: ByteString
531 :: ByteString
505 -- ^ operator
532 -- ^ operator
506− -> Expression schema relations grouping params (ty0)
533+ -> Expression schema from grouping params (ty0)
507− -> Expression schema relations grouping params (ty1)
534+ -> Expression schema from grouping params (ty1)
508− -> Expression schema relations grouping params (ty2)
535+ -> Expression schema from grouping params (ty2)
509unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
536unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
510 renderExpression x <+> op <+> renderExpression y
537 renderExpression x <+> op <+> renderExpression y
@@ -514,8 +541,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
514unsafeUnaryOp
541unsafeUnaryOp
515 :: ByteString
542 :: ByteString
516 -- ^ operator
543 -- ^ operator
517− -> Expression schema relations grouping params (ty0)
544+ -> Expression schema from grouping params (ty0)
518− -> Expression schema relations grouping params (ty1)
545+ -> Expression schema from grouping params (ty1)
519unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
546unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
520 op <+> renderExpression x
547 op <+> renderExpression x
@@ -524,8 +551,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
524unsafeFunction
551unsafeFunction
525 :: ByteString
552 :: ByteString
526 -- ^ function
553 -- ^ function
527− -> Expression schema relations grouping params (xty)
554+ -> Expression schema from grouping params (xty)
528− -> Expression schema relations grouping params (yty)
555+ -> Expression schema from grouping params (yty)
529unsafeFunction fun x = UnsafeExpression $
556unsafeFunction fun x = UnsafeExpression $
530 fun <> parenthesized (renderExpression x)
557 fun <> parenthesized (renderExpression x)
@@ -534,13 +561,13 @@ unsafeVariadicFunction
534 :: SListI elems
561 :: SListI elems
535 => ByteString
562 => ByteString
536 -- ^ function
563 -- ^ function
537− -> NP (Expression schema relations grouping params) elems
564+ -> NP (Expression schema from grouping params) elems
538− -> Expression schema relations grouping params ret
565+ -> Expression schema from grouping params ret
539unsafeVariadicFunction fun x = UnsafeExpression $
566unsafeVariadicFunction fun x = UnsafeExpression $
540 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
567 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
542−instance PGNum ty
569+instance ty `In` PGNum
543− => Num (Expression schema relations grouping params (nullity ty)) where
570+ => Num (Expression schema from grouping params (nullity ty)) where
544 (+) = unsafeBinaryOp "+"
571 (+) = unsafeBinaryOp "+"
545 (-) = unsafeBinaryOp "-"
572 (-) = unsafeBinaryOp "-"
546 (*) = unsafeBinaryOp "*"
573 (*) = unsafeBinaryOp "*"
@@ -551,13 +578,13 @@ instance PGNum ty
551 . fromString
578 . fromString
554−instance (PGNum ty, PGFloating ty) => Fractional
581+instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
555− (Expression schema relations grouping params (nullity ty)) where
582+ (Expression schema from grouping params (nullity ty)) where
556 (/) = unsafeBinaryOp "/"
583 (/) = unsafeBinaryOp "/"
557 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
584 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
559−instance (PGNum ty, PGFloating ty) => Floating
586+instance (ty `In` PGNum, ty `In` PGFloating) => Floating
560− (Expression schema relations grouping params (nullity ty)) where
587+ (Expression schema from grouping params (nullity ty)) where
561 pi = UnsafeExpression "pi()"
588 pi = UnsafeExpression "pi()"
562 exp = unsafeFunction "exp"
589 exp = unsafeFunction "exp"
563 log = unsafeFunction "ln"
590 log = unsafeFunction "ln"
@@ -580,18 +607,18 @@ instance (PGNum ty, PGFloating ty) => Floating
581-- | >>> :{
608-- | >>> :{
583−-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
610+-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
584-- expression = atan2_ pi 2
611-- expression = atan2_ pi 2
585-- in printSQL expression
612-- in printSQL expression
587-- atan2(pi(), 2)
614-- atan2(pi(), 2)
589− :: PGFloating float
616+ :: float `In` PGFloating
590− => Expression schema relations grouping params (nullity float)
617+ => Expression schema from grouping params (nullity float)
591 -- ^ numerator
618 -- ^ numerator
592− -> Expression schema relations grouping params (nullity float)
619+ -> Expression schema from grouping params (nullity float)
593 -- ^ denominator
620 -- ^ denominator
594− -> Expression schema relations grouping params (nullity float)
621+ -> Expression schema from grouping params (nullity float)
595atan2_ y x = UnsafeExpression $
622atan2_ y x = UnsafeExpression $
596 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
623 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
@@ -604,9 +631,9 @@ atan2_ y x = UnsafeExpression $
605 :: TypeExpression schema ty1
632 :: TypeExpression schema ty1
606 -- ^ type to cast as
633 -- ^ type to cast as
607− -> Expression schema relations grouping params (nullity ty0)
634+ -> Expression schema from grouping params ty0
608 -- ^ value to convert
635 -- ^ value to convert
609− -> Expression schema relations grouping params (nullity ty1)
636+ -> Expression schema from grouping params ty1
610cast ty x = UnsafeExpression $ parenthesized $
637cast ty x = UnsafeExpression $ parenthesized $
611 renderExpression x <+> "::" <+> renderTypeExpression ty
638 renderExpression x <+> "::" <+> renderTypeExpression ty
@@ -614,135 +641,136 @@ cast ty x = UnsafeExpression $ parenthesized $
617−-- expression :: Expression schema relations grouping params (nullity 'PGint2)
644+-- expression :: Expression schema from grouping params (nullity 'PGint2)
618-- expression = 5 `quot_` 2
645-- expression = 5 `quot_` 2
619-- in printSQL expression
646-- in printSQL expression
621-- (5 / 2)
648-- (5 / 2)
623− :: PGIntegral int
650+ :: int `In` PGIntegral
624− => Expression schema relations grouping params (nullity int)
651+ => Expression schema from grouping params (nullity int)
625 -- ^ numerator
652 -- ^ numerator
626− -> Expression schema relations grouping params (nullity int)
653+ -> Expression schema from grouping params (nullity int)
627 -- ^ denominator
654 -- ^ denominator
628− -> Expression schema relations grouping params (nullity int)
655+ -> Expression schema from grouping params (nullity int)
629quot_ = unsafeBinaryOp "/"
656quot_ = unsafeBinaryOp "/"
631-- | remainder upon integer division
658-- | remainder upon integer division
635−-- expression :: Expression schema relations grouping params (nullity 'PGint2)
662+-- expression :: Expression schema from grouping params (nullity 'PGint2)
636-- expression = 5 `rem_` 2
663-- expression = 5 `rem_` 2
637-- in printSQL expression
664-- in printSQL expression
639-- (5 % 2)
666-- (5 % 2)
641− :: PGIntegral int
668+ :: int `In` PGIntegral
642− => Expression schema relations grouping params (nullity int)
669+ => Expression schema from grouping params (nullity int)
643 -- ^ numerator
670 -- ^ numerator
644− -> Expression schema relations grouping params (nullity int)
671+ -> Expression schema from grouping params (nullity int)
645 -- ^ denominator
672 -- ^ denominator
646− -> Expression schema relations grouping params (nullity int)
673+ -> Expression schema from grouping params (nullity int)
647rem_ = unsafeBinaryOp "%"
674rem_ = unsafeBinaryOp "%"
649-- | >>> :{
676-- | >>> :{
651−-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
678+-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
652-- expression = trunc pi
679-- expression = trunc pi
653-- in printSQL expression
680-- in printSQL expression
655-- trunc(pi())
682-- trunc(pi())
657− :: PGFloating frac
684+ :: frac `In` PGFloating
658− => Expression schema relations grouping params (nullity frac)
685+ => Expression schema from grouping params (nullity frac)
659 -- ^ fractional number
686 -- ^ fractional number
660− -> Expression schema relations grouping params (nullity frac)
687+ -> Expression schema from grouping params (nullity frac)
661trunc = unsafeFunction "trunc"
688trunc = unsafeFunction "trunc"
663-- | >>> :{
690-- | >>> :{
665−-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
692+-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
666-- expression = round_ pi
693-- expression = round_ pi
667-- in printSQL expression
694-- in printSQL expression
669-- round(pi())
696-- round(pi())
671− :: PGFloating frac
698+ :: frac `In` PGFloating
672− => Expression schema relations grouping params (nullity frac)
699+ => Expression schema from grouping params (nullity frac)
673 -- ^ fractional number
700 -- ^ fractional number
674− -> Expression schema relations grouping params (nullity frac)
701+ -> Expression schema from grouping params (nullity frac)
675round_ = unsafeFunction "round"
702round_ = unsafeFunction "round"
677-- | >>> :{
704-- | >>> :{
679−-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
706+-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
680-- expression = ceiling_ pi
707-- expression = ceiling_ pi
681-- in printSQL expression
708-- in printSQL expression
683-- ceiling(pi())
710-- ceiling(pi())
685− :: PGFloating frac
712+ :: frac `In` PGFloating
686− => Expression schema relations grouping params (nullity frac)
713+ => Expression schema from grouping params (nullity frac)
687 -- ^ fractional number
714 -- ^ fractional number
688− -> Expression schema relations grouping params (nullity frac)
715+ -> Expression schema from grouping params (nullity frac)
689ceiling_ = unsafeFunction "ceiling"
716ceiling_ = unsafeFunction "ceiling"
691−-- | A `Condition` is a boolean valued `Expression`. While SQL allows
718+-- | A `Condition` is an `Expression`, which can evaluate
692−-- conditions to have @NULL@, Squeal instead chooses to disallow @NULL@,
719+-- to `true`, `false` or `null_`. This is because SQL uses
693−-- forcing one to handle the case of @NULL@ explicitly to produce
720+-- a three valued logic.
695−type Condition schema relations grouping params =
721+type Condition schema from grouping params =
696− Expression schema relations grouping params ('NotNull 'PGbool)
722+ Expression schema from grouping params ('Null 'PGbool)
698-- | >>> printSQL true
724-- | >>> printSQL true
700−true :: Condition schema relations grouping params
726+true :: Expression schema from grouping params (nullity 'PGbool)
701true = UnsafeExpression "TRUE"
727true = UnsafeExpression "TRUE"
703-- | >>> printSQL false
729-- | >>> printSQL false
705−false :: Condition schema relations grouping params
731+false :: Expression schema from grouping params (nullity 'PGbool)
706false = UnsafeExpression "FALSE"
732false = UnsafeExpression "FALSE"
708-- | >>> printSQL $ not_ true
734-- | >>> printSQL $ not_ true
709-- (NOT TRUE)
735-- (NOT TRUE)
711− :: Condition schema relations grouping params
737+ :: Expression schema from grouping params (nullity 'PGbool)
712− -> Condition schema relations grouping params
738+ -> Expression schema from grouping params (nullity 'PGbool)
713not_ = unsafeUnaryOp "NOT"
739not_ = unsafeUnaryOp "NOT"
715-- | >>> printSQL $ true .&& false
741-- | >>> printSQL $ true .&& false
716-- (TRUE AND FALSE)
742-- (TRUE AND FALSE)
718− :: Condition schema relations grouping params
744+ :: Expression schema from grouping params (nullity 'PGbool)
719− -> Condition schema relations grouping params
745+ -> Expression schema from grouping params (nullity 'PGbool)
720− -> Condition schema relations grouping params
746+ -> Expression schema from grouping params (nullity 'PGbool)
721(.&&) = unsafeBinaryOp "AND"
748(.&&) = unsafeBinaryOp "AND"
723-- | >>> printSQL $ true .|| false
750-- | >>> printSQL $ true .|| false
724-- (TRUE OR FALSE)
751-- (TRUE OR FALSE)
726− :: Condition schema relations grouping params
753+ :: Expression schema from grouping params (nullity 'PGbool)
727− -> Condition schema relations grouping params
754+ -> Expression schema from grouping params (nullity 'PGbool)
728− -> Condition schema relations grouping params
755+ -> Expression schema from grouping params (nullity 'PGbool)
729(.||) = unsafeBinaryOp "OR"
757(.||) = unsafeBinaryOp "OR"
731-- | >>> :{
759-- | >>> :{
733−-- expression :: Expression schema relations grouping params (nullity 'PGint2)
761+-- expression :: Expression schema from grouping params (nullity 'PGint2)
734-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
762-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
735-- in printSQL expression
763-- in printSQL expression
737-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
765-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
738caseWhenThenElse
766caseWhenThenElse
739− :: [ ( Condition schema relations grouping params
767+ :: [ ( Condition schema from grouping params
740− , Expression schema relations grouping params (ty)
768+ , Expression schema from grouping params ty
742 -- ^ whens and thens
770 -- ^ whens and thens
743− -> Expression schema relations grouping params (ty)
771+ -> Expression schema from grouping params ty
744 -- ^ else
772 -- ^ else
745− -> Expression schema relations grouping params (ty)
773+ -> Expression schema from grouping params ty
746caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
774caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
748 , mconcat
776 , mconcat
@@ -758,103 +786,103 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
759-- | >>> :{
787-- | >>> :{
761−-- expression :: Expression schema relations grouping params (nullity 'PGint2)
789+-- expression :: Expression schema from grouping params (nullity 'PGint2)
762-- expression = ifThenElse true 1 0
790-- expression = ifThenElse true 1 0
763-- in printSQL expression
791-- in printSQL expression
765-- CASE WHEN TRUE THEN 1 ELSE 0 END
793-- CASE WHEN TRUE THEN 1 ELSE 0 END
766ifThenElse
794ifThenElse
767− :: Condition schema relations grouping params
795+ :: Condition schema from grouping params
768− -> Expression schema relations grouping params (ty) -- ^ then
796+ -> Expression schema from grouping params ty -- ^ then
769− -> Expression schema relations grouping params (ty) -- ^ else
797+ -> Expression schema from grouping params ty -- ^ else
770− -> Expression schema relations grouping params (ty)
798+ -> Expression schema from grouping params ty
771ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
799ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
773-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
801-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
774-- will produce @NULL@s if one of their arguments is @NULL@.
802-- will produce @NULL@s if one of their arguments is @NULL@.
776−-- >>> printSQL $ notNull true .== null_
804+-- >>> printSQL $ true .== null_
777-- (TRUE = NULL)
805-- (TRUE = NULL)
779− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
807+ :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
780− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
808+ -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
781− -> Expression schema relations grouping params (nullity 'PGbool)
809+ -> Condition schema from grouping params
782(.==) = unsafeBinaryOp "="
810(.==) = unsafeBinaryOp "="
783infix 4 .==
811infix 4 .==
785−-- | >>> printSQL $ notNull true ./= null_
813+-- | >>> printSQL $ true ./= null_
786-- (TRUE <> NULL)
814-- (TRUE <> NULL)
788− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
816+ :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
789− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
817+ -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
790− -> Expression schema relations grouping params (nullity 'PGbool)
818+ -> Condition schema from grouping params
791(./=) = unsafeBinaryOp "<>"
819(./=) = unsafeBinaryOp "<>"
792infix 4 ./=
820infix 4 ./=
794−-- | >>> printSQL $ notNull true .>= null_
822+-- | >>> printSQL $ true .>= null_
795-- (TRUE >= NULL)
823-- (TRUE >= NULL)
797− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
825+ :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
798− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
826+ -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
799− -> Expression schema relations grouping params (nullity 'PGbool)
827+ -> Condition schema from grouping params
800(.>=) = unsafeBinaryOp ">="
828(.>=) = unsafeBinaryOp ">="
801infix 4 .>=
829infix 4 .>=
803−-- | >>> printSQL $ notNull true .< null_
831+-- | >>> printSQL $ true .< null_
804-- (TRUE < NULL)
832-- (TRUE < NULL)
806− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
834+ :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
807− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
835+ -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
808− -> Expression schema relations grouping params (nullity 'PGbool)
836+ -> Condition schema from grouping params
809(.<) = unsafeBinaryOp "<"
837(.<) = unsafeBinaryOp "<"
810infix 4 .<
838infix 4 .<
812−-- | >>> printSQL $ notNull true .<= null_
840+-- | >>> printSQL $ true .<= null_
813-- (TRUE <= NULL)
841-- (TRUE <= NULL)
815− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
843+ :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
816− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
844+ -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
817− -> Expression schema relations grouping params (nullity 'PGbool)
845+ -> Condition schema from grouping params
818(.<=) = unsafeBinaryOp "<="
846(.<=) = unsafeBinaryOp "<="
819infix 4 .<=
847infix 4 .<=
821−-- | >>> printSQL $ notNull true .> null_
849+-- | >>> printSQL $ true .> null_
822-- (TRUE > NULL)
850-- (TRUE > NULL)
824− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
852+ :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
825− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
853+ -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
826− -> Expression schema relations grouping params (nullity 'PGbool)
854+ -> Condition schema from grouping params
827(.>) = unsafeBinaryOp ">"
855(.>) = unsafeBinaryOp ">"
828infix 4 .>
856infix 4 .>
830-- | >>> printSQL currentDate
858-- | >>> printSQL currentDate
831-- CURRENT_DATE
859-- CURRENT_DATE
832currentDate
860currentDate
833− :: Expression schema relations grouping params (nullity 'PGdate)
861+ :: Expression schema from grouping params (nullity 'PGdate)
834currentDate = UnsafeExpression "CURRENT_DATE"
862currentDate = UnsafeExpression "CURRENT_DATE"
836-- | >>> printSQL currentTime
864-- | >>> printSQL currentTime
837-- CURRENT_TIME
865-- CURRENT_TIME
838currentTime
866currentTime
839− :: Expression schema relations grouping params (nullity 'PGtimetz)
867+ :: Expression schema from grouping params (nullity 'PGtimetz)
840currentTime = UnsafeExpression "CURRENT_TIME"
868currentTime = UnsafeExpression "CURRENT_TIME"
842-- | >>> printSQL currentTimestamp
870-- | >>> printSQL currentTimestamp
843-- CURRENT_TIMESTAMP
871-- CURRENT_TIMESTAMP
844currentTimestamp
872currentTimestamp
845− :: Expression schema relations grouping params (nullity 'PGtimestamptz)
873+ :: Expression schema from grouping params (nullity 'PGtimestamptz)
846currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
874currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
848-- | >>> printSQL localTime
876-- | >>> printSQL localTime
849-- LOCALTIME
877-- LOCALTIME
851− :: Expression schema relations grouping params (nullity 'PGtime)
879+ :: Expression schema from grouping params (nullity 'PGtime)
852localTime = UnsafeExpression "LOCALTIME"
880localTime = UnsafeExpression "LOCALTIME"
854-- | >>> printSQL localTimestamp
882-- | >>> printSQL localTimestamp
855-- LOCALTIMESTAMP
883-- LOCALTIMESTAMP
856localTimestamp
884localTimestamp
857− :: Expression schema relations grouping params (nullity 'PGtimestamp)
885+ :: Expression schema from grouping params (nullity 'PGtimestamp)
858localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
886localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
860{-----------------------------------------
888{-----------------------------------------
@@ -862,7 +890,7 @@ text
862-----------------------------------------}
890-----------------------------------------}
864instance IsString
892instance IsString
865− (Expression schema relations grouping params (nullity 'PGtext)) where
893+ (Expression schema from grouping params (nullity 'PGtext)) where
866 fromString str = UnsafeExpression $
894 fromString str = UnsafeExpression $
867 "E\'" <> fromString (escape =<< str) <> "\'"
895 "E\'" <> fromString (escape =<< str) <> "\'"
@@ -878,36 +906,36 @@ instance IsString
880instance Semigroup
908instance Semigroup
881− (Expression schema relations grouping params (nullity 'PGtext)) where
909+ (Expression schema from grouping params (nullity 'PGtext)) where
882 (<>) = unsafeBinaryOp "||"
910 (<>) = unsafeBinaryOp "||"
884instance Monoid
912instance Monoid
885− (Expression schema relations grouping params (nullity 'PGtext)) where
913+ (Expression schema from grouping params (nullity 'PGtext)) where
886 mempty = fromString ""
914 mempty = fromString ""
887 mappend = (<>)
915 mappend = (<>)
889-- | >>> printSQL $ lower "ARRRGGG"
917-- | >>> printSQL $ lower "ARRRGGG"
890-- lower(E'ARRRGGG')
918-- lower(E'ARRRGGG')
892− :: Expression schema relations grouping params (nullity 'PGtext)
920+ :: Expression schema from grouping params (nullity 'PGtext)
893 -- ^ string to lower case
921 -- ^ string to lower case
894− -> Expression schema relations grouping params (nullity 'PGtext)
922+ -> Expression schema from grouping params (nullity 'PGtext)
895lower = unsafeFunction "lower"
923lower = unsafeFunction "lower"
897-- | >>> printSQL $ upper "eeee"
925-- | >>> printSQL $ upper "eeee"
898-- upper(E'eeee')
926-- upper(E'eeee')
900− :: Expression schema relations grouping params (nullity 'PGtext)
928+ :: Expression schema from grouping params (nullity 'PGtext)
901 -- ^ string to upper case
929 -- ^ string to upper case
902− -> Expression schema relations grouping params (nullity 'PGtext)
930+ -> Expression schema from grouping params (nullity 'PGtext)
903upper = unsafeFunction "upper"
931upper = unsafeFunction "upper"
905-- | >>> printSQL $ charLength "four"
933-- | >>> printSQL $ charLength "four"
906-- char_length(E'four')
934-- char_length(E'four')
907charLength
935charLength
908− :: Expression schema relations grouping params (nullity 'PGtext)
936+ :: Expression schema from grouping params (nullity 'PGtext)
909 -- ^ string to measure
937 -- ^ string to measure
910− -> Expression schema relations grouping params (nullity 'PGint4)
938+ -> Expression schema from grouping params (nullity 'PGint4)
911charLength = unsafeFunction "char_length"
939charLength = unsafeFunction "char_length"
913-- | The `like` expression returns true if the @string@ matches
941-- | The `like` expression returns true if the @string@ matches
@@ -920,11 +948,11 @@ charLength = unsafeFunction "char_length"
920-- >>> printSQL $ "abc" `like` "a%"
948-- >>> printSQL $ "abc" `like` "a%"
921-- (E'abc' LIKE E'a%')
949-- (E'abc' LIKE E'a%')
923− :: Expression schema relations grouping params (nullity 'PGtext)
951+ :: Expression schema from grouping params (nullity 'PGtext)
924 -- ^ string
952 -- ^ string
925− -> Expression schema relations grouping params (nullity 'PGtext)
953+ -> Expression schema from grouping params (nullity 'PGtext)
926 -- ^ pattern
954 -- ^ pattern
927− -> Expression schema relations grouping params (nullity 'PGbool)
955+ -> Expression schema from grouping params (nullity 'PGbool)
928like = unsafeBinaryOp "LIKE"
956like = unsafeBinaryOp "LIKE"
930{-----------------------------------------
958{-----------------------------------------
@@ -938,34 +966,38 @@ Table 9.44: json and jsonb operators
939-- | Get JSON value (object field or array element) at a key.
967-- | Get JSON value (object field or array element) at a key.
941− :: (PGjson_ json, PGjsonKey key)
969+ :: (json `In` PGJsonType, key `In` PGJsonKey)
942− => Expression schema relations grouping params (nullity json)
970+ => Expression schema from grouping params (nullity json)
943− -> Expression schema relations grouping params (nullity key)
971+ -> Expression schema from grouping params (nullity key)
944− -> Expression schema relations grouping params ('Null json)
972+ -> Expression schema from grouping params ('Null json)
945(.->) = unsafeBinaryOp "->"
974(.->) = unsafeBinaryOp "->"
947-- | Get JSON value (object field or array element) at a key, as text.
976-- | Get JSON value (object field or array element) at a key, as text.
949− :: (PGjson_ json, PGjsonKey key)
978+ :: (json `In` PGJsonType, key `In` PGJsonKey)
950− => Expression schema relations grouping params (nullity json)
979+ => Expression schema from grouping params (nullity json)
951− -> Expression schema relations grouping params (nullity key)
980+ -> Expression schema from grouping params (nullity key)
952− -> Expression schema relations grouping params ('Null 'PGtext)
981+ -> Expression schema from grouping params ('Null 'PGtext)
953(.->>) = unsafeBinaryOp "->>"
983(.->>) = unsafeBinaryOp "->>"
955-- | Get JSON value at a specified path.
985-- | Get JSON value at a specified path.
957− :: (PGjson_ json, PGtextArray "(.#>)" path)
987+ :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
958− => Expression schema relations grouping params (nullity json)
988+ => Expression schema from grouping params (nullity json)
959− -> Expression schema relations grouping params (nullity path)
989+ -> Expression schema from grouping params (nullity path)
960− -> Expression schema relations grouping params ('Null json)
990+ -> Expression schema from grouping params ('Null json)
961(.#>) = unsafeBinaryOp "#>"
992(.#>) = unsafeBinaryOp "#>"
963-- | Get JSON value at a specified path as text.
994-- | Get JSON value at a specified path as text.
965− :: (PGjson_ json, PGtextArray "(.#>>)" path)
996+ :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
966− => Expression schema relations grouping params (nullity json)
997+ => Expression schema from grouping params (nullity json)
967− -> Expression schema relations grouping params (nullity path)
998+ -> Expression schema from grouping params (nullity path)
968− -> Expression schema relations grouping params ('Null 'PGtext)
999+ -> Expression schema from grouping params ('Null 'PGtext)
969(.#>>) = unsafeBinaryOp "#>>"
1001(.#>>) = unsafeBinaryOp "#>>"
971-- Additional jsonb operators
1003-- Additional jsonb operators
@@ -973,43 +1005,48 @@ Table 9.44: json and jsonb operators
973-- | Does the left JSON value contain the right JSON path/value entries at the
1005-- | Does the left JSON value contain the right JSON path/value entries at the
974-- top level?
1006-- top level?
976− :: Expression schema relations grouping params (nullity 'PGjsonb)
1008+ :: Expression schema from grouping params (nullity 'PGjsonb)
977− -> Expression schema relations grouping params (nullity 'PGjsonb)
1009+ -> Expression schema from grouping params (nullity 'PGjsonb)
978− -> Condition schema relations grouping params
1010+ -> Condition schema from grouping params
979(.@>) = unsafeBinaryOp "@>"
1012(.@>) = unsafeBinaryOp "@>"
981-- | Are the left JSON path/value entries contained at the top level within the
1014-- | Are the left JSON path/value entries contained at the top level within the
982-- right JSON value?
1015-- right JSON value?
984− :: Expression schema relations grouping params (nullity 'PGjsonb)
1017+ :: Expression schema from grouping params (nullity 'PGjsonb)
985− -> Expression schema relations grouping params (nullity 'PGjsonb)
1018+ -> Expression schema from grouping params (nullity 'PGjsonb)
986− -> Condition schema relations grouping params
1019+ -> Condition schema from grouping params
987(.<@) = unsafeBinaryOp "<@"
1021(.<@) = unsafeBinaryOp "<@"
989-- | Does the string exist as a top-level key within the JSON value?
1023-- | Does the string exist as a top-level key within the JSON value?
991− :: Expression schema relations grouping params (nullity 'PGjsonb)
1025+ :: Expression schema from grouping params (nullity 'PGjsonb)
992− -> Expression schema relations grouping params (nullity 'PGtext)
1026+ -> Expression schema from grouping params (nullity 'PGtext)
993− -> Condition schema relations grouping params
1027+ -> Condition schema from grouping params
994(.?) = unsafeBinaryOp "?"
1029(.?) = unsafeBinaryOp "?"
996-- | Do any of these array strings exist as top-level keys?
1031-- | Do any of these array strings exist as top-level keys?
998− :: Expression schema relations grouping params (nullity 'PGjsonb)
1033+ :: Expression schema from grouping params (nullity 'PGjsonb)
999− -> Expression schema relations grouping params (nullity ('PGvararray 'PGtext))
1034+ -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1000− -> Condition schema relations grouping params
1035+ -> Condition schema from grouping params
1001(.?|) = unsafeBinaryOp "?|"
1037(.?|) = unsafeBinaryOp "?|"
1003-- | Do all of these array strings exist as top-level keys?
1039-- | Do all of these array strings exist as top-level keys?
1005− :: Expression schema relations grouping params (nullity 'PGjsonb)
1041+ :: Expression schema from grouping params (nullity 'PGjsonb)
1006− -> Expression schema relations grouping params (nullity ('PGvararray 'PGtext))
1042+ -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1007− -> Condition schema relations grouping params
1043+ -> Condition schema from grouping params
1008(.?&) = unsafeBinaryOp "?&"
1045(.?&) = unsafeBinaryOp "?&"
1010-- | Concatenate two jsonb values into a new jsonb value.
1047-- | Concatenate two jsonb values into a new jsonb value.
1012− Semigroup (Expression schema relations grouping param (nullity 'PGjsonb)) where
1049+ Semigroup (Expression schema from grouping param (nullity 'PGjsonb)) where
1013 (<>) = unsafeBinaryOp "||"
1050 (<>) = unsafeBinaryOp "||"
1015-- | Delete a key or keys from a JSON object, or remove an array element.
1052-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1025,19 +1062,21 @@ instance
1025-- @ integer @: Delete the array element with specified index (Negative integers
1062-- @ integer @: Delete the array element with specified index (Negative integers
1026-- count from the end). Throws an error if top level container is not an array.
1063-- count from the end). Throws an error if top level container is not an array.
1028− :: (key `In` '[ 'PGtext, 'PGvararray 'PGtext, 'PGint4, 'PGint2 ]) -- hlint error without parens here
1065+ :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1029− => Expression schema relations grouping params (nullity 'PGjsonb)
1066+ => Expression schema from grouping params (nullity 'PGjsonb)
1030− -> Expression schema relations grouping params (nullity key)
1067+ -> Expression schema from grouping params (nullity key)
1031− -> Expression schema relations grouping params (nullity 'PGjsonb)
1068+ -> Expression schema from grouping params (nullity 'PGjsonb)
1032(.-.) = unsafeBinaryOp "-"
1070(.-.) = unsafeBinaryOp "-"
1034-- | Delete the field or element with specified path (for JSON arrays, negative
1072-- | Delete the field or element with specified path (for JSON arrays, negative
1035-- integers count from the end)
1073-- integers count from the end)
1037− :: PGtextArray "(#-.)" arrayty
1075+ :: PGTextArray "(#-.)" arrayty
1038− => Expression schema relations grouping params (nullity 'PGjsonb)
1076+ => Expression schema from grouping params (nullity 'PGjsonb)
1039− -> Expression schema relations grouping params (nullity arrayty)
1077+ -> Expression schema from grouping params (nullity arrayty)
1040− -> Expression schema relations grouping params (nullity 'PGjsonb)
1078+ -> Expression schema from grouping params (nullity 'PGjsonb)
1041(#-.) = unsafeBinaryOp "#-"
1080(#-.) = unsafeBinaryOp "#-"
1043{-----------------------------------------
1082{-----------------------------------------
@@ -1045,12 +1084,18 @@ Table 9.45: JSON creation functions
1045-----------------------------------------}
1084-----------------------------------------}
1047-- | Literal binary JSON
1086-- | Literal binary JSON
1048−jsonbLit :: JSON.Value -> Expression schema relations grouping params (nullity 'PGjsonb)
1089+ => x -> Expression schema from grouping params (nullity 'PGjsonb)
1090+jsonbLit = cast jsonb . UnsafeExpression
1049−jsonbLit = cast jsonb . UnsafeExpression . singleQuotedUtf8 . toStrict . JSON.encode
1091+ . singleQuotedUtf8 . toStrict . JSON.encode
1051-- | Literal JSON
1093-- | Literal JSON
1052−jsonLit :: JSON.Value -> Expression schema relations grouping params (nullity 'PGjson)
1096+ => x -> Expression schema from grouping params (nullity 'PGjson)
1097+jsonLit = cast json . UnsafeExpression
1053−jsonLit = cast json . UnsafeExpression . singleQuotedUtf8 . toStrict . JSON.encode
1098+ . singleQuotedUtf8 . toStrict . JSON.encode
1055-- | Returns the value as json. Arrays and composites are converted
1100-- | Returns the value as json. Arrays and composites are converted
1056-- (recursively) to arrays and objects; otherwise, if there is a cast from the
1101-- (recursively) to arrays and objects; otherwise, if there is a cast from the
@@ -1059,8 +1104,8 @@ jsonLit = cast json . UnsafeExpression . singleQuotedUtf8 . toStrict . JSON.enco
1059-- number, a Boolean, or a null value, the text representation will be used, in
1104-- number, a Boolean, or a null value, the text representation will be used, in
1060-- such a fashion that it is a valid json value.
1105-- such a fashion that it is a valid json value.
1062− :: Expression schema relations grouping params (nullity ty)
1107+ :: Expression schema from grouping params (nullity ty)
1063− -> Expression schema relations grouping params (nullity 'PGjson)
1108+ -> Expression schema from grouping params (nullity 'PGjson)
1064toJson = unsafeFunction "to_json"
1109toJson = unsafeFunction "to_json"
1066-- | Returns the value as jsonb. Arrays and composites are converted
1111-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1070,43 +1115,43 @@ toJson = unsafeFunction "to_json"
1070-- number, a Boolean, or a null value, the text representation will be used, in
1115-- number, a Boolean, or a null value, the text representation will be used, in
1071-- such a fashion that it is a valid jsonb value.
1116-- such a fashion that it is a valid jsonb value.
1073− :: Expression schema relations grouping params (nullity ty)
1118+ :: Expression schema from grouping params (nullity ty)
1074− -> Expression schema relations grouping params (nullity 'PGjsonb)
1119+ -> Expression schema from grouping params (nullity 'PGjsonb)
1075toJsonb = unsafeFunction "to_jsonb"
1120toJsonb = unsafeFunction "to_jsonb"
1077-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1122-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1078-- becomes a JSON array of arrays.
1123-- becomes a JSON array of arrays.
1079arrayToJson
1124arrayToJson
1080− :: PGarray "arrayToJson" arr
1125+ :: PGArray "arrayToJson" arr
1081− => Expression schema relations grouping params (nullity arr)
1126+ => Expression schema from grouping params (nullity arr)
1082− -> Expression schema relations grouping params (nullity 'PGjson)
1127+ -> Expression schema from grouping params (nullity 'PGjson)
1083arrayToJson = unsafeFunction "array_to_json"
1128arrayToJson = unsafeFunction "array_to_json"
1085-- | Returns the row as a JSON object.
1130-- | Returns the row as a JSON object.
1086rowToJson
1131rowToJson
1087− :: Expression schema relations grouping params (nullity ('PGcomposite ty))
1132+ :: Expression schema from grouping params (nullity ('PGcomposite ty))
1088− -> Expression schema relations grouping params (nullity 'PGjson)
1133+ -> Expression schema from grouping params (nullity 'PGjson)
1089rowToJson = unsafeFunction "row_to_json"
1134rowToJson = unsafeFunction "row_to_json"
1091-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1136-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1092-- argument list.
1137-- argument list.
1093jsonBuildArray
1138jsonBuildArray
1094 :: SListI elems
1139 :: SListI elems
1095− => NP (Expression schema relations grouping params) elems
1140+ => NP (Expression schema from grouping params) elems
1096− -> Expression schema relations grouping params (nullity 'PGjson)
1141+ -> Expression schema from grouping params (nullity 'PGjson)
1097jsonBuildArray = unsafeVariadicFunction "json_build_array"
1142jsonBuildArray = unsafeVariadicFunction "json_build_array"
1099-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1144-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1100-- variadic argument list.
1145-- variadic argument list.
1101jsonbBuildArray
1146jsonbBuildArray
1102 :: SListI elems
1147 :: SListI elems
1103− => NP (Expression schema relations grouping params) elems
1148+ => NP (Expression schema from grouping params) elems
1104− -> Expression schema relations grouping params (nullity 'PGjsonb)
1149+ -> Expression schema from grouping params (nullity 'PGjsonb)
1105jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1150jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1107unsafeRowFunction
1152unsafeRowFunction
1108 :: All Top elems
1153 :: All Top elems
1109− => NP (Aliased (Expression schema relations grouping params)) elems
1154+ => NP (Aliased (Expression schema from grouping params)) elems
1110 -> [ByteString]
1155 -> [ByteString]
1111unsafeRowFunction =
1156unsafeRowFunction =
1112 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
1157 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1118,8 +1163,8 @@ unsafeRowFunction =
1118-- and values.
1163-- and values.
1119jsonBuildObject
1164jsonBuildObject
1120 :: All Top elems
1165 :: All Top elems
1121− => NP (Aliased (Expression schema relations grouping params)) elems
1166+ => NP (Aliased (Expression schema from grouping params)) elems
1122− -> Expression schema relations grouping params (nullity 'PGjson)
1167+ -> Expression schema from grouping params (nullity 'PGjson)
1123jsonBuildObject
1168jsonBuildObject
1124 = unsafeFunction "json_build_object"
1169 = unsafeFunction "json_build_object"
1125 . UnsafeExpression
1170 . UnsafeExpression
@@ -1131,8 +1176,8 @@ jsonBuildObject
1131-- between text and values.
1176-- between text and values.
1132jsonbBuildObject
1177jsonbBuildObject
1133 :: All Top elems
1178 :: All Top elems
1134− => NP (Aliased (Expression schema relations grouping params)) elems
1179+ => NP (Aliased (Expression schema from grouping params)) elems
1135− -> Expression schema relations grouping params (nullity 'PGjsonb)
1180+ -> Expression schema from grouping params (nullity 'PGjsonb)
1136jsonbBuildObject
1181jsonbBuildObject
1137 = unsafeFunction "jsonb_build_object"
1182 = unsafeFunction "jsonb_build_object"
1138 . UnsafeExpression
1183 . UnsafeExpression
@@ -1144,9 +1189,9 @@ jsonbBuildObject
1144-- taken as alternating key/value pairs, or two dimensions such that each inner
1189-- taken as alternating key/value pairs, or two dimensions such that each inner
1145-- array has exactly two elements, which are taken as a key/value pair.
1190-- array has exactly two elements, which are taken as a key/value pair.
1146jsonObject
1191jsonObject
1147− :: PGarrayOf "jsonObject" arr 'PGtext
1192+ :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1148− => Expression schema relations grouping params (nullity arr)
1193+ => Expression schema from grouping params (nullity arr)
1149− -> Expression schema relations grouping params (nullity 'PGjson)
1194+ -> Expression schema from grouping params (nullity 'PGjson)
1150jsonObject = unsafeFunction "json_object"
1195jsonObject = unsafeFunction "json_object"
1152-- | Builds a binary JSON object out of a text array. The array must have either
1197-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1154,19 +1199,19 @@ jsonObject = unsafeFunction "json_object"
1154-- taken as alternating key/value pairs, or two dimensions such that each inner
1199-- taken as alternating key/value pairs, or two dimensions such that each inner
1155-- array has exactly two elements, which are taken as a key/value pair.
1200-- array has exactly two elements, which are taken as a key/value pair.
1156jsonbObject
1201jsonbObject
1157− :: PGarrayOf "jsonbObject" arr 'PGtext
1202+ :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1158− => Expression schema relations grouping params (nullity arr)
1203+ => Expression schema from grouping params (nullity arr)
1159− -> Expression schema relations grouping params (nullity 'PGjsonb)
1204+ -> Expression schema from grouping params (nullity 'PGjsonb)
1160jsonbObject = unsafeFunction "jsonb_object"
1205jsonbObject = unsafeFunction "jsonb_object"
1162-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1207-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1163-- keys and one for values, that are zipped pairwise to create a JSON object.
1208-- keys and one for values, that are zipped pairwise to create a JSON object.
1164jsonZipObject
1209jsonZipObject
1165− :: ( PGarrayOf "jsonZipObject" keysArray 'PGtext
1210+ :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1166− , PGarrayOf "jsonZipObject" valuesArray 'PGtext)
1211+ , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1167− => Expression schema relations grouping params (nullity keysArray)
1212+ => Expression schema from grouping params (nullity keysArray)
1168− -> Expression schema relations grouping params (nullity valuesArray)
1213+ -> Expression schema from grouping params (nullity valuesArray)
1169− -> Expression schema relations grouping params (nullity 'PGjson)
1214+ -> Expression schema from grouping params (nullity 'PGjson)
1170jsonZipObject ks vs =
1215jsonZipObject ks vs =
1171 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1216 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
@@ -1174,11 +1219,11 @@ jsonZipObject ks vs =
1174-- keys and one for values, that are zipped pairwise to create a binary JSON
1219-- keys and one for values, that are zipped pairwise to create a binary JSON
1175-- object.
1220-- object.
1176jsonbZipObject
1221jsonbZipObject
1177− :: ( PGarrayOf "jsonbZipObject" keysArray 'PGtext
1222+ :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1178− , PGarrayOf "jsonbZipObject" valuesArray 'PGtext)
1223+ , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1179− => Expression schema relations grouping params (nullity keysArray)
1224+ => Expression schema from grouping params (nullity keysArray)
1180− -> Expression schema relations grouping params (nullity valuesArray)
1225+ -> Expression schema from grouping params (nullity valuesArray)
1181− -> Expression schema relations grouping params (nullity 'PGjsonb)
1226+ -> Expression schema from grouping params (nullity 'PGjsonb)
1182jsonbZipObject ks vs =
1227jsonbZipObject ks vs =
1183 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1228 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
@@ -1188,23 +1233,23 @@ Table 9.46: JSON processing functions
1189-- | Returns the number of elements in the outermost JSON array.
1234-- | Returns the number of elements in the outermost JSON array.
1190jsonArrayLength
1235jsonArrayLength
1191− :: Expression schema relations grouping params (nullity 'PGjson)
1236+ :: Expression schema from grouping params (nullity 'PGjson)
1192− -> Expression schema relations grouping params (nullity 'PGint4)
1237+ -> Expression schema from grouping params (nullity 'PGint4)
1193jsonArrayLength = unsafeFunction "json_array_length"
1238jsonArrayLength = unsafeFunction "json_array_length"
1195-- | Returns the number of elements in the outermost binary JSON array.
1240-- | Returns the number of elements in the outermost binary JSON array.
1196jsonbArrayLength
1241jsonbArrayLength
1197− :: Expression schema relations grouping params (nullity 'PGjsonb)
1242+ :: Expression schema from grouping params (nullity 'PGjsonb)
1198− -> Expression schema relations grouping params (nullity 'PGint4)
1243+ -> Expression schema from grouping params (nullity 'PGint4)
1199jsonbArrayLength = unsafeFunction "jsonb_array_length"
1244jsonbArrayLength = unsafeFunction "jsonb_array_length"
1201-- | Returns JSON value pointed to by the given path (equivalent to #>
1246-- | Returns JSON value pointed to by the given path (equivalent to #>
1202-- operator).
1247-- operator).
1203jsonExtractPath
1248jsonExtractPath
1204 :: SListI elems
1249 :: SListI elems
1205− => Expression schema relations grouping params (nullity 'PGjson)
1250+ => Expression schema from grouping params (nullity 'PGjson)
1206− -> NP (Expression schema relations grouping params) elems
1251+ -> NP (Expression schema from grouping params) elems
1207− -> Expression schema relations grouping params (nullity 'PGjsonb)
1252+ -> Expression schema from grouping params (nullity 'PGjsonb)
1208jsonExtractPath x xs =
1253jsonExtractPath x xs =
1209 unsafeVariadicFunction "json_extract_path" (x :* xs)
1254 unsafeVariadicFunction "json_extract_path" (x :* xs)
@@ -1212,9 +1257,9 @@ jsonExtractPath x xs =
1212-- operator).
1257-- operator).
1213jsonbExtractPath
1258jsonbExtractPath
1214 :: SListI elems
1259 :: SListI elems
1215− => Expression schema relations grouping params (nullity 'PGjsonb)
1260+ => Expression schema from grouping params (nullity 'PGjsonb)
1216− -> NP (Expression schema relations grouping params) elems
1261+ -> NP (Expression schema from grouping params) elems
1217− -> Expression schema relations grouping params (nullity 'PGjsonb)
1262+ -> Expression schema from grouping params (nullity 'PGjsonb)
1218jsonbExtractPath x xs =
1263jsonbExtractPath x xs =
1219 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1264 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
@@ -1222,9 +1267,9 @@ jsonbExtractPath x xs =
1222-- operator), as text.
1267-- operator), as text.
1223jsonExtractPathAsText
1268jsonExtractPathAsText
1224 :: SListI elems
1269 :: SListI elems
1225− => Expression schema relations grouping params (nullity 'PGjson)
1270+ => Expression schema from grouping params (nullity 'PGjson)
1226− -> NP (Expression schema relations grouping params) elems
1271+ -> NP (Expression schema from grouping params) elems
1227− -> Expression schema relations grouping params (nullity 'PGjson)
1272+ -> Expression schema from grouping params (nullity 'PGjson)
1228jsonExtractPathAsText x xs =
1273jsonExtractPathAsText x xs =
1229 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1274 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
@@ -1232,50 +1277,38 @@ jsonExtractPathAsText x xs =
1232-- operator), as text.
1277-- operator), as text.
1233jsonbExtractPathAsText
1278jsonbExtractPathAsText
1234 :: SListI elems
1279 :: SListI elems
1235− => Expression schema relations grouping params (nullity 'PGjsonb)
1280+ => Expression schema from grouping params (nullity 'PGjsonb)
1236− -> NP (Expression schema relations grouping params) elems
1281+ -> NP (Expression schema from grouping params) elems
1237− -> Expression schema relations grouping params (nullity 'PGjsonb)
1282+ -> Expression schema from grouping params (nullity 'PGjsonb)
1238jsonbExtractPathAsText x xs =
1283jsonbExtractPathAsText x xs =
1239 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1284 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1241−-- | Returns set of keys in the outermost JSON object.
1243− :: Expression schema relations grouping params (nullity 'PGjson)
1244− -> Expression schema relations grouping params (nullity 'PGtext)
1245−jsonObjectKeys = unsafeFunction "json_object_keys"
1247−-- | Returns set of keys in the outermost JSON object.
1249− :: Expression schema relations grouping params (nullity 'PGjsonb)
1250− -> Expression schema relations grouping params (nullity 'PGtext)
1251−jsonbObjectKeys = unsafeFunction "jsonb_object_keys"
1253-- | Returns the type of the outermost JSON value as a text string. Possible
1286-- | Returns the type of the outermost JSON value as a text string. Possible
1254-- types are object, array, string, number, boolean, and null.
1287-- types are object, array, string, number, boolean, and null.
1255jsonTypeof
1288jsonTypeof
1256− :: Expression schema relations grouping params (nullity 'PGjson)
1289+ :: Expression schema from grouping params (nullity 'PGjson)
1257− -> Expression schema relations grouping params (nullity 'PGtext)
1290+ -> Expression schema from grouping params (nullity 'PGtext)
1258jsonTypeof = unsafeFunction "json_typeof"
1291jsonTypeof = unsafeFunction "json_typeof"
1260-- | Returns the type of the outermost binary JSON value as a text string.
1293-- | Returns the type of the outermost binary JSON value as a text string.
1261-- Possible types are object, array, string, number, boolean, and null.
1294-- Possible types are object, array, string, number, boolean, and null.
1262jsonbTypeof
1295jsonbTypeof
1263− :: Expression schema relations grouping params (nullity 'PGjsonb)
1296+ :: Expression schema from grouping params (nullity 'PGjsonb)
1264− -> Expression schema relations grouping params (nullity 'PGtext)
1297+ -> Expression schema from grouping params (nullity 'PGtext)
1265jsonbTypeof = unsafeFunction "jsonb_typeof"
1298jsonbTypeof = unsafeFunction "jsonb_typeof"
1267-- | Returns its argument with all object fields that have null values omitted.
1300-- | Returns its argument with all object fields that have null values omitted.
1268-- Other null values are untouched.
1301-- Other null values are untouched.
1269jsonStripNulls
1302jsonStripNulls
1270− :: Expression schema relations grouping params (nullity 'PGjson)
1303+ :: Expression schema from grouping params (nullity 'PGjson)
1271− -> Expression schema relations grouping params (nullity 'PGjson)
1304+ -> Expression schema from grouping params (nullity 'PGjson)
1272jsonStripNulls = unsafeFunction "json_strip_nulls"
1305jsonStripNulls = unsafeFunction "json_strip_nulls"
1274-- | Returns its argument with all object fields that have null values omitted.
1307-- | Returns its argument with all object fields that have null values omitted.
1275-- Other null values are untouched.
1308-- Other null values are untouched.
1276jsonbStripNulls
1309jsonbStripNulls
1277− :: Expression schema relations grouping params (nullity 'PGjsonb)
1310+ :: Expression schema from grouping params (nullity 'PGjsonb)
1278− -> Expression schema relations grouping params (nullity 'PGjsonb)
1311+ -> Expression schema from grouping params (nullity 'PGjsonb)
1279jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1312jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1281-- | @ jsonbSet target path new_value create_missing @
1314-- | @ jsonbSet target path new_value create_missing @
@@ -1286,12 +1319,12 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1286-- operators, negative integers that appear in path count from the end of JSON
1319-- operators, negative integers that appear in path count from the end of JSON
1287-- arrays.
1320-- arrays.
1289− :: PGtextArray "jsonbSet" arr
1322+ :: PGTextArray "jsonbSet" arr
1290− => Expression schema relations grouping params (nullity 'PGjsonb)
1323+ => Expression schema from grouping params (nullity 'PGjsonb)
1291− -> Expression schema relations grouping params (nullity arr)
1324+ -> Expression schema from grouping params (nullity arr)
1292− -> Expression schema relations grouping params (nullity 'PGjsonb)
1325+ -> Expression schema from grouping params (nullity 'PGjsonb)
1293− -> Maybe (Expression schema relations grouping params (nullity 'PGbool))
1326+ -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1294− -> Expression schema relations grouping params (nullity 'PGjsonb)
1327+ -> Expression schema from grouping params (nullity 'PGjsonb)
1295jsonbSet tgt path val createMissing = case createMissing of
1328jsonbSet tgt path val createMissing = case createMissing of
1296 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1329 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1297 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
1330 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1305,20 +1338,20 @@ jsonbSet tgt path val createMissing = case createMissing of
1305-- exist. As with the path orientated operators, negative integers that appear
1338-- exist. As with the path orientated operators, negative integers that appear
1306-- in path count from the end of JSON arrays.
1339-- in path count from the end of JSON arrays.
1307jsonbInsert
1340jsonbInsert
1308− :: PGtextArray "jsonbInsert" arr
1341+ :: PGTextArray "jsonbInsert" arr
1309− => Expression schema relations grouping params (nullity 'PGjsonb)
1342+ => Expression schema from grouping params (nullity 'PGjsonb)
1310− -> Expression schema relations grouping params (nullity arr)
1343+ -> Expression schema from grouping params (nullity arr)
1311− -> Expression schema relations grouping params (nullity 'PGjsonb)
1344+ -> Expression schema from grouping params (nullity 'PGjsonb)
1312− -> Maybe (Expression schema relations grouping params (nullity 'PGbool))
1345+ -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1313− -> Expression schema relations grouping params (nullity 'PGjsonb)
1346+ -> Expression schema from grouping params (nullity 'PGjsonb)
1314jsonbInsert tgt path val insertAfter = case insertAfter of
1347jsonbInsert tgt path val insertAfter = case insertAfter of
1315 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1348 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1316 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1349 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1318-- | Returns its argument as indented JSON text.
1351-- | Returns its argument as indented JSON text.
1319jsonbPretty
1352jsonbPretty
1320− :: Expression schema relations grouping params (nullity 'PGjsonb)
1353+ :: Expression schema from grouping params (nullity 'PGjsonb)
1321− -> Expression schema relations grouping params (nullity 'PGtext)
1354+ -> Expression schema from grouping params (nullity 'PGtext)
1322jsonbPretty = unsafeFunction "jsonb_pretty"
1355jsonbPretty = unsafeFunction "jsonb_pretty"
1324{-----------------------------------------
1357{-----------------------------------------
@@ -1328,16 +1361,16 @@ aggregation
1328-- | escape hatch to define aggregate functions
1361-- | escape hatch to define aggregate functions
1329unsafeAggregate
1362unsafeAggregate
1330 :: ByteString -- ^ aggregate function
1363 :: ByteString -- ^ aggregate function
1331− -> Expression schema relations 'Ungrouped params (xty)
1364+ -> Expression schema from 'Ungrouped params (xty)
1332− -> Expression schema relations ('Grouped bys) params (yty)
1365+ -> Expression schema from ('Grouped bys) params (yty)
1333unsafeAggregate fun x = UnsafeExpression $ mconcat
1366unsafeAggregate fun x = UnsafeExpression $ mconcat
1334 [fun, "(", renderExpression x, ")"]
1367 [fun, "(", renderExpression x, ")"]
1336-- | escape hatch to define aggregate functions over distinct values
1369-- | escape hatch to define aggregate functions over distinct values
1337unsafeAggregateDistinct
1370unsafeAggregateDistinct
1338 :: ByteString -- ^ aggregate function
1371 :: ByteString -- ^ aggregate function
1339− -> Expression schema relations 'Ungrouped params (xty)
1372+ -> Expression schema from 'Ungrouped params (xty)
1340− -> Expression schema relations ('Grouped bys) params (yty)
1373+ -> Expression schema from ('Grouped bys) params (yty)
1341unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1374unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1342 [fun, "(DISTINCT ", renderExpression x, ")"]
1375 [fun, "(DISTINCT ", renderExpression x, ")"]
@@ -1349,10 +1382,10 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1350-- sum("col")
1383-- sum("col")
1352− :: PGNum ty
1385+ :: ty `In` PGNum
1353− => Expression schema relations 'Ungrouped params (nullity ty)
1386+ => Expression schema from 'Ungrouped params (nullity ty)
1354 -- ^ what to sum
1387 -- ^ what to sum
1355− -> Expression schema relations ('Grouped bys) params (nullity ty)
1388+ -> Expression schema from ('Grouped bys) params (nullity ty)
1356sum_ = unsafeAggregate "sum"
1389sum_ = unsafeAggregate "sum"
1358-- | >>> :{
1391-- | >>> :{
@@ -1363,19 +1396,19 @@ sum_ = unsafeAggregate "sum"
1364-- sum(DISTINCT "col")
1397-- sum(DISTINCT "col")
1365sumDistinct
1398sumDistinct
1366− :: PGNum ty
1399+ :: ty `In` PGNum
1367− => Expression schema relations 'Ungrouped params (nullity ty)
1400+ => Expression schema from 'Ungrouped params (nullity ty)
1368 -- ^ what to sum
1401 -- ^ what to sum
1369− -> Expression schema relations ('Grouped bys) params (nullity ty)
1402+ -> Expression schema from ('Grouped bys) params (nullity ty)
1370sumDistinct = unsafeAggregateDistinct "sum"
1403sumDistinct = unsafeAggregateDistinct "sum"
1372-- | A constraint for `PGType`s that you can take averages of and the resulting
1405-- | A constraint for `PGType`s that you can take averages of and the resulting
1373-- `PGType`.
1406-- `PGType`.
1374class PGAvg ty avg | ty -> avg where
1407class PGAvg ty avg | ty -> avg where
1375 avg, avgDistinct
1408 avg, avgDistinct
1376− :: Expression schema relations 'Ungrouped params (nullity ty)
1409+ :: Expression schema from 'Ungrouped params (nullity ty)
1377 -- ^ what to average
1410 -- ^ what to average
1378− -> Expression schema relations ('Grouped bys) params (nullity avg)
1411+ -> Expression schema from ('Grouped bys) params (nullity avg)
1379 avg = unsafeAggregate "avg"
1412 avg = unsafeAggregate "avg"
1380 avgDistinct = unsafeAggregateDistinct "avg"
1413 avgDistinct = unsafeAggregateDistinct "avg"
1381instance PGAvg 'PGint2 'PGnumeric
1414instance PGAvg 'PGint2 'PGnumeric
@@ -1394,10 +1427,10 @@ instance PGAvg 'PGinterval 'PGinterval
1395-- bit_and("col")
1428-- bit_and("col")
1397− :: PGIntegral int
1430+ :: int `In` PGIntegral
1398− => Expression schema relations 'Ungrouped params (nullity int)
1431+ => Expression schema from 'Ungrouped params (nullity int)
1399 -- ^ what to aggregate
1432 -- ^ what to aggregate
1400− -> Expression schema relations ('Grouped bys) params (nullity int)
1433+ -> Expression schema from ('Grouped bys) params (nullity int)
1401bitAnd = unsafeAggregate "bit_and"
1434bitAnd = unsafeAggregate "bit_and"
1403-- | >>> :{
1436-- | >>> :{
@@ -1408,10 +1441,10 @@ bitAnd = unsafeAggregate "bit_and"
1409-- bit_or("col")
1442-- bit_or("col")
1411− :: PGIntegral int
1444+ :: int `In` PGIntegral
1412− => Expression schema relations 'Ungrouped params (nullity int)
1445+ => Expression schema from 'Ungrouped params (nullity int)
1413 -- ^ what to aggregate
1446 -- ^ what to aggregate
1414− -> Expression schema relations ('Grouped bys) params (nullity int)
1447+ -> Expression schema from ('Grouped bys) params (nullity int)
1415bitOr = unsafeAggregate "bit_or"
1448bitOr = unsafeAggregate "bit_or"
1417-- | >>> :{
1450-- | >>> :{
@@ -1422,10 +1455,10 @@ bitOr = unsafeAggregate "bit_or"
1423-- bit_and(DISTINCT "col")
1456-- bit_and(DISTINCT "col")
1424bitAndDistinct
1457bitAndDistinct
1425− :: PGIntegral int
1458+ :: int `In` PGIntegral
1426− => Expression schema relations 'Ungrouped params (nullity int)
1459+ => Expression schema from 'Ungrouped params (nullity int)
1427 -- ^ what to aggregate
1460 -- ^ what to aggregate
1428− -> Expression schema relations ('Grouped bys) params (nullity int)
1461+ -> Expression schema from ('Grouped bys) params (nullity int)
1429bitAndDistinct = unsafeAggregateDistinct "bit_and"
1462bitAndDistinct = unsafeAggregateDistinct "bit_and"
1431-- | >>> :{
1464-- | >>> :{
@@ -1436,10 +1469,10 @@ bitAndDistinct = unsafeAggregateDistinct "bit_and"
1437-- bit_or(DISTINCT "col")
1470-- bit_or(DISTINCT "col")
1438bitOrDistinct
1471bitOrDistinct
1439− :: PGIntegral int
1472+ :: int `In` PGIntegral
1440− => Expression schema relations 'Ungrouped params (nullity int)
1473+ => Expression schema from 'Ungrouped params (nullity int)
1441 -- ^ what to aggregate
1474 -- ^ what to aggregate
1442− -> Expression schema relations ('Grouped bys) params (nullity int)
1475+ -> Expression schema from ('Grouped bys) params (nullity int)
1443bitOrDistinct = unsafeAggregateDistinct "bit_or"
1476bitOrDistinct = unsafeAggregateDistinct "bit_or"
1445-- | >>> :{
1478-- | >>> :{
@@ -1450,9 +1483,9 @@ bitOrDistinct = unsafeAggregateDistinct "bit_or"
1451-- bool_and("col")
1484-- bool_and("col")
1453− :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1486+ :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1454 -- ^ what to aggregate
1487 -- ^ what to aggregate
1455− -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1488+ -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1456boolAnd = unsafeAggregate "bool_and"
1489boolAnd = unsafeAggregate "bool_and"
1458-- | >>> :{
1491-- | >>> :{
@@ -1463,9 +1496,9 @@ boolAnd = unsafeAggregate "bool_and"
1464-- bool_or("col")
1497-- bool_or("col")
1466− :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1499+ :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1467 -- ^ what to aggregate
1500 -- ^ what to aggregate
1468− -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1501+ -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1469boolOr = unsafeAggregate "bool_or"
1502boolOr = unsafeAggregate "bool_or"
1471-- | >>> :{
1504-- | >>> :{
@@ -1476,9 +1509,9 @@ boolOr = unsafeAggregate "bool_or"
1477-- bool_and(DISTINCT "col")
1510-- bool_and(DISTINCT "col")
1478boolAndDistinct
1511boolAndDistinct
1479− :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1512+ :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1480 -- ^ what to aggregate
1513 -- ^ what to aggregate
1481− -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1514+ -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1482boolAndDistinct = unsafeAggregateDistinct "bool_and"
1515boolAndDistinct = unsafeAggregateDistinct "bool_and"
1484-- | >>> :{
1517-- | >>> :{
@@ -1489,9 +1522,9 @@ boolAndDistinct = unsafeAggregateDistinct "bool_and"
1490-- bool_or(DISTINCT "col")
1523-- bool_or(DISTINCT "col")
1491boolOrDistinct
1524boolOrDistinct
1492− :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1525+ :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1493 -- ^ what to aggregate
1526 -- ^ what to aggregate
1494− -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1527+ -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1495boolOrDistinct = unsafeAggregateDistinct "bool_or"
1528boolOrDistinct = unsafeAggregateDistinct "bool_or"
1497-- | A special aggregation that does not require an input
1530-- | A special aggregation that does not require an input
@@ -1499,7 +1532,7 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
1499-- >>> printSQL countStar
1532-- >>> printSQL countStar
1500-- count(*)
1533-- count(*)
1501countStar
1534countStar
1502− :: Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1535+ :: Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1503countStar = UnsafeExpression $ "count(*)"
1536countStar = UnsafeExpression $ "count(*)"
1505-- | >>> :{
1538-- | >>> :{
@@ -1510,9 +1543,9 @@ countStar = UnsafeExpression $ "count(*)"
1511-- count("col")
1544-- count("col")
1513− :: Expression schema relations 'Ungrouped params ty
1546+ :: Expression schema from 'Ungrouped params ty
1514 -- ^ what to count
1547 -- ^ what to count
1515− -> Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1548+ -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1516count = unsafeAggregate "count"
1549count = unsafeAggregate "count"
1518-- | >>> :{
1551-- | >>> :{
@@ -1523,9 +1556,9 @@ count = unsafeAggregate "count"
1524-- count(DISTINCT "col")
1557-- count(DISTINCT "col")
1525countDistinct
1558countDistinct
1526− :: Expression schema relations 'Ungrouped params ty
1559+ :: Expression schema from 'Ungrouped params ty
1527 -- ^ what to count
1560 -- ^ what to count
1528− -> Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1561+ -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1529countDistinct = unsafeAggregateDistinct "count"
1562countDistinct = unsafeAggregateDistinct "count"
1531-- | synonym for `boolAnd`
1564-- | synonym for `boolAnd`
@@ -1538,9 +1571,9 @@ countDistinct = unsafeAggregateDistinct "count"
1539-- every("col")
1572-- every("col")
1541− :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1574+ :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1542 -- ^ what to aggregate
1575 -- ^ what to aggregate
1543− -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1576+ -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1544every = unsafeAggregate "every"
1577every = unsafeAggregate "every"
1546-- | synonym for `boolAndDistinct`
1579-- | synonym for `boolAndDistinct`
@@ -1553,16 +1586,16 @@ every = unsafeAggregate "every"
1554-- every(DISTINCT "col")
1587-- every(DISTINCT "col")
1555everyDistinct
1588everyDistinct
1556− :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1589+ :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1557 -- ^ what to aggregate
1590 -- ^ what to aggregate
1558− -> Expression schema relations ('Grouped bys) params (nullity 'PGbool)
1591+ -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1559everyDistinct = unsafeAggregateDistinct "every"
1592everyDistinct = unsafeAggregateDistinct "every"
1561-- | minimum and maximum aggregation
1594-- | minimum and maximum aggregation
1562max_, min_, maxDistinct, minDistinct
1595max_, min_, maxDistinct, minDistinct
1563− :: Expression schema relations 'Ungrouped params (nullity ty)
1596+ :: Expression schema from 'Ungrouped params (nullity ty)
1564 -- ^ what to aggregate
1597 -- ^ what to aggregate
1565− -> Expression schema relations ('Grouped bys) params (nullity ty)
1598+ -> Expression schema from ('Grouped bys) params (nullity ty)
1566max_ = unsafeAggregate "max"
1599max_ = unsafeAggregate "max"
1567min_ = unsafeAggregate "min"
1600min_ = unsafeAggregate "min"
1568maxDistinct = unsafeAggregateDistinct "max"
1601maxDistinct = unsafeAggregateDistinct "max"
@@ -1573,134 +1606,153 @@ type expressions
1573-----------------------------------------}
1606-----------------------------------------}
1575-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1608-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1576−newtype TypeExpression (schema :: SchemaType) (ty :: PGType)
1609+newtype TypeExpression (schema :: SchemaType) (ty :: NullityType)
1577 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1610 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1578 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1611 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1613+-- | The enum or composite type in a `Typedef` can be expressed by its alias.
1580−instance (Has alias schema ('Typedef ty))
1615+ :: Has alias schema ('Typedef ty)
1581− => IsLabel alias (TypeExpression schema ty) where
1617+ -> TypeExpression schema (nullity ty)
1582− fromLabel = UnsafeTypeExpression (renderAlias (fromLabel @alias))
1618+typedef = UnsafeTypeExpression . renderAlias
1620+-- | The composite type corresponding to a `Table` definition can be expressed
1623+ :: Has alias schema ('Table tab)
1625+ -> TypeExpression schema (nullity ('PGcomposite (TableToRow tab)))
1626+typetable = UnsafeTypeExpression . renderAlias
1628+-- | The composite type corresponding to a `View` definition can be expressed
1631+ :: Has alias schema ('View view)
1633+ -> TypeExpression schema (nullity ('PGcomposite view))
1634+typeview = UnsafeTypeExpression . renderAlias
1584-- | logical Boolean (true/false)
1636-- | logical Boolean (true/false)
1585−bool :: TypeExpression schema 'PGbool
1637+bool :: TypeExpression schema (nullity 'PGbool)
1586bool = UnsafeTypeExpression "bool"
1638bool = UnsafeTypeExpression "bool"
1587-- | signed two-byte integer
1639-- | signed two-byte integer
1588−int2, smallint :: TypeExpression schema 'PGint2
1640+int2, smallint :: TypeExpression schema (nullity 'PGint2)
1589int2 = UnsafeTypeExpression "int2"
1641int2 = UnsafeTypeExpression "int2"
1590smallint = UnsafeTypeExpression "smallint"
1642smallint = UnsafeTypeExpression "smallint"
1591-- | signed four-byte integer
1643-- | signed four-byte integer
1592−int4, int, integer :: TypeExpression schema 'PGint4
1644+int4, int, integer :: TypeExpression schema (nullity 'PGint4)
1593int4 = UnsafeTypeExpression "int4"
1645int4 = UnsafeTypeExpression "int4"
1594int = UnsafeTypeExpression "int"
1646int = UnsafeTypeExpression "int"
1595integer = UnsafeTypeExpression "integer"
1647integer = UnsafeTypeExpression "integer"
1596-- | signed eight-byte integer
1648-- | signed eight-byte integer
1597−int8, bigint :: TypeExpression schema 'PGint8
1649+int8, bigint :: TypeExpression schema (nullity 'PGint8)
1598int8 = UnsafeTypeExpression "int8"
1650int8 = UnsafeTypeExpression "int8"
1599bigint = UnsafeTypeExpression "bigint"
1651bigint = UnsafeTypeExpression "bigint"
1600-- | arbitrary precision numeric type
1652-- | arbitrary precision numeric type
1601−numeric :: TypeExpression schema 'PGnumeric
1653+numeric :: TypeExpression schema (nullity 'PGnumeric)
1602numeric = UnsafeTypeExpression "numeric"
1654numeric = UnsafeTypeExpression "numeric"
1603-- | single precision floating-point number (4 bytes)
1655-- | single precision floating-point number (4 bytes)
1604−float4, real :: TypeExpression schema 'PGfloat4
1656+float4, real :: TypeExpression schema (nullity 'PGfloat4)
1605float4 = UnsafeTypeExpression "float4"
1657float4 = UnsafeTypeExpression "float4"
1606real = UnsafeTypeExpression "real"
1658real = UnsafeTypeExpression "real"
1607-- | double precision floating-point number (8 bytes)
1659-- | double precision floating-point number (8 bytes)
1608−float8, doublePrecision :: TypeExpression schema 'PGfloat8
1660+float8, doublePrecision :: TypeExpression schema (nullity 'PGfloat8)
1609float8 = UnsafeTypeExpression "float8"
1661float8 = UnsafeTypeExpression "float8"
1610doublePrecision = UnsafeTypeExpression "double precision"
1662doublePrecision = UnsafeTypeExpression "double precision"
1611-- | variable-length character string
1663-- | variable-length character string
1612−text :: TypeExpression schema 'PGtext
1664+text :: TypeExpression schema (nullity 'PGtext)
1613text = UnsafeTypeExpression "text"
1665text = UnsafeTypeExpression "text"
1614-- | fixed-length character string
1666-- | fixed-length character string
1615char, character
1667char, character
1616− :: (KnownNat n, 1 <= n)
1668+ :: forall n schema nullity. (KnownNat n, 1 <= n)
1618− -> TypeExpression schema ('PGchar n)
1669+ => TypeExpression schema (nullity ('PGchar n))
1619−char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
1670+char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
1620−character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
1671+character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
1621-- | variable-length character string
1672-- | variable-length character string
1622varchar, characterVarying
1673varchar, characterVarying
1623− :: (KnownNat n, 1 <= n)
1674+ :: forall n schema nullity. (KnownNat n, 1 <= n)
1625− -> TypeExpression schema ('PGvarchar n)
1675+ => TypeExpression schema (nullity ('PGvarchar n))
1626−varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
1676+varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
1627−characterVarying p = UnsafeTypeExpression $
1677+characterVarying = UnsafeTypeExpression $
1628− "character varying(" <> renderNat p <> ")"
1678+ "character varying(" <> renderNat @n <> ")"
1629-- | binary data ("byte array")
1679-- | binary data ("byte array")
1630−bytea :: TypeExpression schema 'PGbytea
1680+bytea :: TypeExpression schema (nullity 'PGbytea)
1631bytea = UnsafeTypeExpression "bytea"
1681bytea = UnsafeTypeExpression "bytea"
1632-- | date and time (no time zone)
1682-- | date and time (no time zone)
1633−timestamp :: TypeExpression schema 'PGtimestamp
1683+timestamp :: TypeExpression schema (nullity 'PGtimestamp)
1634timestamp = UnsafeTypeExpression "timestamp"
1684timestamp = UnsafeTypeExpression "timestamp"
1635-- | date and time, including time zone
1685-- | date and time, including time zone
1636−timestampWithTimeZone :: TypeExpression schema 'PGtimestamptz
1686+timestampWithTimeZone :: TypeExpression schema (nullity 'PGtimestamptz)
1637timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1687timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1638-- | calendar date (year, month, day)
1688-- | calendar date (year, month, day)
1639−date :: TypeExpression schema 'PGdate
1689+date :: TypeExpression schema (nullity 'PGdate)
1640date = UnsafeTypeExpression "date"
1690date = UnsafeTypeExpression "date"
1641-- | time of day (no time zone)
1691-- | time of day (no time zone)
1642−time :: TypeExpression schema 'PGtime
1692+time :: TypeExpression schema (nullity 'PGtime)
1643time = UnsafeTypeExpression "time"
1693time = UnsafeTypeExpression "time"
1644-- | time of day, including time zone
1694-- | time of day, including time zone
1645−timeWithTimeZone :: TypeExpression schema 'PGtimetz
1695+timeWithTimeZone :: TypeExpression schema (nullity 'PGtimetz)
1646timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1696timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1647-- | time span
1697-- | time span
1648−interval :: TypeExpression schema 'PGinterval
1698+interval :: TypeExpression schema (nullity 'PGinterval)
1649interval = UnsafeTypeExpression "interval"
1699interval = UnsafeTypeExpression "interval"
1650-- | universally unique identifier
1700-- | universally unique identifier
1651−uuid :: TypeExpression schema 'PGuuid
1701+uuid :: TypeExpression schema (nullity 'PGuuid)
1652uuid = UnsafeTypeExpression "uuid"
1702uuid = UnsafeTypeExpression "uuid"
1653-- | IPv4 or IPv6 host address
1703-- | IPv4 or IPv6 host address
1654−inet :: TypeExpression schema 'PGinet
1704+inet :: TypeExpression schema (nullity 'PGinet)
1655inet = UnsafeTypeExpression "inet"
1705inet = UnsafeTypeExpression "inet"
1656-- | textual JSON data
1706-- | textual JSON data
1657−json :: TypeExpression schema 'PGjson
1707+json :: TypeExpression schema (nullity 'PGjson)
1658json = UnsafeTypeExpression "json"
1708json = UnsafeTypeExpression "json"
1659-- | binary JSON data, decomposed
1709-- | binary JSON data, decomposed
1660−jsonb :: TypeExpression schema 'PGjsonb
1710+jsonb :: TypeExpression schema (nullity 'PGjsonb)
1661jsonb = UnsafeTypeExpression "jsonb"
1711jsonb = UnsafeTypeExpression "jsonb"
1662-- | variable length array
1712-- | variable length array
1664 :: TypeExpression schema pg
1714 :: TypeExpression schema pg
1665− -> TypeExpression schema ('PGvararray pg)
1715+ -> TypeExpression schema (nullity ('PGvararray pg))
1666vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1716vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1667-- | fixed length array
1717-- | fixed length array
1669−-- >>> renderTypeExpression (fixarray (Proxy @2) json)
1719+-- >>> renderTypeExpression (fixarray @2 json)
1670-- "json[2]"
1720-- "json[2]"
1672− :: KnownNat n
1722+ :: forall n schema nullity pg. KnownNat n
1674− -> TypeExpression schema pg
1723+ => TypeExpression schema pg
1675− -> TypeExpression schema ('PGfixarray n pg)
1724+ -> TypeExpression schema (nullity ('PGfixarray n pg))
1676−fixarray p ty = UnsafeTypeExpression $
1725+fixarray ty = UnsafeTypeExpression $
1677− renderTypeExpression ty <> "[" <> renderNat p <> "]"
1726+ renderTypeExpression ty <> "[" <> renderNat @n <> "]"
1679-- | `pgtype` is a demoted version of a `PGType`
1728-- | `pgtype` is a demoted version of a `PGType`
1729+class PGTyped schema (ty :: NullityType) where
1680−class PGTyped schema (ty :: PGType) where pgtype :: TypeExpression schema ty
1730+ pgtype :: TypeExpression schema ty
1681−instance PGTyped schema 'PGbool where pgtype = bool
1731+instance PGTyped schema (nullity 'PGbool) where pgtype = bool
1682−instance PGTyped schema 'PGint2 where pgtype = int2
1732+instance PGTyped schema (nullity 'PGint2) where pgtype = int2
1683−instance PGTyped schema 'PGint4 where pgtype = int4
1733+instance PGTyped schema (nullity 'PGint4) where pgtype = int4
1684−instance PGTyped schema 'PGint8 where pgtype = int8
1734+instance PGTyped schema (nullity 'PGint8) where pgtype = int8
1685−instance PGTyped schema 'PGnumeric where pgtype = numeric
1735+instance PGTyped schema (nullity 'PGnumeric) where pgtype = numeric
1686−instance PGTyped schema 'PGfloat4 where pgtype = float4
1736+instance PGTyped schema (nullity 'PGfloat4) where pgtype = float4
1687−instance PGTyped schema 'PGfloat8 where pgtype = float8
1737+instance PGTyped schema (nullity 'PGfloat8) where pgtype = float8
1688−instance PGTyped schema 'PGtext where pgtype = text
1738+instance PGTyped schema (nullity 'PGtext) where pgtype = text
1689instance (KnownNat n, 1 <= n)
1739instance (KnownNat n, 1 <= n)
1690− => PGTyped schema ('PGchar n) where pgtype = char (Proxy @n)
1740+ => PGTyped schema (nullity ('PGchar n)) where pgtype = char @n
1691instance (KnownNat n, 1 <= n)
1741instance (KnownNat n, 1 <= n)
1692− => PGTyped schema ('PGvarchar n) where pgtype = varchar (Proxy @n)
1742+ => PGTyped schema (nullity ('PGvarchar n)) where pgtype = varchar @n
1693−instance PGTyped schema 'PGbytea where pgtype = bytea
1743+instance PGTyped schema (nullity 'PGbytea) where pgtype = bytea
1694−instance PGTyped schema 'PGtimestamp where pgtype = timestamp
1744+instance PGTyped schema (nullity 'PGtimestamp) where pgtype = timestamp
1695−instance PGTyped schema 'PGtimestamptz where pgtype = timestampWithTimeZone
1745+instance PGTyped schema (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1696−instance PGTyped schema 'PGdate where pgtype = date
1746+instance PGTyped schema (nullity 'PGdate) where pgtype = date
1697−instance PGTyped schema 'PGtime where pgtype = time
1747+instance PGTyped schema (nullity 'PGtime) where pgtype = time
1698−instance PGTyped schema 'PGtimetz where pgtype = timeWithTimeZone
1748+instance PGTyped schema (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1699−instance PGTyped schema 'PGinterval where pgtype = interval
1749+instance PGTyped schema (nullity 'PGinterval) where pgtype = interval
1700−instance PGTyped schema 'PGuuid where pgtype = uuid
1750+instance PGTyped schema (nullity 'PGuuid) where pgtype = uuid
1701−instance PGTyped schema 'PGjson where pgtype = json
1751+instance PGTyped schema (nullity 'PGjson) where pgtype = json
1702−instance PGTyped schema 'PGjsonb where pgtype = jsonb
1752+instance PGTyped schema (nullity 'PGjsonb) where pgtype = jsonb
1753+instance PGTyped schema ty
1703−instance PGTyped schema ty => PGTyped schema ('PGvararray ty) where
1754+ => PGTyped schema (nullity ('PGvararray ty)) where
1704− pgtype = vararray (pgtype @schema @ty)
1755+ pgtype = vararray (pgtype @schema @ty)
1705−instance (KnownNat n, PGTyped schema ty) => PGTyped schema ('PGfixarray n ty) where
1756+instance (KnownNat n, PGTyped schema ty)
1757+ => PGTyped schema (nullity ('PGfixarray n ty)) where
1706− pgtype = fixarray (Proxy @n) (pgtype @schema @ty)
1758+ pgtype = fixarray @n (pgtype @schema @ty)