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