on dev help sign in
work more thru
commitec70c9f331409ad044fd2d0f87c924bb7d2331aa authorEitan Chatav <eitan.chatav@gmail.com> dateFri 23 Nov 2018, 19:23 (8 years ago) parent371a13e
4 files changed+580−570
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+37−34 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+375−374 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+78−76 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+90−86
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+37−34
@@ -53,7 +53,7 @@ module Squeal.PostgreSQL.Definition
5353 , AlterTable (UnsafeAlterTable, renderAlterTable)
5454 , addConstraint
5555 , dropConstraint
56− , AddColumn (addColumn)
56+ -- , AddColumn (addColumn)
5757 , dropColumn
5858 , renameColumn
5959 , alterColumn
@@ -153,9 +153,9 @@ createTable
153153 , schema1 ~ Create table ('Table (constraints :=> columns)) schema0
154154 , db1 ~ Alter sch schema1 db0 )
155155 => QualifiedAlias sch tab -- ^ the name of the table to add
156− -> NP (Aliased (ColumnTypeExpression schema0)) columns
156+ -> NP (Aliased (ColumnTypeExpression db0)) columns
157157 -- ^ the names and datatype of each column
158− -> NP (Aliased (TableConstraintExpression schema1 table)) constraints
158+ -> NP (Aliased (TableConstraintExpression db1 table)) constraints
159159 -- ^ constraints that must hold for the table
160160 -> Definition db0 db1
161161createTable tab columns constraints = UnsafeDefinition $
@@ -189,9 +189,9 @@ createTableIfNotExists
189189 , SOP.SListI columns
190190 , SOP.SListI constraints )
191191 => QualifiedAlias sch tab -- ^ the name of the table to add
192− -> NP (Aliased (ColumnTypeExpression schema)) columns
192+ -> NP (Aliased (ColumnTypeExpression db)) columns
193193 -- ^ the names and datatype of each column
194− -> NP (Aliased (TableConstraintExpression schema table)) constraints
194+ -> NP (Aliased (TableConstraintExpression db table)) constraints
195195 -- ^ constraints that must hold for the table
196196 -> Definition db db
197197createTableIfNotExists tab columns constraints = UnsafeDefinition $
@@ -241,7 +241,7 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
241241-- violate a constraint, an error is raised. This applies
242242-- even if the value came from the default value definition.
243243newtype TableConstraintExpression
244− (schema :: SchemaType)
244+ (db :: DBType)
245245 (table :: Symbol)
246246 (tableConstraint :: TableConstraint)
247247 = UnsafeTableConstraintExpression
@@ -273,13 +273,13 @@ let
273273CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
274274-}
275275check
276− :: ( Has alias schema ('Table table)
276+ :: ( HasQualified sch tab db schema ('Table table)
277277 , HasAll aliases (TableToRow table) subcolumns )
278278 => NP Alias aliases
279279 -- ^ specify the subcolumns which are getting checked
280− -> (forall tab. Condition schema '[tab ::: subcolumns] 'Ungrouped '[])
280+ -> (forall t. Condition db '[t ::: subcolumns] 'Ungrouped '[])
281281 -- ^ a closed `Condition` on those subcolumns
282− -> TableConstraintExpression schema alias ('Check aliases)
282+ -> TableConstraintExpression db tab ('Check aliases)
283283check _cols condition = UnsafeTableConstraintExpression $
284284 "CHECK" <+> parenthesized (renderExpression condition)
285285
@@ -311,7 +311,7 @@ unique
311311 , HasAll aliases (TableToRow table) subcolumns )
312312 => NP Alias aliases
313313 -- ^ specify subcolumns which together are unique for each row
314− -> TableConstraintExpression schema alias ('Unique aliases)
314+ -> TableConstraintExpression db alias ('Unique aliases)
315315unique columns = UnsafeTableConstraintExpression $
316316 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
317317
@@ -345,7 +345,7 @@ primaryKey
345345 , AllNotNull subcolumns )
346346 => NP Alias aliases
347347 -- ^ specify the subcolumns which together form a primary key.
348− -> TableConstraintExpression schema alias ('PrimaryKey aliases)
348+ -> TableConstraintExpression db alias ('PrimaryKey aliases)
349349primaryKey columns = UnsafeTableConstraintExpression $
350350 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
351351
@@ -438,7 +438,7 @@ foreignKey
438438 -- ^ what to do when reference is deleted
439439 -> OnUpdateClause
440440 -- ^ what to do when reference is updated
441− -> TableConstraintExpression schema child
441+ -> TableConstraintExpression db child
442442 ('ForeignKey columns parent refcolumns)
443443foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
444444 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
@@ -529,7 +529,7 @@ ALTER statements
529529alterTable
530530 :: HasQualified sch tab db schema ('Table table0)
531531 => QualifiedAlias sch tab -- ^ table to alter
532− -> AlterTable tab table1 schema -- ^ alteration to perform
532+ -> AlterTable tab table1 db -- ^ alteration to perform
533533 -> Definition db (Alter sch (Alter tab ('Table table1) schema) db)
534534alterTable tab alteration = UnsafeDefinition $
535535 "ALTER TABLE"
@@ -553,9 +553,9 @@ alterTableRename table0 table1 = UnsafeDefinition $
553553-- | An `AlterTable` describes the alteration to perform on the columns
554554-- of a table.
555555newtype AlterTable
556− (alias :: Symbol)
556+ (tab :: Symbol)
557557 (table :: TableType)
558− (schema :: SchemaType) =
558+ (db :: DBType) =
559559 UnsafeAlterTable {renderAlterTable :: ByteString}
560560 deriving (GHC.Generic,Show,Eq,Ord,NFData)
561561
@@ -576,9 +576,9 @@ addConstraint
576576 , table0 ~ (constraints :=> columns)
577577 , table1 ~ (Create alias constraint constraints :=> columns) )
578578 => Alias alias
579− -> TableConstraintExpression schema tab constraint
579+ -> TableConstraintExpression db tab constraint
580580 -- ^ constraint to add
581− -> AlterTable tab table1 schema
581+ -> AlterTable tab table1 db
582582addConstraint alias constraint = UnsafeAlterTable $
583583 "ADD" <+> "CONSTRAINT" <+> renderAlias alias
584584 <+> renderTableConstraintExpression constraint
@@ -601,10 +601,11 @@ dropConstraint
601601 , table1 ~ (Drop constraint constraints :=> columns) )
602602 => Alias constraint
603603 -- ^ constraint to drop
604− -> AlterTable tab table1 schema
604+ -> AlterTable tab table1 db
605605dropConstraint constraint = UnsafeAlterTable $
606606 "DROP" <+> "CONSTRAINT" <+> renderAlias constraint
607607
608+{---------FIX ADD COLUMN
608609-- | An `AddColumn` is either @NULL@ or has @DEFAULT@.
609610class AddColumn ty where
610611 -- | `addColumn` adds a new column, initially filled with whatever
@@ -635,17 +636,19 @@ class AddColumn ty where
635636 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
636637 addColumn
637638 :: ( KnownSymbol column
638− , Has tab schema ('Table table0)
639+ , HasQualified sch tab db schema ('Table table0)
639640 , table0 ~ (constraints :=> columns)
640641 , table1 ~ (constraints :=> Create column ty columns) )
641642 => Alias column -- ^ column to add
642− -> ColumnTypeExpression schema ty -- ^ type of the new column
643− -> AlterTable tab table1 schema
643+ -> ColumnTypeExpression db ty -- ^ type of the new column
644+ -> AlterTable tab table1 db
644645 addColumn column ty = UnsafeAlterTable $
645646 "ADD COLUMN" <+> renderAlias column <+> renderColumnTypeExpression ty
646647instance {-# OVERLAPPING #-} AddColumn ('Def :=> ty)
647648instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
648649
650+-}
651+
649652-- | A `dropColumn` removes a column. Whatever data was in the column
650653-- disappears. Table constraints involving the column are dropped, too.
651654-- However, if the column is referenced by a foreign key constraint of
@@ -668,7 +671,7 @@ dropColumn
668671 , table0 ~ (constraints :=> columns)
669672 , table1 ~ (constraints :=> Drop column columns) )
670673 => Alias column -- ^ column to remove
671− -> AlterTable tab table1 schema
674+ -> AlterTable tab table1 db
672675dropColumn column = UnsafeAlterTable $
673676 "DROP COLUMN" <+> renderAlias column
674677
@@ -691,7 +694,7 @@ renameColumn
691694 , table1 ~ (constraints :=> Rename column0 column1 columns) )
692695 => Alias column0 -- ^ column to rename
693696 -> Alias column1 -- ^ what to rename the column
694− -> AlterTable tab table1 schema
697+ -> AlterTable tab table1 db
695698renameColumn column0 column1 = UnsafeAlterTable $
696699 "RENAME COLUMN" <+> renderAlias column0 <+> "TO" <+> renderAlias column1
697700
@@ -703,13 +706,13 @@ alterColumn
703706 , Has column columns ty0
704707 , tables1 ~ (constraints :=> Alter column ty1 columns))
705708 => Alias column -- ^ column to alter
706− -> AlterColumn schema ty0 ty1 -- ^ alteration to perform
707− -> AlterTable tab table1 schema
709+ -> AlterColumn db ty0 ty1 -- ^ alteration to perform
710+ -> AlterTable tab table1 db
708711alterColumn column alteration = UnsafeAlterTable $
709712 "ALTER COLUMN" <+> renderAlias column <+> renderAlterColumn alteration
710713
711714-- | An `AlterColumn` describes the alteration to perform on a single column.
712−newtype AlterColumn (schema :: SchemaType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
715+newtype AlterColumn (db :: DBType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
713716 UnsafeAlterColumn {renderAlterColumn :: ByteString}
714717 deriving (GHC.Generic,Show,Eq,Ord,NFData)
715718
@@ -811,7 +814,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
811814createView
812815 :: (KnownSymbol sch, KnownSymbol vw)
813816 => QualifiedAlias sch vw -- ^ the name of the view to add
814− -> Query schema '[] view
817+ -> Query db '[] view
815818 -- ^ query
816819 -> Definition db (Alter sch (Create vw ('View view) schema) db)
817820createView alias query = UnsafeDefinition $
@@ -892,7 +895,7 @@ createTypeComposite
892895 :: (KnownSymbol ty, Has sch db schema, SOP.SListI fields)
893896 => QualifiedAlias sch ty
894897 -- ^ name of the user defined composite type
895− -> NP (Aliased (TypeExpression schema)) fields
898+ -> NP (Aliased (TypeExpression db)) fields
896899 -- ^ list of attribute names and data types
897900 -> Definition db (Alter sch (Create ty ('Typedef ('PGcomposite fields)) schema) db)
898901createTypeComposite ty fields = UnsafeDefinition $
@@ -912,15 +915,15 @@ createTypeComposite ty fields = UnsafeDefinition $
912915-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
913916createTypeCompositeFrom
914917 :: forall hask sch ty db schema.
915− ( SOP.All (FieldTyped schema) (RowPG hask)
918+ ( SOP.All (FieldTyped db) (RowPG hask)
916919 , KnownSymbol ty
917920 , Has sch db schema )
918921 => QualifiedAlias sch ty
919922 -- ^ name of the user defined composite type
920923 -> Definition db (Alter sch (Create ty ( 'Typedef (PG (Composite hask))) schema) db)
921924createTypeCompositeFrom ty = createTypeComposite ty
922− (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped schema)) fieldtype
923− :: NP (Aliased (TypeExpression schema)) (RowPG hask))
925+ (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped db)) fieldtype
926+ :: NP (Aliased (TypeExpression db)) (RowPG hask))
924927
925928class FieldTyped schema ty where
926929 fieldtype :: Aliased (TypeExpression schema) ty
@@ -943,15 +946,15 @@ dropType
943946dropType tydef = UnsafeDefinition $ "DROP" <+> "TYPE" <+> renderQualifiedAlias tydef <> ";"
944947
945948-- | `ColumnTypeExpression`s are used in `createTable` commands.
946−newtype ColumnTypeExpression (schema :: SchemaType) (ty :: ColumnType)
949+newtype ColumnTypeExpression (db :: DBType) (ty :: ColumnType)
947950 = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
948951 deriving (GHC.Generic,Show,Eq,Ord,NFData)
949952
950953-- | used in `createTable` commands as a column constraint to note that
951954-- @NULL@ may be present in a column
952955nullable
953− :: TypeExpression schema (nullity ty)
954− -> ColumnTypeExpression schema ('NoDef :=> 'Null ty)
956+ :: TypeExpression db (nullity ty)
957+ -> ColumnTypeExpression db ('NoDef :=> 'Null ty)
955958nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
956959
957960-- | used in `createTable` commands as a column constraint to ensure
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+375−374
@@ -217,7 +217,7 @@ values from primitive expression using arithmetic, logical,
217217and other operations.
218218-}
219219newtype Expression
220− (schema :: SchemaType)
220+ (db :: DBType)
221221 (from :: FromType)
222222 (grouping :: Grouping)
223223 (params :: [NullityType])
@@ -225,7 +225,7 @@ newtype Expression
225225 = UnsafeExpression { renderExpression :: ByteString }
226226 deriving (GHC.Generic,Show,Eq,Ord,NFData)
227227
228−instance RenderSQL (Expression schema from grouping params ty) where
228+instance RenderSQL (Expression db from grouping params ty) where
229229 renderSQL = renderExpression
230230
231231{- | A `HasParameter` constraint is used to indicate a value that is
@@ -238,7 +238,7 @@ refer to the out-of-line data values.
238238-}
239239class KnownNat n => HasParameter
240240 (n :: Nat)
241− (schema :: SchemaType)
241+ (db :: DBType)
242242 (params :: [NullityType])
243243 (ty :: NullityType)
244244 | n params -> ty where
@@ -248,8 +248,8 @@ class KnownNat n => HasParameter
248248 -- >>> printSQL expr
249249 -- ($1 :: int4)
250250 parameter
251− :: TypeExpression schema ty
252− -> Expression schema from grouping params ty
251+ :: TypeExpression db ty
252+ -> Expression db from grouping params ty
253253 parameter ty = UnsafeExpression $ parenthesized $
254254 "$" <> renderNat @n <+> "::"
255255 <+> renderTypeExpression ty
@@ -264,34 +264,34 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
264264-- >>> printSQL expr
265265-- ($1 :: int4)
266266param
267− :: forall n schema params from grouping ty
268− . (PGTyped schema ty, HasParameter n schema params ty)
269− => Expression schema from grouping params ty -- ^ param
267+ :: forall n db params from grouping ty
268+ . (PGTyped db ty, HasParameter n db params ty)
269+ => Expression db from grouping params ty -- ^ param
270270param = parameter @n pgtype
271271
272272instance (HasUnique table from columns, Has column columns ty)
273− => IsLabel column (Expression schema from 'Ungrouped params ty) where
273+ => IsLabel column (Expression db from 'Ungrouped params ty) where
274274 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
275275instance (HasUnique table from columns, Has column columns ty)
276276 => IsLabel column
277− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
277+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
278278 fromLabel = fromLabel @column `As` Alias @column
279279instance (HasUnique table from columns, Has column columns ty)
280280 => IsLabel column
281− (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
281+ (NP (Aliased (Expression db from 'Ungrouped params)) '[column ::: ty]) where
282282 fromLabel = fromLabel @column :* Nil
283283
284284instance (Has table from columns, Has column columns ty)
285− => IsQualified table column (Expression schema from 'Ungrouped params ty) where
285+ => IsQualified table column (Expression db from 'Ungrouped params ty) where
286286 table ! column = UnsafeExpression $
287287 renderAlias table <> "." <> renderAlias column
288288instance (Has table from columns, Has column columns ty)
289289 => IsQualified table column
290− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
290+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
291291 table ! column = table ! column `As` column
292292instance (Has table from columns, Has column columns ty)
293293 => IsQualified table column
294− (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
294+ (NP (Aliased (Expression db from 'Ungrouped params)) '[column ::: ty]) where
295295 table ! column = table ! column :* Nil
296296
297297instance
@@ -299,14 +299,14 @@ instance
299299 , Has column columns ty
300300 , GroupedBy table column bys
301301 ) => IsLabel column
302− (Expression schema from ('Grouped bys) params ty) where
302+ (Expression db from ('Grouped bys) params ty) where
303303 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
304304instance
305305 ( HasUnique table from columns
306306 , Has column columns ty
307307 , GroupedBy table column bys
308308 ) => IsLabel column
309− ( Aliased (Expression schema from ('Grouped bys) params)
309+ ( Aliased (Expression db from ('Grouped bys) params)
310310 (column ::: ty) ) where
311311 fromLabel = fromLabel @column `As` Alias @column
312312instance
@@ -314,7 +314,7 @@ instance
314314 , Has column columns ty
315315 , GroupedBy table column bys
316316 ) => IsLabel column
317− ( NP (Aliased (Expression schema from ('Grouped bys) params))
317+ ( NP (Aliased (Expression db from ('Grouped bys) params))
318318 '[column ::: ty] ) where
319319 fromLabel = fromLabel @column :* Nil
320320
@@ -323,7 +323,7 @@ instance
323323 , Has column columns ty
324324 , GroupedBy table column bys
325325 ) => IsQualified table column
326− (Expression schema from ('Grouped bys) params ty) where
326+ (Expression db from ('Grouped bys) params ty) where
327327 table ! column = UnsafeExpression $
328328 renderAlias table <> "." <> renderAlias column
329329instance
@@ -331,7 +331,7 @@ instance
331331 , Has column columns ty
332332 , GroupedBy table column bys
333333 ) => IsQualified table column
334− (Aliased (Expression schema from ('Grouped bys) params)
334+ (Aliased (Expression db from ('Grouped bys) params)
335335 (column ::: ty)) where
336336 table ! column = table ! column `As` column
337337instance
@@ -339,7 +339,7 @@ instance
339339 , Has column columns ty
340340 , GroupedBy table column bys
341341 ) => IsQualified table column
342− ( NP (Aliased (Expression schema from ('Grouped bys) params))
342+ ( NP (Aliased (Expression db from ('Grouped bys) params))
343343 '[column ::: ty]) where
344344 table ! column = table ! column :* Nil
345345
@@ -347,7 +347,7 @@ instance
347347--
348348-- >>> printSQL null_
349349-- NULL
350−null_ :: Expression schema rels grouping params ('Null ty)
350+null_ :: Expression db rels grouping params ('Null ty)
351351null_ = UnsafeExpression "NULL"
352352
353353-- | analagous to `Just`
@@ -355,8 +355,8 @@ null_ = UnsafeExpression "NULL"
355355-- >>> printSQL $ notNull true
356356-- TRUE
357357notNull
358− :: Expression schema rels grouping params ('NotNull ty)
359− -> Expression schema rels grouping params ('Null ty)
358+ :: Expression db rels grouping params ('NotNull ty)
359+ -> Expression db rels grouping params ('Null ty)
360360notNull = UnsafeExpression . renderExpression
361361
362362-- | return the leftmost value which is not NULL
@@ -364,11 +364,11 @@ notNull = UnsafeExpression . renderExpression
364364-- >>> printSQL $ coalesce [null_, true] false
365365-- COALESCE(NULL, TRUE, FALSE)
366366coalesce
367− :: [Expression schema from grouping params ('Null ty)]
367+ :: [Expression db from grouping params ('Null ty)]
368368 -- ^ @NULL@s may be present
369− -> Expression schema from grouping params ('NotNull ty)
369+ -> Expression db from grouping params ('NotNull ty)
370370 -- ^ @NULL@ is absent
371− -> Expression schema from grouping params ('NotNull ty)
371+ -> Expression db from grouping params ('NotNull ty)
372372coalesce nullxs notNullx = UnsafeExpression $
373373 "COALESCE" <> parenthesized (commaSeparated
374374 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -378,26 +378,26 @@ coalesce nullxs notNullx = UnsafeExpression $
378378-- >>> printSQL $ fromNull true null_
379379-- COALESCE(NULL, TRUE)
380380fromNull
381− :: Expression schema from grouping params ('NotNull ty)
381+ :: Expression db from grouping params ('NotNull ty)
382382 -- ^ what to convert @NULL@ to
383− -> Expression schema from grouping params ('Null ty)
384− -> Expression schema from grouping params ('NotNull ty)
383+ -> Expression db from grouping params ('Null ty)
384+ -> Expression db from grouping params ('NotNull ty)
385385fromNull notNullx nullx = coalesce [nullx] notNullx
386386
387387-- | >>> printSQL $ null_ & isNull
388388-- NULL IS NULL
389389isNull
390− :: Expression schema from grouping params ('Null ty)
390+ :: Expression db from grouping params ('Null ty)
391391 -- ^ possibly @NULL@
392− -> Condition schema from grouping params
392+ -> Condition db from grouping params
393393isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
394394
395395-- | >>> printSQL $ null_ & isNotNull
396396-- NULL IS NOT NULL
397397isNotNull
398− :: Expression schema from grouping params ('Null ty)
398+ :: Expression db from grouping params ('Null ty)
399399 -- ^ possibly @NULL@
400− -> Condition schema from grouping params
400+ -> Condition db from grouping params
401401isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
402402
403403-- | analagous to `maybe` using @IS NULL@
@@ -405,13 +405,13 @@ isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
405405-- >>> printSQL $ matchNull true not_ null_
406406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407407matchNull
408− :: Expression schema from grouping params (nullty)
408+ :: Expression db from grouping params (nullty)
409409 -- ^ what to convert @NULL@ to
410− -> ( Expression schema from grouping params ('NotNull ty)
411− -> Expression schema from grouping params (nullty) )
410+ -> ( Expression db from grouping params ('NotNull ty)
411+ -> Expression db from grouping params (nullty) )
412412 -- ^ function to perform when @NULL@ is absent
413− -> Expression schema from grouping params ('Null ty)
414− -> Expression schema from grouping params (nullty)
413+ -> Expression db from grouping params ('Null ty)
414+ -> Expression db from grouping params (nullty)
415415matchNull y f x = ifThenElse (isNull x) y
416416 (f (UnsafeExpression (renderExpression x)))
417417
@@ -419,25 +419,25 @@ matchNull y f x = ifThenElse (isNull x) y
419419`nullIf` gives @NULL@.
420420
421421>>> :set -XTypeApplications -XDataKinds
422−>>> let expr = nullIf false (param @1) :: Expression schema rels grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
422+>>> let expr = nullIf false (param @1) :: Expression db rels grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
423423>>> printSQL expr
424424NULL IF (FALSE, ($1 :: bool))
425425-}
426426nullIf
427− :: Expression schema from grouping params ('NotNull ty)
427+ :: Expression db from grouping params ('NotNull ty)
428428 -- ^ @NULL@ is absent
429− -> Expression schema from grouping params ('NotNull ty)
429+ -> Expression db from grouping params ('NotNull ty)
430430 -- ^ @NULL@ is absent
431− -> Expression schema from grouping params ('Null ty)
431+ -> Expression db from grouping params ('Null ty)
432432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
433433 (renderExpression x <> ", " <> renderExpression y)
434434
435435-- | >>> printSQL $ array [null_, false, true]
436436-- ARRAY[NULL, FALSE, TRUE]
437437array
438− :: [Expression schema from grouping params ty]
438+ :: [Expression db from grouping params ty]
439439 -- ^ array elements
440− -> Expression schema from grouping params (nullity ('PGvararray ty))
440+ -> Expression db from grouping params (nullity ('PGvararray ty))
441441array xs = UnsafeExpression $
442442 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
443443
@@ -445,13 +445,13 @@ array xs = UnsafeExpression $
445445-- (ARRAY[NULL, FALSE, TRUE])[2]
446446index
447447 :: Word64 -- ^ index
448− -> Expression schema from grouping params (nullity ('PGvararray ty)) -- ^ array
449− -> Expression schema from grouping params (NullifyType ty)
448+ -> Expression db from grouping params (nullity ('PGvararray ty)) -- ^ array
449+ -> Expression db from grouping params (NullifyType ty)
450450index n expr = UnsafeExpression $
451451 parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
452452
453453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
454− (Expression schema from grouping params (nullity ('PGenum labels))) where
454+ (Expression db from grouping params (nullity ('PGenum labels))) where
455455 label = UnsafeExpression $ renderLabel (PGlabel @label)
456456
457457-- | A row constructor is an expression that builds a row value
@@ -468,9 +468,9 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
468468-- ROW(0, 1)
469469row
470470 :: SListI row
471− => NP (Aliased (Expression schema from grouping params)) row
471+ => NP (Aliased (Expression db from grouping params)) row
472472 -- ^ zero or more expressions for the row field values
473− -> Expression schema from grouping params (nullity ('PGcomposite row))
473+ -> Expression db from grouping params (nullity ('PGcomposite row))
474474row exprs = UnsafeExpression $ "ROW" <> parenthesized
475475 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
476476
@@ -484,21 +484,22 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
484484-- >>> printSQL $ i & field #complex #imaginary
485485-- (ROW(0, 1)::"complex")."imaginary"
486486field
487− :: (Has tydef schema ('Typedef ('PGcomposite row)), Has field row ty)
488− => Alias tydef -- ^ row type
487+ :: ( HasQualified sch tydef db schema ('Typedef ('PGcomposite row))
488+ , Has field row ty)
489+ => QualifiedAlias sch tydef -- ^ row type
489490 -> Alias field -- ^ field name
490− -> Expression schema from grouping params ('NotNull ('PGcomposite row))
491− -> Expression schema from grouping params ty
491+ -> Expression db from grouping params ('NotNull ('PGcomposite row))
492+ -> Expression db from grouping params ty
492493field td fld expr = UnsafeExpression $
493− parenthesized (renderExpression expr <> "::" <> renderAlias td)
494+ parenthesized (renderExpression expr <> "::" <> renderQualifiedAlias td)
494495 <> "." <> renderAlias fld
495496
496497instance Semigroup
497− (Expression schema from grouping params (nullity ('PGvararray ty))) where
498+ (Expression db from grouping params (nullity ('PGvararray ty))) where
498499 (<>) = unsafeBinaryOp "||"
499500
500501instance Monoid
501− (Expression schema from grouping params (nullity ('PGvararray ty))) where
502+ (Expression db from grouping params (nullity ('PGvararray ty))) where
502503 mempty = array []
503504 mappend = (<>)
504505
@@ -506,22 +507,22 @@ instance Monoid
506507-- >>> printSQL expr
507508-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
508509greatest
509− :: Expression schema from grouping params (nullty)
510+ :: Expression db from grouping params (nullty)
510511 -- ^ needs at least 1 argument
511− -> [Expression schema from grouping params (nullty)]
512+ -> [Expression db from grouping params (nullty)]
512513 -- ^ or more
513− -> Expression schema from grouping params (nullty)
514+ -> Expression db from grouping params (nullty)
514515greatest x xs = UnsafeExpression $ "GREATEST("
515516 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
516517
517518-- | >>> printSQL $ least currentTimestamp [null_]
518519-- LEAST(CURRENT_TIMESTAMP, NULL)
519520least
520− :: Expression schema from grouping params (nullty)
521+ :: Expression db from grouping params (nullty)
521522 -- ^ needs at least 1 argument
522− -> [Expression schema from grouping params (nullty)]
523+ -> [Expression db from grouping params (nullty)]
523524 -- ^ or more
524− -> Expression schema from grouping params (nullty)
525+ -> Expression db from grouping params (nullty)
525526least x xs = UnsafeExpression $ "LEAST("
526527 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
527528
@@ -530,9 +531,9 @@ least x xs = UnsafeExpression $ "LEAST("
530531unsafeBinaryOp
531532 :: ByteString
532533 -- ^ operator
533− -> Expression schema from grouping params (ty0)
534− -> Expression schema from grouping params (ty1)
535− -> Expression schema from grouping params (ty2)
534+ -> Expression db from grouping params (ty0)
535+ -> Expression db from grouping params (ty1)
536+ -> Expression db from grouping params (ty2)
536537unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
537538 renderExpression x <+> op <+> renderExpression y
538539
@@ -541,8 +542,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
541542unsafeUnaryOp
542543 :: ByteString
543544 -- ^ operator
544− -> Expression schema from grouping params (ty0)
545− -> Expression schema from grouping params (ty1)
545+ -> Expression db from grouping params (ty0)
546+ -> Expression db from grouping params (ty1)
546547unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
547548 op <+> renderExpression x
548549
@@ -551,8 +552,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
551552unsafeFunction
552553 :: ByteString
553554 -- ^ function
554− -> Expression schema from grouping params (xty)
555− -> Expression schema from grouping params (yty)
555+ -> Expression db from grouping params (xty)
556+ -> Expression db from grouping params (yty)
556557unsafeFunction fun x = UnsafeExpression $
557558 fun <> parenthesized (renderExpression x)
558559
@@ -561,13 +562,13 @@ unsafeVariadicFunction
561562 :: SListI elems
562563 => ByteString
563564 -- ^ function
564− -> NP (Expression schema from grouping params) elems
565− -> Expression schema from grouping params ret
565+ -> NP (Expression db from grouping params) elems
566+ -> Expression db from grouping params ret
566567unsafeVariadicFunction fun x = UnsafeExpression $
567568 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
568569
569570instance ty `In` PGNum
570− => Num (Expression schema from grouping params (nullity ty)) where
571+ => Num (Expression db from grouping params (nullity ty)) where
571572 (+) = unsafeBinaryOp "+"
572573 (-) = unsafeBinaryOp "-"
573574 (*) = unsafeBinaryOp "*"
@@ -579,12 +580,12 @@ instance ty `In` PGNum
579580 . show
580581
581582instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
582− (Expression schema from grouping params (nullity ty)) where
583+ (Expression db from grouping params (nullity ty)) where
583584 (/) = unsafeBinaryOp "/"
584585 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
585586
586587instance (ty `In` PGNum, ty `In` PGFloating) => Floating
587− (Expression schema from grouping params (nullity ty)) where
588+ (Expression db from grouping params (nullity ty)) where
588589 pi = UnsafeExpression "pi()"
589590 exp = unsafeFunction "exp"
590591 log = unsafeFunction "ln"
@@ -607,18 +608,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
607608
608609-- | >>> :{
609610-- let
610−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
611+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
611612-- expression = atan2_ pi 2
612613-- in printSQL expression
613614-- :}
614615-- atan2(pi(), 2)
615616atan2_
616617 :: float `In` PGFloating
617− => Expression schema from grouping params (nullity float)
618+ => Expression db from grouping params (nullity float)
618619 -- ^ numerator
619− -> Expression schema from grouping params (nullity float)
620+ -> Expression db from grouping params (nullity float)
620621 -- ^ denominator
621− -> Expression schema from grouping params (nullity float)
622+ -> Expression db from grouping params (nullity float)
622623atan2_ y x = UnsafeExpression $
623624 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
624625
@@ -629,11 +630,11 @@ atan2_ y x = UnsafeExpression $
629630-- | >>> printSQL $ true & cast int4
630631-- (TRUE :: int4)
631632cast
632− :: TypeExpression schema ty1
633+ :: TypeExpression db ty1
633634 -- ^ type to cast as
634− -> Expression schema from grouping params ty0
635+ -> Expression db from grouping params ty0
635636 -- ^ value to convert
636− -> Expression schema from grouping params ty1
637+ -> Expression db from grouping params ty1
637638cast ty x = UnsafeExpression $ parenthesized $
638639 renderExpression x <+> "::" <+> renderTypeExpression ty
639640
@@ -641,136 +642,136 @@ cast ty x = UnsafeExpression $ parenthesized $
641642--
642643-- >>> :{
643644-- let
644−-- expression :: Expression schema from grouping params (nullity 'PGint2)
645+-- expression :: Expression db from grouping params (nullity 'PGint2)
645646-- expression = 5 `quot_` 2
646647-- in printSQL expression
647648-- :}
648649-- (5 / 2)
649650quot_
650651 :: int `In` PGIntegral
651− => Expression schema from grouping params (nullity int)
652+ => Expression db from grouping params (nullity int)
652653 -- ^ numerator
653− -> Expression schema from grouping params (nullity int)
654+ -> Expression db from grouping params (nullity int)
654655 -- ^ denominator
655− -> Expression schema from grouping params (nullity int)
656+ -> Expression db from grouping params (nullity int)
656657quot_ = unsafeBinaryOp "/"
657658
658659-- | remainder upon integer division
659660--
660661-- >>> :{
661662-- let
662−-- expression :: Expression schema from grouping params (nullity 'PGint2)
663+-- expression :: Expression db from grouping params (nullity 'PGint2)
663664-- expression = 5 `rem_` 2
664665-- in printSQL expression
665666-- :}
666667-- (5 % 2)
667668rem_
668669 :: int `In` PGIntegral
669− => Expression schema from grouping params (nullity int)
670+ => Expression db from grouping params (nullity int)
670671 -- ^ numerator
671− -> Expression schema from grouping params (nullity int)
672+ -> Expression db from grouping params (nullity int)
672673 -- ^ denominator
673− -> Expression schema from grouping params (nullity int)
674+ -> Expression db from grouping params (nullity int)
674675rem_ = unsafeBinaryOp "%"
675676
676677-- | >>> :{
677678-- let
678−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
679+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
679680-- expression = trunc pi
680681-- in printSQL expression
681682-- :}
682683-- trunc(pi())
683684trunc
684685 :: frac `In` PGFloating
685− => Expression schema from grouping params (nullity frac)
686+ => Expression db from grouping params (nullity frac)
686687 -- ^ fractional number
687− -> Expression schema from grouping params (nullity frac)
688+ -> Expression db from grouping params (nullity frac)
688689trunc = unsafeFunction "trunc"
689690
690691-- | >>> :{
691692-- let
692−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
693+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
693694-- expression = round_ pi
694695-- in printSQL expression
695696-- :}
696697-- round(pi())
697698round_
698699 :: frac `In` PGFloating
699− => Expression schema from grouping params (nullity frac)
700+ => Expression db from grouping params (nullity frac)
700701 -- ^ fractional number
701− -> Expression schema from grouping params (nullity frac)
702+ -> Expression db from grouping params (nullity frac)
702703round_ = unsafeFunction "round"
703704
704705-- | >>> :{
705706-- let
706−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
707+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
707708-- expression = ceiling_ pi
708709-- in printSQL expression
709710-- :}
710711-- ceiling(pi())
711712ceiling_
712713 :: frac `In` PGFloating
713− => Expression schema from grouping params (nullity frac)
714+ => Expression db from grouping params (nullity frac)
714715 -- ^ fractional number
715− -> Expression schema from grouping params (nullity frac)
716+ -> Expression db from grouping params (nullity frac)
716717ceiling_ = unsafeFunction "ceiling"
717718
718719-- | A `Condition` is an `Expression`, which can evaluate
719720-- to `true`, `false` or `null_`. This is because SQL uses
720721-- a three valued logic.
721−type Condition schema from grouping params =
722− Expression schema from grouping params ('Null 'PGbool)
722+type Condition db from grouping params =
723+ Expression db from grouping params ('Null 'PGbool)
723724
724725-- | >>> printSQL true
725726-- TRUE
726−true :: Expression schema from grouping params (nullity 'PGbool)
727+true :: Expression db from grouping params (nullity 'PGbool)
727728true = UnsafeExpression "TRUE"
728729
729730-- | >>> printSQL false
730731-- FALSE
731−false :: Expression schema from grouping params (nullity 'PGbool)
732+false :: Expression db from grouping params (nullity 'PGbool)
732733false = UnsafeExpression "FALSE"
733734
734735-- | >>> printSQL $ not_ true
735736-- (NOT TRUE)
736737not_
737− :: Expression schema from grouping params (nullity 'PGbool)
738− -> Expression schema from grouping params (nullity 'PGbool)
738+ :: Expression db from grouping params (nullity 'PGbool)
739+ -> Expression db from grouping params (nullity 'PGbool)
739740not_ = unsafeUnaryOp "NOT"
740741
741742-- | >>> printSQL $ true .&& false
742743-- (TRUE AND FALSE)
743744(.&&)
744− :: Expression schema from grouping params (nullity 'PGbool)
745− -> Expression schema from grouping params (nullity 'PGbool)
746− -> Expression schema from grouping params (nullity 'PGbool)
745+ :: Expression db from grouping params (nullity 'PGbool)
746+ -> Expression db from grouping params (nullity 'PGbool)
747+ -> Expression db from grouping params (nullity 'PGbool)
747748infixr 3 .&&
748749(.&&) = unsafeBinaryOp "AND"
749750
750751-- | >>> printSQL $ true .|| false
751752-- (TRUE OR FALSE)
752753(.||)
753− :: Expression schema from grouping params (nullity 'PGbool)
754− -> Expression schema from grouping params (nullity 'PGbool)
755− -> Expression schema from grouping params (nullity 'PGbool)
754+ :: Expression db from grouping params (nullity 'PGbool)
755+ -> Expression db from grouping params (nullity 'PGbool)
756+ -> Expression db from grouping params (nullity 'PGbool)
756757infixr 2 .||
757758(.||) = unsafeBinaryOp "OR"
758759
759760-- | >>> :{
760761-- let
761−-- expression :: Expression schema from grouping params (nullity 'PGint2)
762+-- expression :: Expression db from grouping params (nullity 'PGint2)
762763-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
763764-- in printSQL expression
764765-- :}
765766-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
766767caseWhenThenElse
767− :: [ ( Condition schema from grouping params
768− , Expression schema from grouping params ty
768+ :: [ ( Condition db from grouping params
769+ , Expression db from grouping params ty
769770 ) ]
770771 -- ^ whens and thens
771− -> Expression schema from grouping params ty
772+ -> Expression db from grouping params ty
772773 -- ^ else
773− -> Expression schema from grouping params ty
774+ -> Expression db from grouping params ty
774775caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
775776 [ "CASE"
776777 , mconcat
@@ -786,16 +787,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
786787
787788-- | >>> :{
788789-- let
789−-- expression :: Expression schema from grouping params (nullity 'PGint2)
790+-- expression :: Expression db from grouping params (nullity 'PGint2)
790791-- expression = ifThenElse true 1 0
791792-- in printSQL expression
792793-- :}
793794-- CASE WHEN TRUE THEN 1 ELSE 0 END
794795ifThenElse
795− :: Condition schema from grouping params
796− -> Expression schema from grouping params ty -- ^ then
797− -> Expression schema from grouping params ty -- ^ else
798− -> Expression schema from grouping params ty
796+ :: Condition db from grouping params
797+ -> Expression db from grouping params ty -- ^ then
798+ -> Expression db from grouping params ty -- ^ else
799+ -> Expression db from grouping params ty
799800ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
800801
801802-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -804,85 +805,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
804805-- >>> printSQL $ true .== null_
805806-- (TRUE = NULL)
806807(.==)
807− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
808− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
809− -> Condition schema from grouping params
808+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
809+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
810+ -> Condition db from grouping params
810811(.==) = unsafeBinaryOp "="
811812infix 4 .==
812813
813814-- | >>> printSQL $ true ./= null_
814815-- (TRUE <> NULL)
815816(./=)
816− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
817− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
818− -> Condition schema from grouping params
817+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
818+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
819+ -> Condition db from grouping params
819820(./=) = unsafeBinaryOp "<>"
820821infix 4 ./=
821822
822823-- | >>> printSQL $ true .>= null_
823824-- (TRUE >= NULL)
824825(.>=)
825− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
826− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
827− -> Condition schema from grouping params
826+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
827+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
828+ -> Condition db from grouping params
828829(.>=) = unsafeBinaryOp ">="
829830infix 4 .>=
830831
831832-- | >>> printSQL $ true .< null_
832833-- (TRUE < NULL)
833834(.<)
834− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
835− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
836− -> Condition schema from grouping params
835+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
836+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
837+ -> Condition db from grouping params
837838(.<) = unsafeBinaryOp "<"
838839infix 4 .<
839840
840841-- | >>> printSQL $ true .<= null_
841842-- (TRUE <= NULL)
842843(.<=)
843− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
844− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
845− -> Condition schema from grouping params
844+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
845+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
846+ -> Condition db from grouping params
846847(.<=) = unsafeBinaryOp "<="
847848infix 4 .<=
848849
849850-- | >>> printSQL $ true .> null_
850851-- (TRUE > NULL)
851852(.>)
852− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
853− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
854− -> Condition schema from grouping params
853+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
854+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
855+ -> Condition db from grouping params
855856(.>) = unsafeBinaryOp ">"
856857infix 4 .>
857858
858859-- | >>> printSQL currentDate
859860-- CURRENT_DATE
860861currentDate
861− :: Expression schema from grouping params (nullity 'PGdate)
862+ :: Expression db from grouping params (nullity 'PGdate)
862863currentDate = UnsafeExpression "CURRENT_DATE"
863864
864865-- | >>> printSQL currentTime
865866-- CURRENT_TIME
866867currentTime
867− :: Expression schema from grouping params (nullity 'PGtimetz)
868+ :: Expression db from grouping params (nullity 'PGtimetz)
868869currentTime = UnsafeExpression "CURRENT_TIME"
869870
870871-- | >>> printSQL currentTimestamp
871872-- CURRENT_TIMESTAMP
872873currentTimestamp
873− :: Expression schema from grouping params (nullity 'PGtimestamptz)
874+ :: Expression db from grouping params (nullity 'PGtimestamptz)
874875currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
875876
876877-- | >>> printSQL localTime
877878-- LOCALTIME
878879localTime
879− :: Expression schema from grouping params (nullity 'PGtime)
880+ :: Expression db from grouping params (nullity 'PGtime)
880881localTime = UnsafeExpression "LOCALTIME"
881882
882883-- | >>> printSQL localTimestamp
883884-- LOCALTIMESTAMP
884885localTimestamp
885− :: Expression schema from grouping params (nullity 'PGtimestamp)
886+ :: Expression db from grouping params (nullity 'PGtimestamp)
886887localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
887888
888889{-----------------------------------------
@@ -890,7 +891,7 @@ text
890891-----------------------------------------}
891892
892893instance IsString
893− (Expression schema from grouping params (nullity 'PGtext)) where
894+ (Expression db from grouping params (nullity 'PGtext)) where
894895 fromString str = UnsafeExpression $
895896 "E\'" <> fromString (escape =<< str) <> "\'"
896897 where
@@ -906,36 +907,36 @@ instance IsString
906907 c -> [c]
907908
908909instance Semigroup
909− (Expression schema from grouping params (nullity 'PGtext)) where
910+ (Expression db from grouping params (nullity 'PGtext)) where
910911 (<>) = unsafeBinaryOp "||"
911912
912913instance Monoid
913− (Expression schema from grouping params (nullity 'PGtext)) where
914+ (Expression db from grouping params (nullity 'PGtext)) where
914915 mempty = fromString ""
915916 mappend = (<>)
916917
917918-- | >>> printSQL $ lower "ARRRGGG"
918919-- lower(E'ARRRGGG')
919920lower
920− :: Expression schema from grouping params (nullity 'PGtext)
921+ :: Expression db from grouping params (nullity 'PGtext)
921922 -- ^ string to lower case
922− -> Expression schema from grouping params (nullity 'PGtext)
923+ -> Expression db from grouping params (nullity 'PGtext)
923924lower = unsafeFunction "lower"
924925
925926-- | >>> printSQL $ upper "eeee"
926927-- upper(E'eeee')
927928upper
928− :: Expression schema from grouping params (nullity 'PGtext)
929+ :: Expression db from grouping params (nullity 'PGtext)
929930 -- ^ string to upper case
930− -> Expression schema from grouping params (nullity 'PGtext)
931+ -> Expression db from grouping params (nullity 'PGtext)
931932upper = unsafeFunction "upper"
932933
933934-- | >>> printSQL $ charLength "four"
934935-- char_length(E'four')
935936charLength
936− :: Expression schema from grouping params (nullity 'PGtext)
937+ :: Expression db from grouping params (nullity 'PGtext)
937938 -- ^ string to measure
938− -> Expression schema from grouping params (nullity 'PGint4)
939+ -> Expression db from grouping params (nullity 'PGint4)
939940charLength = unsafeFunction "char_length"
940941
941942-- | The `like` expression returns true if the @string@ matches
@@ -948,11 +949,11 @@ charLength = unsafeFunction "char_length"
948949-- >>> printSQL $ "abc" `like` "a%"
949950-- (E'abc' LIKE E'a%')
950951like
951− :: Expression schema from grouping params (nullity 'PGtext)
952+ :: Expression db from grouping params (nullity 'PGtext)
952953 -- ^ string
953− -> Expression schema from grouping params (nullity 'PGtext)
954+ -> Expression db from grouping params (nullity 'PGtext)
954955 -- ^ pattern
955− -> Expression schema from grouping params (nullity 'PGbool)
956+ -> Expression db from grouping params (nullity 'PGbool)
956957like = unsafeBinaryOp "LIKE"
957958
958959{-----------------------------------------
@@ -967,36 +968,36 @@ Table 9.44: json and jsonb operators
967968-- | Get JSON value (object field or array element) at a key.
968969(.->)
969970 :: (json `In` PGJsonType, key `In` PGJsonKey)
970− => Expression schema from grouping params (nullity json)
971− -> Expression schema from grouping params (nullity key)
972− -> Expression schema from grouping params ('Null json)
971+ => Expression db from grouping params (nullity json)
972+ -> Expression db from grouping params (nullity key)
973+ -> Expression db from grouping params ('Null json)
973974infixl 8 .->
974975(.->) = unsafeBinaryOp "->"
975976
976977-- | Get JSON value (object field or array element) at a key, as text.
977978(.->>)
978979 :: (json `In` PGJsonType, key `In` PGJsonKey)
979− => Expression schema from grouping params (nullity json)
980− -> Expression schema from grouping params (nullity key)
981− -> Expression schema from grouping params ('Null 'PGtext)
980+ => Expression db from grouping params (nullity json)
981+ -> Expression db from grouping params (nullity key)
982+ -> Expression db from grouping params ('Null 'PGtext)
982983infixl 8 .->>
983984(.->>) = unsafeBinaryOp "->>"
984985
985986-- | Get JSON value at a specified path.
986987(.#>)
987988 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
988− => Expression schema from grouping params (nullity json)
989− -> Expression schema from grouping params (nullity path)
990− -> Expression schema from grouping params ('Null json)
989+ => Expression db from grouping params (nullity json)
990+ -> Expression db from grouping params (nullity path)
991+ -> Expression db from grouping params ('Null json)
991992infixl 8 .#>
992993(.#>) = unsafeBinaryOp "#>"
993994
994995-- | Get JSON value at a specified path as text.
995996(.#>>)
996997 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
997− => Expression schema from grouping params (nullity json)
998− -> Expression schema from grouping params (nullity path)
999− -> Expression schema from grouping params ('Null 'PGtext)
998+ => Expression db from grouping params (nullity json)
999+ -> Expression db from grouping params (nullity path)
1000+ -> Expression db from grouping params ('Null 'PGtext)
10001001infixl 8 .#>>
10011002(.#>>) = unsafeBinaryOp "#>>"
10021003
@@ -1005,48 +1006,48 @@ infixl 8 .#>>
10051006-- | Does the left JSON value contain the right JSON path/value entries at the
10061007-- top level?
10071008(.@>)
1008− :: Expression schema from grouping params (nullity 'PGjsonb)
1009− -> Expression schema from grouping params (nullity 'PGjsonb)
1010− -> Condition schema from grouping params
1009+ :: Expression db from grouping params (nullity 'PGjsonb)
1010+ -> Expression db from grouping params (nullity 'PGjsonb)
1011+ -> Condition db from grouping params
10111012infixl 9 .@>
10121013(.@>) = unsafeBinaryOp "@>"
10131014
10141015-- | Are the left JSON path/value entries contained at the top level within the
10151016-- right JSON value?
10161017(.<@)
1017− :: Expression schema from grouping params (nullity 'PGjsonb)
1018− -> Expression schema from grouping params (nullity 'PGjsonb)
1019− -> Condition schema from grouping params
1018+ :: Expression db from grouping params (nullity 'PGjsonb)
1019+ -> Expression db from grouping params (nullity 'PGjsonb)
1020+ -> Condition db from grouping params
10201021infixl 9 .<@
10211022(.<@) = unsafeBinaryOp "<@"
10221023
10231024-- | Does the string exist as a top-level key within the JSON value?
10241025(.?)
1025− :: Expression schema from grouping params (nullity 'PGjsonb)
1026− -> Expression schema from grouping params (nullity 'PGtext)
1027− -> Condition schema from grouping params
1026+ :: Expression db from grouping params (nullity 'PGjsonb)
1027+ -> Expression db from grouping params (nullity 'PGtext)
1028+ -> Condition db from grouping params
10281029infixl 9 .?
10291030(.?) = unsafeBinaryOp "?"
10301031
10311032-- | Do any of these array strings exist as top-level keys?
10321033(.?|)
1033− :: Expression schema from grouping params (nullity 'PGjsonb)
1034− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1035− -> Condition schema from grouping params
1034+ :: Expression db from grouping params (nullity 'PGjsonb)
1035+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1036+ -> Condition db from grouping params
10361037infixl 9 .?|
10371038(.?|) = unsafeBinaryOp "?|"
10381039
10391040-- | Do all of these array strings exist as top-level keys?
10401041(.?&)
1041− :: Expression schema from grouping params (nullity 'PGjsonb)
1042− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1043− -> Condition schema from grouping params
1042+ :: Expression db from grouping params (nullity 'PGjsonb)
1043+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1044+ -> Condition db from grouping params
10441045infixl 9 .?&
10451046(.?&) = unsafeBinaryOp "?&"
10461047
10471048-- | Concatenate two jsonb values into a new jsonb value.
10481049instance
1049− Semigroup (Expression schema from grouping param (nullity 'PGjsonb)) where
1050+ Semigroup (Expression db from grouping param (nullity 'PGjsonb)) where
10501051 (<>) = unsafeBinaryOp "||"
10511052
10521053-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1063,9 +1064,9 @@ instance
10631064-- count from the end). Throws an error if top level container is not an array.
10641065(.-.)
10651066 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1066− => Expression schema from grouping params (nullity 'PGjsonb)
1067− -> Expression schema from grouping params (nullity key)
1068− -> Expression schema from grouping params (nullity 'PGjsonb)
1067+ => Expression db from grouping params (nullity 'PGjsonb)
1068+ -> Expression db from grouping params (nullity key)
1069+ -> Expression db from grouping params (nullity 'PGjsonb)
10691070infixl 6 .-.
10701071(.-.) = unsafeBinaryOp "-"
10711072
@@ -1073,9 +1074,9 @@ infixl 6 .-.
10731074-- integers count from the end)
10741075(#-.)
10751076 :: PGTextArray "(#-.)" arrayty
1076− => Expression schema from grouping params (nullity 'PGjsonb)
1077− -> Expression schema from grouping params (nullity arrayty)
1078− -> Expression schema from grouping params (nullity 'PGjsonb)
1077+ => Expression db from grouping params (nullity 'PGjsonb)
1078+ -> Expression db from grouping params (nullity arrayty)
1079+ -> Expression db from grouping params (nullity 'PGjsonb)
10791080infixl 6 #-.
10801081(#-.) = unsafeBinaryOp "#-"
10811082
@@ -1086,14 +1087,14 @@ Table 9.45: JSON creation functions
10861087-- | Literal binary JSON
10871088jsonbLit
10881089 :: JSON.ToJSON x
1089− => x -> Expression schema from grouping params (nullity 'PGjsonb)
1090+ => x -> Expression db from grouping params (nullity 'PGjsonb)
10901091jsonbLit = cast jsonb . UnsafeExpression
10911092 . singleQuotedUtf8 . toStrict . JSON.encode
10921093
10931094-- | Literal JSON
10941095jsonLit
10951096 :: JSON.ToJSON x
1096− => x -> Expression schema from grouping params (nullity 'PGjson)
1097+ => x -> Expression db from grouping params (nullity 'PGjson)
10971098jsonLit = cast json . UnsafeExpression
10981099 . singleQuotedUtf8 . toStrict . JSON.encode
10991100
@@ -1104,8 +1105,8 @@ jsonLit = cast json . UnsafeExpression
11041105-- number, a Boolean, or a null value, the text representation will be used, in
11051106-- such a fashion that it is a valid json value.
11061107toJson
1107− :: Expression schema from grouping params (nullity ty)
1108− -> Expression schema from grouping params (nullity 'PGjson)
1108+ :: Expression db from grouping params (nullity ty)
1109+ -> Expression db from grouping params (nullity 'PGjson)
11091110toJson = unsafeFunction "to_json"
11101111
11111112-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1115,43 +1116,43 @@ toJson = unsafeFunction "to_json"
11151116-- number, a Boolean, or a null value, the text representation will be used, in
11161117-- such a fashion that it is a valid jsonb value.
11171118toJsonb
1118− :: Expression schema from grouping params (nullity ty)
1119− -> Expression schema from grouping params (nullity 'PGjsonb)
1119+ :: Expression db from grouping params (nullity ty)
1120+ -> Expression db from grouping params (nullity 'PGjsonb)
11201121toJsonb = unsafeFunction "to_jsonb"
11211122
11221123-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
11231124-- becomes a JSON array of arrays.
11241125arrayToJson
11251126 :: PGArray "arrayToJson" arr
1126− => Expression schema from grouping params (nullity arr)
1127− -> Expression schema from grouping params (nullity 'PGjson)
1127+ => Expression db from grouping params (nullity arr)
1128+ -> Expression db from grouping params (nullity 'PGjson)
11281129arrayToJson = unsafeFunction "array_to_json"
11291130
11301131-- | Returns the row as a JSON object.
11311132rowToJson
1132− :: Expression schema from grouping params (nullity ('PGcomposite ty))
1133− -> Expression schema from grouping params (nullity 'PGjson)
1133+ :: Expression db from grouping params (nullity ('PGcomposite ty))
1134+ -> Expression db from grouping params (nullity 'PGjson)
11341135rowToJson = unsafeFunction "row_to_json"
11351136
11361137-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
11371138-- argument list.
11381139jsonBuildArray
11391140 :: SListI elems
1140− => NP (Expression schema from grouping params) elems
1141− -> Expression schema from grouping params (nullity 'PGjson)
1141+ => NP (Expression db from grouping params) elems
1142+ -> Expression db from grouping params (nullity 'PGjson)
11421143jsonBuildArray = unsafeVariadicFunction "json_build_array"
11431144
11441145-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
11451146-- variadic argument list.
11461147jsonbBuildArray
11471148 :: SListI elems
1148− => NP (Expression schema from grouping params) elems
1149− -> Expression schema from grouping params (nullity 'PGjsonb)
1149+ => NP (Expression db from grouping params) elems
1150+ -> Expression db from grouping params (nullity 'PGjsonb)
11501151jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
11511152
11521153unsafeRowFunction
11531154 :: All Top elems
1154− => NP (Aliased (Expression schema from grouping params)) elems
1155+ => NP (Aliased (Expression db from grouping params)) elems
11551156 -> [ByteString]
11561157unsafeRowFunction =
11571158 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1163,8 +1164,8 @@ unsafeRowFunction =
11631164-- and values.
11641165jsonBuildObject
11651166 :: All Top elems
1166− => NP (Aliased (Expression schema from grouping params)) elems
1167− -> Expression schema from grouping params (nullity 'PGjson)
1167+ => NP (Aliased (Expression db from grouping params)) elems
1168+ -> Expression db from grouping params (nullity 'PGjson)
11681169jsonBuildObject
11691170 = unsafeFunction "json_build_object"
11701171 . UnsafeExpression
@@ -1176,8 +1177,8 @@ jsonBuildObject
11761177-- between text and values.
11771178jsonbBuildObject
11781179 :: All Top elems
1179− => NP (Aliased (Expression schema from grouping params)) elems
1180− -> Expression schema from grouping params (nullity 'PGjsonb)
1180+ => NP (Aliased (Expression db from grouping params)) elems
1181+ -> Expression db from grouping params (nullity 'PGjsonb)
11811182jsonbBuildObject
11821183 = unsafeFunction "jsonb_build_object"
11831184 . UnsafeExpression
@@ -1190,8 +1191,8 @@ jsonbBuildObject
11901191-- array has exactly two elements, which are taken as a key/value pair.
11911192jsonObject
11921193 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1193− => Expression schema from grouping params (nullity arr)
1194− -> Expression schema from grouping params (nullity 'PGjson)
1194+ => Expression db from grouping params (nullity arr)
1195+ -> Expression db from grouping params (nullity 'PGjson)
11951196jsonObject = unsafeFunction "json_object"
11961197
11971198-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1200,8 +1201,8 @@ jsonObject = unsafeFunction "json_object"
12001201-- array has exactly two elements, which are taken as a key/value pair.
12011202jsonbObject
12021203 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1203− => Expression schema from grouping params (nullity arr)
1204− -> Expression schema from grouping params (nullity 'PGjsonb)
1204+ => Expression db from grouping params (nullity arr)
1205+ -> Expression db from grouping params (nullity 'PGjsonb)
12051206jsonbObject = unsafeFunction "jsonb_object"
12061207
12071208-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1209,9 +1210,9 @@ jsonbObject = unsafeFunction "jsonb_object"
12091210jsonZipObject
12101211 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
12111212 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1212− => Expression schema from grouping params (nullity keysArray)
1213− -> Expression schema from grouping params (nullity valuesArray)
1214− -> Expression schema from grouping params (nullity 'PGjson)
1213+ => Expression db from grouping params (nullity keysArray)
1214+ -> Expression db from grouping params (nullity valuesArray)
1215+ -> Expression db from grouping params (nullity 'PGjson)
12151216jsonZipObject ks vs =
12161217 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
12171218
@@ -1221,9 +1222,9 @@ jsonZipObject ks vs =
12211222jsonbZipObject
12221223 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
12231224 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1224− => Expression schema from grouping params (nullity keysArray)
1225− -> Expression schema from grouping params (nullity valuesArray)
1226− -> Expression schema from grouping params (nullity 'PGjsonb)
1225+ => Expression db from grouping params (nullity keysArray)
1226+ -> Expression db from grouping params (nullity valuesArray)
1227+ -> Expression db from grouping params (nullity 'PGjsonb)
12271228jsonbZipObject ks vs =
12281229 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
12291230
@@ -1233,23 +1234,23 @@ Table 9.46: JSON processing functions
12331234
12341235-- | Returns the number of elements in the outermost JSON array.
12351236jsonArrayLength
1236− :: Expression schema from grouping params (nullity 'PGjson)
1237− -> Expression schema from grouping params (nullity 'PGint4)
1237+ :: Expression db from grouping params (nullity 'PGjson)
1238+ -> Expression db from grouping params (nullity 'PGint4)
12381239jsonArrayLength = unsafeFunction "json_array_length"
12391240
12401241-- | Returns the number of elements in the outermost binary JSON array.
12411242jsonbArrayLength
1242− :: Expression schema from grouping params (nullity 'PGjsonb)
1243− -> Expression schema from grouping params (nullity 'PGint4)
1243+ :: Expression db from grouping params (nullity 'PGjsonb)
1244+ -> Expression db from grouping params (nullity 'PGint4)
12441245jsonbArrayLength = unsafeFunction "jsonb_array_length"
12451246
12461247-- | Returns JSON value pointed to by the given path (equivalent to #>
12471248-- operator).
12481249jsonExtractPath
12491250 :: SListI elems
1250− => Expression schema from grouping params (nullity 'PGjson)
1251− -> NP (Expression schema from grouping params) elems
1252− -> Expression schema from grouping params (nullity 'PGjsonb)
1251+ => Expression db from grouping params (nullity 'PGjson)
1252+ -> NP (Expression db from grouping params) elems
1253+ -> Expression db from grouping params (nullity 'PGjsonb)
12531254jsonExtractPath x xs =
12541255 unsafeVariadicFunction "json_extract_path" (x :* xs)
12551256
@@ -1257,9 +1258,9 @@ jsonExtractPath x xs =
12571258-- operator).
12581259jsonbExtractPath
12591260 :: SListI elems
1260− => Expression schema from grouping params (nullity 'PGjsonb)
1261− -> NP (Expression schema from grouping params) elems
1262− -> Expression schema from grouping params (nullity 'PGjsonb)
1261+ => Expression db from grouping params (nullity 'PGjsonb)
1262+ -> NP (Expression db from grouping params) elems
1263+ -> Expression db from grouping params (nullity 'PGjsonb)
12631264jsonbExtractPath x xs =
12641265 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
12651266
@@ -1267,9 +1268,9 @@ jsonbExtractPath x xs =
12671268-- operator), as text.
12681269jsonExtractPathAsText
12691270 :: SListI elems
1270− => Expression schema from grouping params (nullity 'PGjson)
1271− -> NP (Expression schema from grouping params) elems
1272− -> Expression schema from grouping params (nullity 'PGjson)
1271+ => Expression db from grouping params (nullity 'PGjson)
1272+ -> NP (Expression db from grouping params) elems
1273+ -> Expression db from grouping params (nullity 'PGjson)
12731274jsonExtractPathAsText x xs =
12741275 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
12751276
@@ -1277,38 +1278,38 @@ jsonExtractPathAsText x xs =
12771278-- operator), as text.
12781279jsonbExtractPathAsText
12791280 :: SListI elems
1280− => Expression schema from grouping params (nullity 'PGjsonb)
1281− -> NP (Expression schema from grouping params) elems
1282− -> Expression schema from grouping params (nullity 'PGjsonb)
1281+ => Expression db from grouping params (nullity 'PGjsonb)
1282+ -> NP (Expression db from grouping params) elems
1283+ -> Expression db from grouping params (nullity 'PGjsonb)
12831284jsonbExtractPathAsText x xs =
12841285 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
12851286
12861287-- | Returns the type of the outermost JSON value as a text string. Possible
12871288-- types are object, array, string, number, boolean, and null.
12881289jsonTypeof
1289− :: Expression schema from grouping params (nullity 'PGjson)
1290− -> Expression schema from grouping params (nullity 'PGtext)
1290+ :: Expression db from grouping params (nullity 'PGjson)
1291+ -> Expression db from grouping params (nullity 'PGtext)
12911292jsonTypeof = unsafeFunction "json_typeof"
12921293
12931294-- | Returns the type of the outermost binary JSON value as a text string.
12941295-- Possible types are object, array, string, number, boolean, and null.
12951296jsonbTypeof
1296− :: Expression schema from grouping params (nullity 'PGjsonb)
1297− -> Expression schema from grouping params (nullity 'PGtext)
1297+ :: Expression db from grouping params (nullity 'PGjsonb)
1298+ -> Expression db from grouping params (nullity 'PGtext)
12981299jsonbTypeof = unsafeFunction "jsonb_typeof"
12991300
13001301-- | Returns its argument with all object fields that have null values omitted.
13011302-- Other null values are untouched.
13021303jsonStripNulls
1303− :: Expression schema from grouping params (nullity 'PGjson)
1304− -> Expression schema from grouping params (nullity 'PGjson)
1304+ :: Expression db from grouping params (nullity 'PGjson)
1305+ -> Expression db from grouping params (nullity 'PGjson)
13051306jsonStripNulls = unsafeFunction "json_strip_nulls"
13061307
13071308-- | Returns its argument with all object fields that have null values omitted.
13081309-- Other null values are untouched.
13091310jsonbStripNulls
1310− :: Expression schema from grouping params (nullity 'PGjsonb)
1311− -> Expression schema from grouping params (nullity 'PGjsonb)
1311+ :: Expression db from grouping params (nullity 'PGjsonb)
1312+ -> Expression db from grouping params (nullity 'PGjsonb)
13121313jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13131314
13141315-- | @ jsonbSet target path new_value create_missing @
@@ -1320,11 +1321,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13201321-- arrays.
13211322jsonbSet
13221323 :: PGTextArray "jsonbSet" arr
1323− => Expression schema from grouping params (nullity 'PGjsonb)
1324− -> Expression schema from grouping params (nullity arr)
1325− -> Expression schema from grouping params (nullity 'PGjsonb)
1326− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1327− -> Expression schema from grouping params (nullity 'PGjsonb)
1324+ => Expression db from grouping params (nullity 'PGjsonb)
1325+ -> Expression db from grouping params (nullity arr)
1326+ -> Expression db from grouping params (nullity 'PGjsonb)
1327+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1328+ -> Expression db from grouping params (nullity 'PGjsonb)
13281329jsonbSet tgt path val createMissing = case createMissing of
13291330 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
13301331 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1339,19 +1340,19 @@ jsonbSet tgt path val createMissing = case createMissing of
13391340-- in path count from the end of JSON arrays.
13401341jsonbInsert
13411342 :: PGTextArray "jsonbInsert" arr
1342− => Expression schema from grouping params (nullity 'PGjsonb)
1343− -> Expression schema from grouping params (nullity arr)
1344− -> Expression schema from grouping params (nullity 'PGjsonb)
1345− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1346− -> Expression schema from grouping params (nullity 'PGjsonb)
1343+ => Expression db from grouping params (nullity 'PGjsonb)
1344+ -> Expression db from grouping params (nullity arr)
1345+ -> Expression db from grouping params (nullity 'PGjsonb)
1346+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1347+ -> Expression db from grouping params (nullity 'PGjsonb)
13471348jsonbInsert tgt path val insertAfter = case insertAfter of
13481349 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
13491350 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
13501351
13511352-- | Returns its argument as indented JSON text.
13521353jsonbPretty
1353− :: Expression schema from grouping params (nullity 'PGjsonb)
1354− -> Expression schema from grouping params (nullity 'PGtext)
1354+ :: Expression db from grouping params (nullity 'PGjsonb)
1355+ -> Expression db from grouping params (nullity 'PGtext)
13551356jsonbPretty = unsafeFunction "jsonb_pretty"
13561357
13571358{-----------------------------------------
@@ -1361,54 +1362,54 @@ aggregation
13611362-- | escape hatch to define aggregate functions
13621363unsafeAggregate
13631364 :: ByteString -- ^ aggregate function
1364− -> Expression schema from 'Ungrouped params (xty)
1365− -> Expression schema from ('Grouped bys) params (yty)
1365+ -> Expression db from 'Ungrouped params (xty)
1366+ -> Expression db from ('Grouped bys) params (yty)
13661367unsafeAggregate fun x = UnsafeExpression $ mconcat
13671368 [fun, "(", renderExpression x, ")"]
13681369
13691370-- | escape hatch to define aggregate functions over distinct values
13701371unsafeAggregateDistinct
13711372 :: ByteString -- ^ aggregate function
1372− -> Expression schema from 'Ungrouped params (xty)
1373− -> Expression schema from ('Grouped bys) params (yty)
1373+ -> Expression db from 'Ungrouped params (xty)
1374+ -> Expression db from ('Grouped bys) params (yty)
13741375unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
13751376 [fun, "(DISTINCT ", renderExpression x, ")"]
13761377
13771378-- | >>> :{
13781379-- let
1379−-- expression :: Expression schema '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
1380+-- expression :: Expression db '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
13801381-- expression = sum_ #col
13811382-- in printSQL expression
13821383-- :}
13831384-- sum("col")
13841385sum_
13851386 :: ty `In` PGNum
1386− => Expression schema from 'Ungrouped params (nullity ty)
1387+ => Expression db from 'Ungrouped params (nullity ty)
13871388 -- ^ what to sum
1388− -> Expression schema from ('Grouped bys) params (nullity ty)
1389+ -> Expression db from ('Grouped bys) params (nullity ty)
13891390sum_ = unsafeAggregate "sum"
13901391
13911392-- | >>> :{
13921393-- let
1393−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
1394+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
13941395-- expression = sumDistinct #col
13951396-- in printSQL expression
13961397-- :}
13971398-- sum(DISTINCT "col")
13981399sumDistinct
13991400 :: ty `In` PGNum
1400− => Expression schema from 'Ungrouped params (nullity ty)
1401+ => Expression db from 'Ungrouped params (nullity ty)
14011402 -- ^ what to sum
1402− -> Expression schema from ('Grouped bys) params (nullity ty)
1403+ -> Expression db from ('Grouped bys) params (nullity ty)
14031404sumDistinct = unsafeAggregateDistinct "sum"
14041405
14051406-- | A constraint for `PGType`s that you can take averages of and the resulting
14061407-- `PGType`.
14071408class PGAvg ty avg | ty -> avg where
14081409 avg, avgDistinct
1409− :: Expression schema from 'Ungrouped params (nullity ty)
1410+ :: Expression db from 'Ungrouped params (nullity ty)
14101411 -- ^ what to average
1411− -> Expression schema from ('Grouped bys) params (nullity avg)
1412+ -> Expression db from ('Grouped bys) params (nullity avg)
14121413 avg = unsafeAggregate "avg"
14131414 avgDistinct = unsafeAggregateDistinct "avg"
14141415instance PGAvg 'PGint2 'PGnumeric
@@ -1421,110 +1422,110 @@ instance PGAvg 'PGinterval 'PGinterval
14211422
14221423-- | >>> :{
14231424-- let
1424−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1425+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14251426-- expression = bitAnd #col
14261427-- in printSQL expression
14271428-- :}
14281429-- bit_and("col")
14291430bitAnd
14301431 :: int `In` PGIntegral
1431− => Expression schema from 'Ungrouped params (nullity int)
1432+ => Expression db from 'Ungrouped params (nullity int)
14321433 -- ^ what to aggregate
1433− -> Expression schema from ('Grouped bys) params (nullity int)
1434+ -> Expression db from ('Grouped bys) params (nullity int)
14341435bitAnd = unsafeAggregate "bit_and"
14351436
14361437-- | >>> :{
14371438-- let
1438−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1439+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14391440-- expression = bitOr #col
14401441-- in printSQL expression
14411442-- :}
14421443-- bit_or("col")
14431444bitOr
14441445 :: int `In` PGIntegral
1445− => Expression schema from 'Ungrouped params (nullity int)
1446+ => Expression db from 'Ungrouped params (nullity int)
14461447 -- ^ what to aggregate
1447− -> Expression schema from ('Grouped bys) params (nullity int)
1448+ -> Expression db from ('Grouped bys) params (nullity int)
14481449bitOr = unsafeAggregate "bit_or"
14491450
14501451-- | >>> :{
14511452-- let
1452−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1453+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14531454-- expression = bitAndDistinct #col
14541455-- in printSQL expression
14551456-- :}
14561457-- bit_and(DISTINCT "col")
14571458bitAndDistinct
14581459 :: int `In` PGIntegral
1459− => Expression schema from 'Ungrouped params (nullity int)
1460+ => Expression db from 'Ungrouped params (nullity int)
14601461 -- ^ what to aggregate
1461− -> Expression schema from ('Grouped bys) params (nullity int)
1462+ -> Expression db from ('Grouped bys) params (nullity int)
14621463bitAndDistinct = unsafeAggregateDistinct "bit_and"
14631464
14641465-- | >>> :{
14651466-- let
1466−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
1467+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
14671468-- expression = bitOrDistinct #col
14681469-- in printSQL expression
14691470-- :}
14701471-- bit_or(DISTINCT "col")
14711472bitOrDistinct
14721473 :: int `In` PGIntegral
1473− => Expression schema from 'Ungrouped params (nullity int)
1474+ => Expression db from 'Ungrouped params (nullity int)
14741475 -- ^ what to aggregate
1475− -> Expression schema from ('Grouped bys) params (nullity int)
1476+ -> Expression db from ('Grouped bys) params (nullity int)
14761477bitOrDistinct = unsafeAggregateDistinct "bit_or"
14771478
14781479-- | >>> :{
14791480-- let
1480−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1481+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
14811482-- expression = boolAnd #col
14821483-- in printSQL expression
14831484-- :}
14841485-- bool_and("col")
14851486boolAnd
1486− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1487+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
14871488 -- ^ what to aggregate
1488− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1489+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
14891490boolAnd = unsafeAggregate "bool_and"
14901491
14911492-- | >>> :{
14921493-- let
1493−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1494+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
14941495-- expression = boolOr #col
14951496-- in printSQL expression
14961497-- :}
14971498-- bool_or("col")
14981499boolOr
1499− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1500+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15001501 -- ^ what to aggregate
1501− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1502+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15021503boolOr = unsafeAggregate "bool_or"
15031504
15041505-- | >>> :{
15051506-- let
1506−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1507+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15071508-- expression = boolAndDistinct #col
15081509-- in printSQL expression
15091510-- :}
15101511-- bool_and(DISTINCT "col")
15111512boolAndDistinct
1512− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1513+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15131514 -- ^ what to aggregate
1514− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1515+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15151516boolAndDistinct = unsafeAggregateDistinct "bool_and"
15161517
15171518-- | >>> :{
15181519-- let
1519−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1520+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15201521-- expression = boolOrDistinct #col
15211522-- in printSQL expression
15221523-- :}
15231524-- bool_or(DISTINCT "col")
15241525boolOrDistinct
1525− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1526+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15261527 -- ^ what to aggregate
1527− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1528+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15281529boolOrDistinct = unsafeAggregateDistinct "bool_or"
15291530
15301531-- | A special aggregation that does not require an input
@@ -1532,70 +1533,70 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
15321533-- >>> printSQL countStar
15331534-- count(*)
15341535countStar
1535− :: Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1536+ :: Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15361537countStar = UnsafeExpression $ "count(*)"
15371538
15381539-- | >>> :{
15391540-- let
1540−-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1541+-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
15411542-- expression = count #col
15421543-- in printSQL expression
15431544-- :}
15441545-- count("col")
15451546count
1546− :: Expression schema from 'Ungrouped params ty
1547+ :: Expression db from 'Ungrouped params ty
15471548 -- ^ what to count
1548− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1549+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15491550count = unsafeAggregate "count"
15501551
15511552-- | >>> :{
15521553-- let
1553−-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1554+-- expression :: Expression db '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
15541555-- expression = countDistinct #col
15551556-- in printSQL expression
15561557-- :}
15571558-- count(DISTINCT "col")
15581559countDistinct
1559− :: Expression schema from 'Ungrouped params ty
1560+ :: Expression db from 'Ungrouped params ty
15601561 -- ^ what to count
1561− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1562+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
15621563countDistinct = unsafeAggregateDistinct "count"
15631564
15641565-- | synonym for `boolAnd`
15651566--
15661567-- >>> :{
15671568-- let
1568−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1569+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15691570-- expression = every #col
15701571-- in printSQL expression
15711572-- :}
15721573-- every("col")
15731574every
1574− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1575+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15751576 -- ^ what to aggregate
1576− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1577+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15771578every = unsafeAggregate "every"
15781579
15791580-- | synonym for `boolAndDistinct`
15801581--
15811582-- >>> :{
15821583-- let
1583−-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1584+-- expression :: Expression db '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
15841585-- expression = everyDistinct #col
15851586-- in printSQL expression
15861587-- :}
15871588-- every(DISTINCT "col")
15881589everyDistinct
1589− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1590+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
15901591 -- ^ what to aggregate
1591− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1592+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
15921593everyDistinct = unsafeAggregateDistinct "every"
15931594
15941595-- | minimum and maximum aggregation
15951596max_, min_, maxDistinct, minDistinct
1596− :: Expression schema from 'Ungrouped params (nullity ty)
1597+ :: Expression db from 'Ungrouped params (nullity ty)
15971598 -- ^ what to aggregate
1598− -> Expression schema from ('Grouped bys) params (nullity ty)
1599+ -> Expression db from ('Grouped bys) params (nullity ty)
15991600max_ = unsafeAggregate "max"
16001601min_ = unsafeAggregate "min"
16011602maxDistinct = unsafeAggregateDistinct "max"
@@ -1606,153 +1607,153 @@ type expressions
16061607-----------------------------------------}
16071608
16081609-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1609−newtype TypeExpression (schema :: SchemaType) (ty :: NullityType)
1610+newtype TypeExpression (db :: DBType) (ty :: NullityType)
16101611 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
16111612 deriving (GHC.Generic,Show,Eq,Ord,NFData)
16121613
16131614-- | The enum or composite type in a `Typedef` can be expressed by its alias.
16141615typedef
1615− :: Has alias schema ('Typedef ty)
1616− => Alias alias
1617− -> TypeExpression schema (nullity ty)
1618−typedef = UnsafeTypeExpression . renderAlias
1616+ :: HasQualified sch td db schema ('Typedef ty)
1617+ => QualifiedAlias sch td
1618+ -> TypeExpression db (nullity ty)
1619+typedef = UnsafeTypeExpression . renderQualifiedAlias
16191620
16201621-- | The composite type corresponding to a `Table` definition can be expressed
16211622-- by its alias.
16221623typetable
1623− :: Has alias schema ('Table tab)
1624− => Alias alias
1625− -> TypeExpression schema (nullity ('PGcomposite (TableToRow tab)))
1626−typetable = UnsafeTypeExpression . renderAlias
1624+ :: HasQualified sch tab db schema ('Table table)
1625+ => QualifiedAlias sch tab
1626+ -> TypeExpression db (nullity ('PGcomposite (TableToRow table)))
1627+typetable = UnsafeTypeExpression . renderQualifiedAlias
16271628
16281629-- | The composite type corresponding to a `View` definition can be expressed
16291630-- by its alias.
16301631typeview
1631− :: Has alias schema ('View view)
1632− => Alias alias
1633− -> TypeExpression schema (nullity ('PGcomposite view))
1634−typeview = UnsafeTypeExpression . renderAlias
1632+ :: HasQualified sch vw db schema ('View view)
1633+ => QualifiedAlias sch vw
1634+ -> TypeExpression db (nullity ('PGcomposite view))
1635+typeview = UnsafeTypeExpression . renderQualifiedAlias
16351636
16361637-- | logical Boolean (true/false)
1637−bool :: TypeExpression schema (nullity 'PGbool)
1638+bool :: TypeExpression db (nullity 'PGbool)
16381639bool = UnsafeTypeExpression "bool"
16391640-- | signed two-byte integer
1640−int2, smallint :: TypeExpression schema (nullity 'PGint2)
1641+int2, smallint :: TypeExpression db (nullity 'PGint2)
16411642int2 = UnsafeTypeExpression "int2"
16421643smallint = UnsafeTypeExpression "smallint"
16431644-- | signed four-byte integer
1644−int4, int, integer :: TypeExpression schema (nullity 'PGint4)
1645+int4, int, integer :: TypeExpression db (nullity 'PGint4)
16451646int4 = UnsafeTypeExpression "int4"
16461647int = UnsafeTypeExpression "int"
16471648integer = UnsafeTypeExpression "integer"
16481649-- | signed eight-byte integer
1649−int8, bigint :: TypeExpression schema (nullity 'PGint8)
1650+int8, bigint :: TypeExpression db (nullity 'PGint8)
16501651int8 = UnsafeTypeExpression "int8"
16511652bigint = UnsafeTypeExpression "bigint"
16521653-- | arbitrary precision numeric type
1653−numeric :: TypeExpression schema (nullity 'PGnumeric)
1654+numeric :: TypeExpression db (nullity 'PGnumeric)
16541655numeric = UnsafeTypeExpression "numeric"
16551656-- | single precision floating-point number (4 bytes)
1656−float4, real :: TypeExpression schema (nullity 'PGfloat4)
1657+float4, real :: TypeExpression db (nullity 'PGfloat4)
16571658float4 = UnsafeTypeExpression "float4"
16581659real = UnsafeTypeExpression "real"
16591660-- | double precision floating-point number (8 bytes)
1660−float8, doublePrecision :: TypeExpression schema (nullity 'PGfloat8)
1661+float8, doublePrecision :: TypeExpression db (nullity 'PGfloat8)
16611662float8 = UnsafeTypeExpression "float8"
16621663doublePrecision = UnsafeTypeExpression "double precision"
16631664-- | variable-length character string
1664−text :: TypeExpression schema (nullity 'PGtext)
1665+text :: TypeExpression db (nullity 'PGtext)
16651666text = UnsafeTypeExpression "text"
16661667-- | fixed-length character string
16671668char, character
1668− :: forall n schema nullity. (KnownNat n, 1 <= n)
1669− => TypeExpression schema (nullity ('PGchar n))
1669+ :: forall n db nullity. (KnownNat n, 1 <= n)
1670+ => TypeExpression db (nullity ('PGchar n))
16701671char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
16711672character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
16721673-- | variable-length character string
16731674varchar, characterVarying
1674− :: forall n schema nullity. (KnownNat n, 1 <= n)
1675− => TypeExpression schema (nullity ('PGvarchar n))
1675+ :: forall n db nullity. (KnownNat n, 1 <= n)
1676+ => TypeExpression db (nullity ('PGvarchar n))
16761677varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
16771678characterVarying = UnsafeTypeExpression $
16781679 "character varying(" <> renderNat @n <> ")"
16791680-- | binary data ("byte array")
1680−bytea :: TypeExpression schema (nullity 'PGbytea)
1681+bytea :: TypeExpression db (nullity 'PGbytea)
16811682bytea = UnsafeTypeExpression "bytea"
16821683-- | date and time (no time zone)
1683−timestamp :: TypeExpression schema (nullity 'PGtimestamp)
1684+timestamp :: TypeExpression db (nullity 'PGtimestamp)
16841685timestamp = UnsafeTypeExpression "timestamp"
16851686-- | date and time, including time zone
1686−timestampWithTimeZone :: TypeExpression schema (nullity 'PGtimestamptz)
1687+timestampWithTimeZone :: TypeExpression db (nullity 'PGtimestamptz)
16871688timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
16881689-- | calendar date (year, month, day)
1689−date :: TypeExpression schema (nullity 'PGdate)
1690+date :: TypeExpression db (nullity 'PGdate)
16901691date = UnsafeTypeExpression "date"
16911692-- | time of day (no time zone)
1692−time :: TypeExpression schema (nullity 'PGtime)
1693+time :: TypeExpression db (nullity 'PGtime)
16931694time = UnsafeTypeExpression "time"
16941695-- | time of day, including time zone
1695−timeWithTimeZone :: TypeExpression schema (nullity 'PGtimetz)
1696+timeWithTimeZone :: TypeExpression db (nullity 'PGtimetz)
16961697timeWithTimeZone = UnsafeTypeExpression "time with time zone"
16971698-- | time span
1698−interval :: TypeExpression schema (nullity 'PGinterval)
1699+interval :: TypeExpression db (nullity 'PGinterval)
16991700interval = UnsafeTypeExpression "interval"
17001701-- | universally unique identifier
1701−uuid :: TypeExpression schema (nullity 'PGuuid)
1702+uuid :: TypeExpression db (nullity 'PGuuid)
17021703uuid = UnsafeTypeExpression "uuid"
17031704-- | IPv4 or IPv6 host address
1704−inet :: TypeExpression schema (nullity 'PGinet)
1705+inet :: TypeExpression db (nullity 'PGinet)
17051706inet = UnsafeTypeExpression "inet"
17061707-- | textual JSON data
1707−json :: TypeExpression schema (nullity 'PGjson)
1708+json :: TypeExpression db (nullity 'PGjson)
17081709json = UnsafeTypeExpression "json"
17091710-- | binary JSON data, decomposed
1710−jsonb :: TypeExpression schema (nullity 'PGjsonb)
1711+jsonb :: TypeExpression db (nullity 'PGjsonb)
17111712jsonb = UnsafeTypeExpression "jsonb"
17121713-- | variable length array
17131714vararray
1714− :: TypeExpression schema pg
1715− -> TypeExpression schema (nullity ('PGvararray pg))
1715+ :: TypeExpression db pg
1716+ -> TypeExpression db (nullity ('PGvararray pg))
17161717vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
17171718-- | fixed length array
17181719--
17191720-- >>> renderTypeExpression (fixarray @2 json)
17201721-- "json[2]"
17211722fixarray
1722− :: forall n schema nullity pg. KnownNat n
1723− => TypeExpression schema pg
1724− -> TypeExpression schema (nullity ('PGfixarray n pg))
1723+ :: forall n db nullity pg. KnownNat n
1724+ => TypeExpression db pg
1725+ -> TypeExpression db (nullity ('PGfixarray n pg))
17251726fixarray ty = UnsafeTypeExpression $
17261727 renderTypeExpression ty <> "[" <> renderNat @n <> "]"
17271728
17281729-- | `pgtype` is a demoted version of a `PGType`
1729−class PGTyped schema (ty :: NullityType) where
1730− pgtype :: TypeExpression schema ty
1731−instance PGTyped schema (nullity 'PGbool) where pgtype = bool
1732−instance PGTyped schema (nullity 'PGint2) where pgtype = int2
1733−instance PGTyped schema (nullity 'PGint4) where pgtype = int4
1734−instance PGTyped schema (nullity 'PGint8) where pgtype = int8
1735−instance PGTyped schema (nullity 'PGnumeric) where pgtype = numeric
1736−instance PGTyped schema (nullity 'PGfloat4) where pgtype = float4
1737−instance PGTyped schema (nullity 'PGfloat8) where pgtype = float8
1738−instance PGTyped schema (nullity 'PGtext) where pgtype = text
1730+class PGTyped db (ty :: NullityType) where
1731+ pgtype :: TypeExpression db ty
1732+instance PGTyped db (nullity 'PGbool) where pgtype = bool
1733+instance PGTyped db (nullity 'PGint2) where pgtype = int2
1734+instance PGTyped db (nullity 'PGint4) where pgtype = int4
1735+instance PGTyped db (nullity 'PGint8) where pgtype = int8
1736+instance PGTyped db (nullity 'PGnumeric) where pgtype = numeric
1737+instance PGTyped db (nullity 'PGfloat4) where pgtype = float4
1738+instance PGTyped db (nullity 'PGfloat8) where pgtype = float8
1739+instance PGTyped db (nullity 'PGtext) where pgtype = text
17391740instance (KnownNat n, 1 <= n)
1740− => PGTyped schema (nullity ('PGchar n)) where pgtype = char @n
1741+ => PGTyped db (nullity ('PGchar n)) where pgtype = char @n
17411742instance (KnownNat n, 1 <= n)
1742− => PGTyped schema (nullity ('PGvarchar n)) where pgtype = varchar @n
1743−instance PGTyped schema (nullity 'PGbytea) where pgtype = bytea
1744−instance PGTyped schema (nullity 'PGtimestamp) where pgtype = timestamp
1745−instance PGTyped schema (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1746−instance PGTyped schema (nullity 'PGdate) where pgtype = date
1747−instance PGTyped schema (nullity 'PGtime) where pgtype = time
1748−instance PGTyped schema (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1749−instance PGTyped schema (nullity 'PGinterval) where pgtype = interval
1750−instance PGTyped schema (nullity 'PGuuid) where pgtype = uuid
1751−instance PGTyped schema (nullity 'PGjson) where pgtype = json
1752−instance PGTyped schema (nullity 'PGjsonb) where pgtype = jsonb
1753−instance PGTyped schema ty
1754− => PGTyped schema (nullity ('PGvararray ty)) where
1755− pgtype = vararray (pgtype @schema @ty)
1756−instance (KnownNat n, PGTyped schema ty)
1757− => PGTyped schema (nullity ('PGfixarray n ty)) where
1758− pgtype = fixarray @n (pgtype @schema @ty)
1743+ => PGTyped db (nullity ('PGvarchar n)) where pgtype = varchar @n
1744+instance PGTyped db (nullity 'PGbytea) where pgtype = bytea
1745+instance PGTyped db (nullity 'PGtimestamp) where pgtype = timestamp
1746+instance PGTyped db (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1747+instance PGTyped db (nullity 'PGdate) where pgtype = date
1748+instance PGTyped db (nullity 'PGtime) where pgtype = time
1749+instance PGTyped db (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1750+instance PGTyped db (nullity 'PGinterval) where pgtype = interval
1751+instance PGTyped db (nullity 'PGuuid) where pgtype = uuid
1752+instance PGTyped db (nullity 'PGjson) where pgtype = json
1753+instance PGTyped db (nullity 'PGjsonb) where pgtype = jsonb
1754+instance PGTyped db ty
1755+ => PGTyped db (nullity ('PGvararray ty)) where
1756+ pgtype = vararray (pgtype @db @ty)
1757+instance (KnownNat n, PGTyped db ty)
1758+ => PGTyped db (nullity ('PGfixarray n ty)) where
1759+ pgtype = fixarray @n (pgtype @db @ty)
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+78−76
@@ -197,23 +197,25 @@ WITH "deleted_rows" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RET
197197-}
198198
199199newtype Manipulation
200− (schema :: SchemaType)
200+ (db :: DBType)
201201 (params :: [NullityType])
202202 (columns :: RowType)
203203 = UnsafeManipulation { renderManipulation :: ByteString }
204204 deriving (GHC.Generic,Show,Eq,Ord,NFData)
205−instance RenderSQL (Manipulation schema params columns) where
205+instance RenderSQL (Manipulation db params columns) where
206206 renderSQL = renderManipulation
207+{--------------FIX WITH
208+
207209instance With Manipulation where
208210 with Done manip = manip
209211 with (cte :>> ctes) manip = UnsafeManipulation $
210212 "WITH" <+> renderCommonTableExpressions renderManipulation cte ctes
211213 <+> renderManipulation manip
212−
214+-}
213215-- | Convert a `Query` into a `Manipulation`.
214216queryStatement
215− :: Query schema params columns
216− -> Manipulation schema params columns
217+ :: Query db params columns
218+ -> Manipulation db params columns
217219queryStatement q = UnsafeManipulation $ renderQuery q
218220
219221{-----------------------------------------
@@ -230,18 +232,18 @@ INSERT statements
230232insertRows
231233 :: ( SOP.SListI columns
232234 , SOP.SListI results
233− , Has tab schema ('Table table)
235+ , HasQualified sch tab db schema ('Table table)
234236 , row ~ TableToRow table
235237 , columns ~ TableToColumns table )
236− => Alias tab -- ^ table to insert into
237− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
238− -> [NP (Aliased (ColumnValue schema '[] params)) columns] -- ^ more rows to insert
239− -> ConflictClause schema table params
238+ => QualifiedAlias sch tab -- ^ table to insert into
239+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
240+ -> [NP (Aliased (ColumnValue db '[] params)) columns] -- ^ more rows to insert
241+ -> ConflictClause db table params
240242 -- ^ what to do in case of constraint conflict
241− -> ReturningClause schema params row results -- ^ results to return
242− -> Manipulation schema params results
243+ -> ReturningClause db params row results -- ^ results to return
244+ -> Manipulation db params results
243245insertRows tab rw rws conflict returning = UnsafeManipulation $
244− "INSERT" <+> "INTO" <+> renderAlias tab
246+ "INSERT" <+> "INTO" <+> renderQualifiedAlias tab
245247 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
246248 <+> "VALUES"
247249 <+> commaSeparated
@@ -261,54 +263,54 @@ insertRows tab rw rws conflict returning = UnsafeManipulation $
261263insertRow
262264 :: ( SOP.SListI columns
263265 , SOP.SListI results
264− , Has tab schema ('Table table)
266+ , HasQualified sch tab db schema ('Table table)
265267 , row ~ TableToRow table
266268 , columns ~ TableToColumns table )
267− => Alias tab -- ^ table to insert into
268− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
269− -> ConflictClause schema table params
269+ => QualifiedAlias sch tab -- ^ table to insert into
270+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
271+ -> ConflictClause db table params
270272 -- ^ what to do in case of constraint conflict
271− -> ReturningClause schema params row results -- ^ results to return
272− -> Manipulation schema params results
273+ -> ReturningClause db params row results -- ^ results to return
274+ -> Manipulation db params results
273275insertRow tab rw = insertRows tab rw []
274276
275277-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
276278insertRows_
277279 :: ( SOP.SListI columns
278− , Has tab schema ('Table table)
280+ , HasQualified sch tab db schema ('Table table)
279281 , columns ~ TableToColumns table )
280− => Alias tab -- ^ table to insert into
281− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
282− -> [NP (Aliased (ColumnValue schema '[] params)) columns] -- ^ more rows to insert
283− -> Manipulation schema params '[]
282+ => QualifiedAlias sch tab -- ^ table to insert into
283+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
284+ -> [NP (Aliased (ColumnValue db '[] params)) columns] -- ^ more rows to insert
285+ -> Manipulation db params '[]
284286insertRows_ tab rw rws =
285287 insertRows tab rw rws OnConflictDoRaise (Returning Nil)
286288
287289-- | Insert a single row returning `Nil` and raising an error on conflicts.
288290insertRow_
289291 :: ( SOP.SListI columns
290− , Has tab schema ('Table table)
292+ , HasQualified sch tab db schema ('Table table)
291293 , columns ~ TableToColumns table )
292− => Alias tab -- ^ table to insert into
293− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
294− -> Manipulation schema params '[]
294+ => QualifiedAlias sch tab -- ^ table to insert into
295+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
296+ -> Manipulation db params '[]
295297insertRow_ tab rw = insertRow tab rw OnConflictDoRaise (Returning Nil)
296298
297299-- | Insert a `Query`.
298300insertQuery
299301 :: ( SOP.SListI columns
300302 , SOP.SListI results
301− , Has tab schema ('Table table)
303+ , HasQualified sch tab db schema ('Table table)
302304 , row ~ TableToRow table
303305 , columns ~ TableToColumns table )
304− => Alias tab -- ^ table to insert into
305− -> Query schema params (TableToRow table)
306− -> ConflictClause schema table params
306+ => QualifiedAlias sch tab -- ^ table to insert into
307+ -> Query db params (TableToRow table)
308+ -> ConflictClause db table params
307309 -- ^ what to do in case of constraint conflict
308− -> ReturningClause schema params row results -- ^ results to return
309− -> Manipulation schema params results
310+ -> ReturningClause db params row results -- ^ results to return
311+ -> Manipulation db params results
310312insertQuery tab query conflict returning = UnsafeManipulation $
311− "INSERT" <+> "INTO" <+> renderAlias tab
313+ "INSERT" <+> "INTO" <+> renderQualifiedAlias tab
312314 <+> renderQuery query
313315 <> renderConflictClause conflict
314316 <> renderReturningClause returning
@@ -316,11 +318,11 @@ insertQuery tab query conflict returning = UnsafeManipulation $
316318-- | Insert a `Query` returning `Nil` and raising an error on conflicts.
317319insertQuery_
318320 :: ( SOP.SListI columns
319− , Has tab schema ('Table table)
321+ , HasQualified sch tab db schema ('Table table)
320322 , columns ~ TableToColumns table )
321− => Alias tab -- ^ table to insert into
322− -> Query schema params (TableToRow table)
323− -> Manipulation schema params '[]
323+ => QualifiedAlias sch tab -- ^ table to insert into
324+ -> Query db params (TableToRow table)
325+ -> Manipulation db params '[]
324326insertQuery_ tab query =
325327 insertQuery tab query OnConflictDoRaise (Returning Nil)
326328
@@ -330,16 +332,16 @@ insertQuery_ tab query =
330332-- `Set` sets a value to be an `Expression`, which can refer to
331333-- existing value in the row for an update.
332334data ColumnValue
333− (schema :: SchemaType)
335+ (db :: DBType)
334336 (columns :: RowType)
335337 (params :: [NullityType])
336338 (ty :: ColumnType)
337339 where
338− Same :: ColumnValue schema (column ': columns) params ty
339− Default :: ColumnValue schema columns params ('Def :=> ty)
340+ Same :: ColumnValue db (column ': columns) params ty
341+ Default :: ColumnValue db columns params ('Def :=> ty)
340342 Set
341− :: (forall table. Expression schema '[table ::: columns] 'Ungrouped params ty)
342− -> ColumnValue schema columns params (constraint :=> ty)
343+ :: (forall table. Expression db '[table ::: columns] 'Ungrouped params ty)
344+ -> ColumnValue db columns params (constraint :=> ty)
343345
344346-- | A `ReturningClause` computes and return value(s) based
345347-- on each row actually inserted, updated or deleted. This is primarily
@@ -352,16 +354,16 @@ data ColumnValue
352354-- in the row. Use @Returning Nil@ in the common case where no return
353355-- values are desired.
354356data ReturningClause
355− (schema :: SchemaType)
357+ (db :: DBType)
356358 (params :: [NullityType])
357359 (row0 :: RowType)
358360 (row1 :: RowType)
359361 where
360362 ReturningStar
361− :: ReturningClause schema params row row
363+ :: ReturningClause db params row row
362364 Returning
363− :: NP (Aliased (Expression schema '[table ::: row0] 'Ungrouped params)) row1
364− -> ReturningClause schema params row0 row1
365+ :: NP (Aliased (Expression db '[table ::: row0] 'Ungrouped params)) row1
366+ -> ReturningClause db params row0 row1
365367
366368-- | Render a `ReturningClause`.
367369renderReturningClause
@@ -380,16 +382,16 @@ renderReturningClause = \case
380382-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
381383-- proposed for insertion.
382384data ConflictClause
383− (schema :: SchemaType)
385+ (db :: DBType)
384386 (table :: TableType)
385387 (params :: [NullityType]) where
386− OnConflictDoRaise :: ConflictClause schema table params
387− OnConflictDoNothing :: ConflictClause schema table params
388+ OnConflictDoRaise :: ConflictClause db table params
389+ OnConflictDoNothing :: ConflictClause db table params
388390 OnConflictDoUpdate
389391 :: (row ~ TableToRow table, columns ~ TableToColumns table)
390− => NP (Aliased (ColumnValue schema row params)) columns
391− -> [Condition schema '[t ::: row] 'Ungrouped params]
392− -> ConflictClause schema table params
392+ => NP (Aliased (ColumnValue db row params)) columns
393+ -> [Condition db '[t ::: row] 'Ungrouped params]
394+ -> ConflictClause db table params
393395
394396-- | Render a `ConflictClause`.
395397renderConflictClause
@@ -425,19 +427,19 @@ UPDATE statements
425427update
426428 :: ( SOP.SListI columns
427429 , SOP.SListI results
428− , Has tab schema ('Table table)
430+ , HasQualified sch tab db schema ('Table table)
429431 , row ~ TableToRow table
430432 , columns ~ TableToColumns table )
431− => Alias tab -- ^ table to update
432− -> NP (Aliased (ColumnValue schema row params)) columns
433+ => QualifiedAlias sch tab -- ^ table to update
434+ -> NP (Aliased (ColumnValue db row params)) columns
433435 -- ^ modified values to replace old values
434− -> (forall t. Condition schema '[t ::: row] 'Ungrouped params)
436+ -> (forall t. Condition db '[t ::: row] 'Ungrouped params)
435437 -- ^ condition under which to perform update on a row
436− -> ReturningClause schema params row results -- ^ results to return
437− -> Manipulation schema params results
438+ -> ReturningClause db params row results -- ^ results to return
439+ -> Manipulation db params results
438440update tab columns wh returning = UnsafeManipulation $
439441 "UPDATE"
440− <+> renderAlias tab
442+ <+> renderQualifiedAlias tab
441443 <+> "SET"
442444 <+> renderCommaSeparatedMaybe renderUpdate columns
443445 <+> "WHERE" <+> renderExpression wh
@@ -456,15 +458,15 @@ update tab columns wh returning = UnsafeManipulation $
456458-- | Update a row returning `Nil`.
457459update_
458460 :: ( SOP.SListI columns
459− , Has tab schema ('Table table)
461+ , HasQualified sch tab db schema ('Table table)
460462 , row ~ TableToRow table
461463 , columns ~ TableToColumns table )
462− => Alias tab -- ^ table to update
463− -> NP (Aliased (ColumnValue schema row params)) columns
464+ => QualifiedAlias sch tab -- ^ table to update
465+ -> NP (Aliased (ColumnValue db row params)) columns
464466 -- ^ modified values to replace old values
465− -> (forall t. Condition schema '[t ::: row] 'Ungrouped params)
467+ -> (forall t. Condition db '[t ::: row] 'Ungrouped params)
466468 -- ^ condition under which to perform update on a row
467− -> Manipulation schema params '[]
469+ -> Manipulation db params '[]
468470update_ tab columns wh = update tab columns wh (Returning Nil)
469471
470472{-----------------------------------------
@@ -474,26 +476,26 @@ DELETE statements
474476-- | Delete rows of a table.
475477deleteFrom
476478 :: ( SOP.SListI results
477− , Has tab schema ('Table table)
479+ , HasQualified sch tab db schema ('Table table)
478480 , row ~ TableToRow table
479481 , columns ~ TableToColumns table )
480− => Alias tab -- ^ table to delete from
481− -> Condition schema '[tab ::: row] 'Ungrouped params
482+ => QualifiedAlias sch tab -- ^ table to delete from
483+ -> Condition db '[tab ::: row] 'Ungrouped params
482484 -- ^ condition under which to delete a row
483− -> ReturningClause schema params row results -- ^ results to return
484− -> Manipulation schema params results
485+ -> ReturningClause db params row results -- ^ results to return
486+ -> Manipulation db params results
485487deleteFrom tab wh returning = UnsafeManipulation $
486− "DELETE FROM" <+> renderAlias tab
488+ "DELETE FROM" <+> renderQualifiedAlias tab
487489 <+> "WHERE" <+> renderExpression wh
488490 <> renderReturningClause returning
489491
490492-- | Delete rows returning `Nil`.
491493deleteFrom_
492− :: ( Has tab schema ('Table table)
494+ :: ( HasQualified sch tab db schema ('Table table)
493495 , row ~ TableToRow table
494496 , columns ~ TableToColumns table )
495− => Alias tab -- ^ table to delete from
496− -> (forall t. Condition schema '[t ::: row] 'Ungrouped params)
497+ => QualifiedAlias sch tab -- ^ table to delete from
498+ -> (forall t. Condition db '[t ::: row] 'Ungrouped params)
497499 -- ^ condition under which to delete a row
498− -> Manipulation schema params '[]
500+ -> Manipulation db params '[]
499501deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+90−86
@@ -47,7 +47,7 @@ module Squeal.PostgreSQL.Query
4747 , except
4848 , exceptAll
4949 -- ** With
50− , With (with)
50+ -- , With (with)
5151 , CommonTableExpression (..)
5252 , renderCommonTableExpression
5353 , renderCommonTableExpressions
@@ -357,19 +357,19 @@ in printSQL query
357357WITH "t2" AS (SELECT * FROM "t1" AS "t1"), "t3" AS (SELECT * FROM "t2" AS "t2") SELECT * FROM "t3" AS "t3"
358358-}
359359newtype Query
360− (schema :: SchemaType)
360+ (db :: DBType)
361361 (params :: [NullityType])
362362 (columns :: RowType)
363363 = UnsafeQuery { renderQuery :: ByteString }
364364 deriving (GHC.Generic,Show,Eq,Ord,NFData)
365−instance RenderSQL (Query schema params columns) where renderSQL = renderQuery
365+instance RenderSQL (Query db params columns) where renderSQL = renderQuery
366366
367367-- | The results of two queries can be combined using the set operation
368368-- `union`. Duplicate rows are eliminated.
369369union
370− :: Query schema params columns
371− -> Query schema params columns
372− -> Query schema params columns
370+ :: Query db params columns
371+ -> Query db params columns
372+ -> Query db params columns
373373q1 `union` q2 = UnsafeQuery $
374374 parenthesized (renderQuery q1)
375375 <+> "UNION"
@@ -378,9 +378,9 @@ q1 `union` q2 = UnsafeQuery $
378378-- | The results of two queries can be combined using the set operation
379379-- `unionAll`, the disjoint union. Duplicate rows are retained.
380380unionAll
381− :: Query schema params columns
382− -> Query schema params columns
383− -> Query schema params columns
381+ :: Query db params columns
382+ -> Query db params columns
383+ -> Query db params columns
384384q1 `unionAll` q2 = UnsafeQuery $
385385 parenthesized (renderQuery q1)
386386 <+> "UNION" <+> "ALL"
@@ -389,9 +389,9 @@ q1 `unionAll` q2 = UnsafeQuery $
389389-- | The results of two queries can be combined using the set operation
390390-- `intersect`, the intersection. Duplicate rows are eliminated.
391391intersect
392− :: Query schema params columns
393− -> Query schema params columns
394− -> Query schema params columns
392+ :: Query db params columns
393+ -> Query db params columns
394+ -> Query db params columns
395395q1 `intersect` q2 = UnsafeQuery $
396396 parenthesized (renderQuery q1)
397397 <+> "INTERSECT"
@@ -400,9 +400,9 @@ q1 `intersect` q2 = UnsafeQuery $
400400-- | The results of two queries can be combined using the set operation
401401-- `intersectAll`, the intersection. Duplicate rows are retained.
402402intersectAll
403− :: Query schema params columns
404− -> Query schema params columns
405− -> Query schema params columns
403+ :: Query db params columns
404+ -> Query db params columns
405+ -> Query db params columns
406406q1 `intersectAll` q2 = UnsafeQuery $
407407 parenthesized (renderQuery q1)
408408 <+> "INTERSECT" <+> "ALL"
@@ -411,9 +411,9 @@ q1 `intersectAll` q2 = UnsafeQuery $
411411-- | The results of two queries can be combined using the set operation
412412-- `except`, the set difference. Duplicate rows are eliminated.
413413except
414− :: Query schema params columns
415− -> Query schema params columns
416− -> Query schema params columns
414+ :: Query db params columns
415+ -> Query db params columns
416+ -> Query db params columns
417417q1 `except` q2 = UnsafeQuery $
418418 parenthesized (renderQuery q1)
419419 <+> "EXCEPT"
@@ -422,9 +422,9 @@ q1 `except` q2 = UnsafeQuery $
422422-- | The results of two queries can be combined using the set operation
423423-- `exceptAll`, the set difference. Duplicate rows are retained.
424424exceptAll
425− :: Query schema params columns
426− -> Query schema params columns
427− -> Query schema params columns
425+ :: Query db params columns
426+ -> Query db params columns
427+ -> Query db params columns
428428q1 `exceptAll` q2 = UnsafeQuery $
429429 parenthesized (renderQuery q1)
430430 <+> "EXCEPT" <+> "ALL"
@@ -440,12 +440,12 @@ SELECT queries
440440-- the select list. The select list determines which columns of
441441-- the intermediate table are actually output.
442442select
443− :: SListI columns
444− => NP (Aliased (Expression schema from grouping params)) (column ': columns)
443+ :: (SListI columns, columns ~ (col ': cols))
444+ => NP (Aliased (Expression db from grouping params)) columns
445445 -- ^ select list
446− -> TableExpression schema params from grouping
446+ -> TableExpression db params from grouping
447447 -- ^ intermediate virtual table
448− -> Query schema params (column ': columns)
448+ -> Query db params columns
449449select list rels = UnsafeQuery $
450450 "SELECT"
451451 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
@@ -454,12 +454,12 @@ select list rels = UnsafeQuery $
454454-- | After the select list has been processed, the result table can
455455-- be subject to the elimination of duplicate rows using `selectDistinct`.
456456selectDistinct
457− :: SListI columns
458− => NP (Aliased (Expression schema from 'Ungrouped params)) (column ': columns)
457+ :: (SListI columns, columns ~ (col ': cols))
458+ => NP (Aliased (Expression db from 'Ungrouped params)) columns
459459 -- ^ select list
460− -> TableExpression schema params from 'Ungrouped
460+ -> TableExpression db params from 'Ungrouped
461461 -- ^ intermediate virtual table
462− -> Query schema params (column ': columns)
462+ -> Query db params columns
463463selectDistinct list rels = UnsafeQuery $
464464 "SELECT DISTINCT"
465465 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
@@ -471,7 +471,7 @@ selectStar
471471 :: HasUnique table from columns
472472 => TableExpression schema params from 'Ungrouped
473473 -- ^ intermediate virtual table
474− -> Query schema params columns
474+ -> Query db params columns
475475selectStar rels = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression rels
476476
477477-- | A `selectDistinctStar` emits all columns that the table expression
@@ -480,7 +480,7 @@ selectDistinctStar
480480 :: HasUnique table from columns
481481 => TableExpression schema params from 'Ungrouped
482482 -- ^ intermediate virtual table
483− -> Query schema params columns
483+ -> Query db params columns
484484selectDistinctStar rels = UnsafeQuery $
485485 "SELECT DISTINCT" <+> "*" <+> renderTableExpression rels
486486
@@ -492,7 +492,7 @@ selectDotStar
492492 -- ^ particular virtual subtable
493493 -> TableExpression schema params from 'Ungrouped
494494 -- ^ intermediate virtual table
495− -> Query schema params columns
495+ -> Query db params columns
496496selectDotStar rel tab = UnsafeQuery $
497497 "SELECT" <+> renderAlias rel <> ".*" <+> renderTableExpression tab
498498
@@ -504,7 +504,7 @@ selectDistinctDotStar
504504 -- ^ particular virtual table
505505 -> TableExpression schema params from 'Ungrouped
506506 -- ^ intermediate virtual table
507− -> Query schema params columns
507+ -> Query db params columns
508508selectDistinctDotStar rel tab = UnsafeQuery $
509509 "SELECT DISTINCT" <+> renderAlias rel <> ".*"
510510 <+> renderTableExpression tab
@@ -524,7 +524,7 @@ values
524524 -> [NP (Aliased (Expression schema '[] 'Ungrouped params)) cols]
525525 -- ^ When more than one row is specified, all the rows must
526526 -- must have the same number of elements
527− -> Query schema params cols
527+ -> Query db params cols
528528values rw rws = UnsafeQuery $ "SELECT * FROM"
529529 <+> parenthesized (
530530 "VALUES"
@@ -545,7 +545,7 @@ values_
545545 :: SListI cols
546546 => NP (Aliased (Expression schema '[] 'Ungrouped params)) cols
547547 -- ^ one row of values
548− -> Query schema params cols
548+ -> Query db params cols
549549values_ rw = values rw []
550550
551551{-----------------------------------------
@@ -559,15 +559,15 @@ Table Expressions
559559-- to a table on disk, a so-called base table, but more complex expressions
560560-- can be used to modify or combine base tables in various ways.
561561data TableExpression
562− (schema :: SchemaType)
562+ (db :: DBType)
563563 (params :: [NullityType])
564564 (from :: FromType)
565565 (grouping :: Grouping)
566566 = TableExpression
567− { fromClause :: FromClause schema params from
567+ { fromClause :: FromClause db params from
568568 -- ^ A table reference that can be a table name, or a derived table such
569569 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
570− , whereClause :: [Condition schema from 'Ungrouped params]
570+ , whereClause :: [Condition db from 'Ungrouped params]
571571 -- ^ optional search coditions, combined with `.&&`. After the processing
572572 -- of the `fromClause` is done, each row of the derived virtual table
573573 -- is checked against the search condition. If the result of the
@@ -583,13 +583,13 @@ data TableExpression
583583 -- set of rows having common values into one group row that represents all
584584 -- rows in the group. This is done to eliminate redundancy in the output
585585 -- and/or compute aggregates that apply to these groups.
586− , havingClause :: HavingClause schema from grouping params
586+ , havingClause :: HavingClause db from grouping params
587587 -- ^ If a table has been grouped using `groupBy`, but only certain groups
588588 -- are of interest, the `havingClause` can be used, much like a
589589 -- `whereClause`, to eliminate groups from the result. Expressions in the
590590 -- `havingClause` can refer both to grouped expressions and to ungrouped
591591 -- expressions (which necessarily involve an aggregate function).
592− , orderByClause :: [SortExpression schema from grouping params]
592+ , orderByClause :: [SortExpression db from grouping params]
593593 -- ^ The `orderByClause` is for optional sorting. When more than one
594594 -- `SortExpression` is specified, the later (right) values are used to sort
595595 -- rows that are equal according to the earlier (left) values.
@@ -711,55 +711,55 @@ JSON stuff
711711unsafeSetOfFunction
712712 :: ByteString
713713 -> Expression schema '[] 'Ungrouped params ty
714− -> Query schema params row
714+ -> Query db params row
715715unsafeSetOfFunction fun expr = UnsafeQuery $
716716 "SELECT * FROM " <> fun <> "(" <> renderExpression expr <> ")"
717717
718718-- | Expands the outermost JSON object into a set of key/value pairs.
719719jsonEach
720720 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
721− -> Query schema params
721+ -> Query db params
722722 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
723723jsonEach = unsafeSetOfFunction "json_each"
724724
725725-- | Expands the outermost binary JSON object into a set of key/value pairs.
726726jsonbEach
727727 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
728− -> Query schema params
728+ -> Query db params
729729 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
730730jsonbEach = unsafeSetOfFunction "jsonb_each"
731731
732732-- | Expands the outermost JSON object into a set of key/value pairs.
733733jsonEachAsText
734734 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
735− -> Query schema params
735+ -> Query db params
736736 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
737737jsonEachAsText = unsafeSetOfFunction "json_each_text"
738738
739739-- | Expands the outermost binary JSON object into a set of key/value pairs.
740740jsonbEachAsText
741741 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
742− -> Query schema params
742+ -> Query db params
743743 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
744744jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
745745
746746-- | Returns set of keys in the outermost JSON object.
747747jsonObjectKeys
748748 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
749− -> Query schema params '["json_object_keys" ::: 'NotNull 'PGtext]
749+ -> Query db params '["json_object_keys" ::: 'NotNull 'PGtext]
750750jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
751751
752752-- | Returns set of keys in the outermost JSON object.
753753jsonbObjectKeys
754754 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
755− -> Query schema params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
755+ -> Query db params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
756756jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
757757
758758unsafePopulateFunction
759759 :: ByteString
760760 -> TypeExpression schema (nullity ('PGcomposite row))
761761 -> Expression schema '[] 'Ungrouped params ty
762− -> Query schema params row
762+ -> Query db params row
763763unsafePopulateFunction fun ty expr = UnsafeQuery $
764764 "SELECT * FROM " <> fun <> "("
765765 <> "null::" <> renderTypeExpression ty <> ", "
@@ -770,7 +770,7 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
770770jsonPopulateRecord
771771 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
772772 -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
773− -> Query schema params row
773+ -> Query db params row
774774jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
775775
776776-- | Expands the binary JSON expression to a row whose columns match the record
@@ -778,7 +778,7 @@ jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
778778jsonbPopulateRecord
779779 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
780780 -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
781− -> Query schema params row
781+ -> Query db params row
782782jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
783783
784784-- | Expands the outermost array of objects in the given JSON expression to a
@@ -786,7 +786,7 @@ jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
786786jsonPopulateRecordSet
787787 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
788788 -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
789− -> Query schema params row
789+ -> Query db params row
790790jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
791791
792792-- | Expands the outermost array of objects in the given binary JSON expression
@@ -795,7 +795,7 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
795795jsonbPopulateRecordSet
796796 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
797797 -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
798− -> Query schema params row
798+ -> Query db params row
799799jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
800800
801801unsafeRecordFunction
@@ -803,7 +803,7 @@ unsafeRecordFunction
803803 => ByteString
804804 -> Expression schema '[] 'Ungrouped params (nullity json)
805805 -> NP (Aliased (TypeExpression schema)) record
806− -> Query schema params record
806+ -> Query db params record
807807unsafeRecordFunction fun expr types = UnsafeQuery $
808808 "SELECT * FROM " <> fun <> "("
809809 <> renderExpression expr <> ")"
@@ -818,7 +818,7 @@ jsonToRecord
818818 :: SListI record
819819 => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
820820 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
821− -> Query schema params record
821+ -> Query db params record
822822jsonToRecord = unsafeRecordFunction "json_to_record"
823823
824824-- | Builds an arbitrary record from a binary JSON object.
@@ -826,7 +826,7 @@ jsonbToRecord
826826 :: SListI record
827827 => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
828828 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
829− -> Query schema params record
829+ -> Query db params record
830830jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
831831
832832-- | Builds an arbitrary set of records from a JSON array of objects.
@@ -834,7 +834,7 @@ jsonToRecordSet
834834 :: SListI record
835835 => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
836836 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
837− -> Query schema params record
837+ -> Query db params record
838838jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
839839
840840-- | Builds an arbitrary set of records from a binary JSON array of objects.
@@ -842,7 +842,7 @@ jsonbToRecordSet
842842 :: SListI record
843843 => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
844844 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
845− -> Query schema params record
845+ -> Query db params record
846846jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
847847
848848{-----------------------------------------
@@ -867,7 +867,7 @@ table (tab `As` alias) = UnsafeFromClause $
867867
868868-- | `subquery` derives a table from a `Query`.
869869subquery
870− :: Aliased (Query schema params) rel
870+ :: Aliased (Query db params) rel
871871 -> FromClause schema params '[rel]
872872subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
873873
@@ -1094,7 +1094,7 @@ renderSortExpression = \case
10941094unsafeSubqueryExpression
10951095 :: ByteString
10961096 -> Expression schema from grp params ty
1097− -> Query schema params '[alias ::: ty]
1097+ -> Query db params '[alias ::: ty]
10981098 -> Expression schema from grp params (nullity 'PGbool)
10991099unsafeSubqueryExpression op x q = UnsafeExpression $
11001100 renderExpression x <+> op <+> parenthesized (renderQuery q)
@@ -1103,7 +1103,7 @@ unsafeRowSubqueryExpression
11031103 :: SListI row
11041104 => ByteString
11051105 -> NP (Aliased (Expression schema from grp params)) row
1106− -> Query schema params row
1106+ -> Query db params row
11071107 -> Expression schema from grp params (nullity 'PGbool)
11081108unsafeRowSubqueryExpression op xs q = UnsafeExpression $
11091109 renderExpression (row xs) <+> op <+> parenthesized (renderQuery q)
@@ -1118,7 +1118,7 @@ unsafeRowSubqueryExpression op xs q = UnsafeExpression $
11181118-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11191119in_
11201120 :: Expression schema from grp params ty -- ^ expression
1121− -> Query schema params '[alias ::: ty] -- ^ subquery
1121+ -> Query db params '[alias ::: ty] -- ^ subquery
11221122 -> Expression schema from grp params (nullity 'PGbool)
11231123in_ = unsafeSubqueryExpression "IN"
11241124
@@ -1139,7 +1139,7 @@ ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11391139rowIn
11401140 :: SListI row
11411141 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1142− -> Query schema params row -- ^ subquery
1142+ -> Query db params row -- ^ subquery
11431143 -> Expression schema from grp params (nullity 'PGbool)
11441144rowIn = unsafeRowSubqueryExpression "IN"
11451145
@@ -1147,7 +1147,7 @@ rowIn = unsafeRowSubqueryExpression "IN"
11471147-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11481148eqAll
11491149 :: Expression schema from grp params ty -- ^ expression
1150− -> Query schema params '[alias ::: ty] -- ^ subquery
1150+ -> Query db params '[alias ::: ty] -- ^ subquery
11511151 -> Expression schema from grp params (nullity 'PGbool)
11521152eqAll = unsafeSubqueryExpression "= ALL"
11531153
@@ -1157,7 +1157,7 @@ eqAll = unsafeSubqueryExpression "= ALL"
11571157rowEqAll
11581158 :: SListI row
11591159 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1160− -> Query schema params row -- ^ subquery
1160+ -> Query db params row -- ^ subquery
11611161 -> Expression schema from grp params (nullity 'PGbool)
11621162rowEqAll = unsafeRowSubqueryExpression "= ALL"
11631163
@@ -1165,7 +1165,7 @@ rowEqAll = unsafeRowSubqueryExpression "= ALL"
11651165-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11661166eqAny
11671167 :: Expression schema from grp params ty -- ^ expression
1168− -> Query schema params '[alias ::: ty] -- ^ subquery
1168+ -> Query db params '[alias ::: ty] -- ^ subquery
11691169 -> Expression schema from grp params (nullity 'PGbool)
11701170eqAny = unsafeSubqueryExpression "= ANY"
11711171
@@ -1175,7 +1175,7 @@ eqAny = unsafeSubqueryExpression "= ANY"
11751175rowEqAny
11761176 :: SListI row
11771177 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1178− -> Query schema params row -- ^ subquery
1178+ -> Query db params row -- ^ subquery
11791179 -> Expression schema from grp params (nullity 'PGbool)
11801180rowEqAny = unsafeRowSubqueryExpression "= ANY"
11811181
@@ -1183,7 +1183,7 @@ rowEqAny = unsafeRowSubqueryExpression "= ANY"
11831183-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11841184neqAll
11851185 :: Expression schema from grp params ty -- ^ expression
1186− -> Query schema params '[alias ::: ty] -- ^ subquery
1186+ -> Query db params '[alias ::: ty] -- ^ subquery
11871187 -> Expression schema from grp params (nullity 'PGbool)
11881188neqAll = unsafeSubqueryExpression "<> ALL"
11891189
@@ -1193,7 +1193,7 @@ neqAll = unsafeSubqueryExpression "<> ALL"
11931193rowNeqAll
11941194 :: SListI row
11951195 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1196− -> Query schema params row -- ^ subquery
1196+ -> Query db params row -- ^ subquery
11971197 -> Expression schema from grp params (nullity 'PGbool)
11981198rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
11991199
@@ -1201,7 +1201,7 @@ rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
12011201-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12021202neqAny
12031203 :: Expression schema from grp params ty -- ^ expression
1204− -> Query schema params '[alias ::: ty] -- ^ subquery
1204+ -> Query db params '[alias ::: ty] -- ^ subquery
12051205 -> Expression schema from grp params (nullity 'PGbool)
12061206neqAny = unsafeSubqueryExpression "<> ANY"
12071207
@@ -1211,7 +1211,7 @@ neqAny = unsafeSubqueryExpression "<> ANY"
12111211rowNeqAny
12121212 :: SListI row
12131213 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1214− -> Query schema params row -- ^ subquery
1214+ -> Query db params row -- ^ subquery
12151215 -> Expression schema from grp params (nullity 'PGbool)
12161216rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
12171217
@@ -1219,7 +1219,7 @@ rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
12191219-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12201220allLt
12211221 :: Expression schema from grp params ty -- ^ expression
1222− -> Query schema params '[alias ::: ty] -- ^ subquery
1222+ -> Query db params '[alias ::: ty] -- ^ subquery
12231223 -> Expression schema from grp params (nullity 'PGbool)
12241224allLt = unsafeSubqueryExpression "ALL <"
12251225
@@ -1229,7 +1229,7 @@ allLt = unsafeSubqueryExpression "ALL <"
12291229rowLtAll
12301230 :: SListI row
12311231 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1232− -> Query schema params row -- ^ subquery
1232+ -> Query db params row -- ^ subquery
12331233 -> Expression schema from grp params (nullity 'PGbool)
12341234rowLtAll = unsafeRowSubqueryExpression "ALL <"
12351235
@@ -1237,7 +1237,7 @@ rowLtAll = unsafeRowSubqueryExpression "ALL <"
12371237-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12381238ltAny
12391239 :: Expression schema from grp params ty -- ^ expression
1240− -> Query schema params '[alias ::: ty] -- ^ subquery
1240+ -> Query db params '[alias ::: ty] -- ^ subquery
12411241 -> Expression schema from grp params (nullity 'PGbool)
12421242ltAny = unsafeSubqueryExpression "ANY <"
12431243
@@ -1247,7 +1247,7 @@ ltAny = unsafeSubqueryExpression "ANY <"
12471247rowLtAny
12481248 :: SListI row
12491249 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1250− -> Query schema params row -- ^ subquery
1250+ -> Query db params row -- ^ subquery
12511251 -> Expression schema from grp params (nullity 'PGbool)
12521252rowLtAny = unsafeRowSubqueryExpression "ANY <"
12531253
@@ -1255,7 +1255,7 @@ rowLtAny = unsafeRowSubqueryExpression "ANY <"
12551255-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12561256lteAll
12571257 :: Expression schema from grp params ty -- ^ expression
1258− -> Query schema params '[alias ::: ty] -- ^ subquery
1258+ -> Query db params '[alias ::: ty] -- ^ subquery
12591259 -> Expression schema from grp params (nullity 'PGbool)
12601260lteAll = unsafeSubqueryExpression "<= ALL"
12611261
@@ -1265,7 +1265,7 @@ lteAll = unsafeSubqueryExpression "<= ALL"
12651265rowLteAll
12661266 :: SListI row
12671267 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1268− -> Query schema params row -- ^ subquery
1268+ -> Query db params row -- ^ subquery
12691269 -> Expression schema from grp params (nullity 'PGbool)
12701270rowLteAll = unsafeRowSubqueryExpression "<= ALL"
12711271
@@ -1273,7 +1273,7 @@ rowLteAll = unsafeRowSubqueryExpression "<= ALL"
12731273-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12741274lteAny
12751275 :: Expression schema from grp params ty -- ^ expression
1276− -> Query schema params '[alias ::: ty] -- ^ subquery
1276+ -> Query db params '[alias ::: ty] -- ^ subquery
12771277 -> Expression schema from grp params (nullity 'PGbool)
12781278lteAny = unsafeSubqueryExpression "<= ANY"
12791279
@@ -1283,7 +1283,7 @@ lteAny = unsafeSubqueryExpression "<= ANY"
12831283rowLteAny
12841284 :: SListI row
12851285 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1286− -> Query schema params row -- ^ subquery
1286+ -> Query db params row -- ^ subquery
12871287 -> Expression schema from grp params (nullity 'PGbool)
12881288rowLteAny = unsafeRowSubqueryExpression "<= ANY"
12891289
@@ -1291,7 +1291,7 @@ rowLteAny = unsafeRowSubqueryExpression "<= ANY"
12911291-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12921292gtAll
12931293 :: Expression schema from grp params ty -- ^ expression
1294− -> Query schema params '[alias ::: ty] -- ^ subquery
1294+ -> Query db params '[alias ::: ty] -- ^ subquery
12951295 -> Expression schema from grp params (nullity 'PGbool)
12961296gtAll = unsafeSubqueryExpression "> ALL"
12971297
@@ -1301,7 +1301,7 @@ gtAll = unsafeSubqueryExpression "> ALL"
13011301rowGtAll
13021302 :: SListI row
13031303 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1304− -> Query schema params row -- ^ subquery
1304+ -> Query db params row -- ^ subquery
13051305 -> Expression schema from grp params (nullity 'PGbool)
13061306rowGtAll = unsafeRowSubqueryExpression "> ALL"
13071307
@@ -1309,7 +1309,7 @@ rowGtAll = unsafeRowSubqueryExpression "> ALL"
13091309-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
13101310gtAny
13111311 :: Expression schema from grp params ty -- ^ expression
1312− -> Query schema params '[alias ::: ty] -- ^ subquery
1312+ -> Query db params '[alias ::: ty] -- ^ subquery
13131313 -> Expression schema from grp params (nullity 'PGbool)
13141314gtAny = unsafeSubqueryExpression "> ANY"
13151315
@@ -1319,7 +1319,7 @@ gtAny = unsafeSubqueryExpression "> ANY"
13191319rowGtAny
13201320 :: SListI row
13211321 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1322− -> Query schema params row -- ^ subquery
1322+ -> Query db params row -- ^ subquery
13231323 -> Expression schema from grp params (nullity 'PGbool)
13241324rowGtAny = unsafeRowSubqueryExpression "> ANY"
13251325
@@ -1327,7 +1327,7 @@ rowGtAny = unsafeRowSubqueryExpression "> ANY"
13271327-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
13281328gteAll
13291329 :: Expression schema from grp params ty -- ^ expression
1330− -> Query schema params '[alias ::: ty] -- ^ subquery
1330+ -> Query db params '[alias ::: ty] -- ^ subquery
13311331 -> Expression schema from grp params (nullity 'PGbool)
13321332gteAll = unsafeSubqueryExpression ">= ALL"
13331333
@@ -1337,7 +1337,7 @@ gteAll = unsafeSubqueryExpression ">= ALL"
13371337rowGteAll
13381338 :: SListI row
13391339 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1340− -> Query schema params row -- ^ subquery
1340+ -> Query db params row -- ^ subquery
13411341 -> Expression schema from grp params (nullity 'PGbool)
13421342rowGteAll = unsafeRowSubqueryExpression ">= ALL"
13431343
@@ -1345,7 +1345,7 @@ rowGteAll = unsafeRowSubqueryExpression ">= ALL"
13451345-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
13461346gteAny
13471347 :: Expression schema from grp params ty -- ^ expression
1348− -> Query schema params '[alias ::: ty] -- ^ subquery
1348+ -> Query db params '[alias ::: ty] -- ^ subquery
13491349 -> Expression schema from grp params (nullity 'PGbool)
13501350gteAny = unsafeSubqueryExpression ">= ANY"
13511351
@@ -1355,7 +1355,7 @@ gteAny = unsafeSubqueryExpression ">= ANY"
13551355rowGteAny
13561356 :: SListI row
13571357 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1358− -> Query schema params row -- ^ subquery
1358+ -> Query db params row -- ^ subquery
13591359 -> Expression schema from grp params (nullity 'PGbool)
13601360rowGteAny = unsafeRowSubqueryExpression ">= ANY"
13611361
@@ -1398,6 +1398,8 @@ renderCommonTableExpressions renderStatement cte ctes =
13981398 cte' :>> ctes' -> "," <+>
13991399 renderCommonTableExpressions renderStatement cte' ctes'
14001400
1401+{---------------FIX WITH
1402+
14011403-- | `with` provides a way to write auxiliary statements for use in a larger query.
14021404-- These statements, referred to as `CommonTableExpression`s, can be thought of as
14031405-- defining temporary tables that exist just for one query.
@@ -1413,3 +1415,5 @@ instance With Query where
14131415 with (cte :>> ctes) query = UnsafeQuery $
14141416 "WITH" <+> renderCommonTableExpressions renderQuery cte ctes
14151417 <+> renderQuery query
1418+
1419+-}