on dev help sign in
work more thru
ec70c9fEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+37−34
@@ -53,7 +53,7 @@ module Squeal.PostgreSQL.Definition
53 , AlterTable (UnsafeAlterTable, renderAlterTable)
53 , AlterTable (UnsafeAlterTable, renderAlterTable)
54 , addConstraint
54 , addConstraint
55 , dropConstraint
55 , dropConstraint
56− , AddColumn (addColumn)
56+ -- , AddColumn (addColumn)
57 , dropColumn
57 , dropColumn
58 , renameColumn
58 , renameColumn
59 , alterColumn
59 , alterColumn
@@ -153,9 +153,9 @@ createTable
153 , schema1 ~ Create table ('Table (constraints :=> columns)) schema0
153 , schema1 ~ Create table ('Table (constraints :=> columns)) schema0
154 , db1 ~ Alter sch schema1 db0 )
154 , db1 ~ Alter sch schema1 db0 )
155 => QualifiedAlias sch tab -- ^ the name of the table to add
155 => QualifiedAlias sch tab -- ^ the name of the table to add
156− -> NP (Aliased (ColumnTypeExpression schema0)) columns
156+ -> NP (Aliased (ColumnTypeExpression db0)) columns
157 -- ^ the names and datatype of each column
157 -- ^ the names and datatype of each column
158− -> NP (Aliased (TableConstraintExpression schema1 table)) constraints
158+ -> NP (Aliased (TableConstraintExpression db1 table)) constraints
159 -- ^ constraints that must hold for the table
159 -- ^ constraints that must hold for the table
160 -> Definition db0 db1
160 -> Definition db0 db1
161createTable tab columns constraints = UnsafeDefinition $
161createTable tab columns constraints = UnsafeDefinition $
@@ -189,9 +189,9 @@ createTableIfNotExists
189 , SOP.SListI columns
189 , SOP.SListI columns
190 , SOP.SListI constraints )
190 , SOP.SListI constraints )
191 => QualifiedAlias sch tab -- ^ the name of the table to add
191 => QualifiedAlias sch tab -- ^ the name of the table to add
192− -> NP (Aliased (ColumnTypeExpression schema)) columns
192+ -> NP (Aliased (ColumnTypeExpression db)) columns
193 -- ^ the names and datatype of each column
193 -- ^ the names and datatype of each column
194− -> NP (Aliased (TableConstraintExpression schema table)) constraints
194+ -> NP (Aliased (TableConstraintExpression db table)) constraints
195 -- ^ constraints that must hold for the table
195 -- ^ constraints that must hold for the table
196 -> Definition db db
196 -> Definition db db
197createTableIfNotExists tab columns constraints = UnsafeDefinition $
197createTableIfNotExists tab columns constraints = UnsafeDefinition $
@@ -241,7 +241,7 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
241-- violate a constraint, an error is raised. This applies
241-- violate a constraint, an error is raised. This applies
242-- even if the value came from the default value definition.
242-- even if the value came from the default value definition.
243newtype TableConstraintExpression
243newtype TableConstraintExpression
244− (schema :: SchemaType)
244+ (db :: DBType)
245 (table :: Symbol)
245 (table :: Symbol)
246 (tableConstraint :: TableConstraint)
246 (tableConstraint :: TableConstraint)
247 = UnsafeTableConstraintExpression
247 = UnsafeTableConstraintExpression
@@ -273,13 +273,13 @@ let
273CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
273CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
274-}
274-}
275check
275check
276− :: ( Has alias schema ('Table table)
276+ :: ( HasQualified sch tab db schema ('Table table)
277 , HasAll aliases (TableToRow table) subcolumns )
277 , HasAll aliases (TableToRow table) subcolumns )
278 => NP Alias aliases
278 => NP Alias aliases
279 -- ^ specify the subcolumns which are getting checked
279 -- ^ specify the subcolumns which are getting checked
280− -> (forall tab. Condition schema '[tab ::: subcolumns] 'Ungrouped '[])
280+ -> (forall t. Condition db '[t ::: subcolumns] 'Ungrouped '[])
281 -- ^ a closed `Condition` on those subcolumns
281 -- ^ a closed `Condition` on those subcolumns
282− -> TableConstraintExpression schema alias ('Check aliases)
282+ -> TableConstraintExpression db tab ('Check aliases)
283check _cols condition = UnsafeTableConstraintExpression $
283check _cols condition = UnsafeTableConstraintExpression $
284 "CHECK" <+> parenthesized (renderExpression condition)
284 "CHECK" <+> parenthesized (renderExpression condition)
285
285
@@ -311,7 +311,7 @@ unique
311 , HasAll aliases (TableToRow table) subcolumns )
311 , HasAll aliases (TableToRow table) subcolumns )
312 => NP Alias aliases
312 => NP Alias aliases
313 -- ^ specify subcolumns which together are unique for each row
313 -- ^ specify subcolumns which together are unique for each row
314− -> TableConstraintExpression schema alias ('Unique aliases)
314+ -> TableConstraintExpression db alias ('Unique aliases)
315unique columns = UnsafeTableConstraintExpression $
315unique columns = UnsafeTableConstraintExpression $
316 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
316 "UNIQUE" <+> parenthesized (commaSeparated (renderAliases columns))
317
317
@@ -345,7 +345,7 @@ primaryKey
345 , AllNotNull subcolumns )
345 , AllNotNull subcolumns )
346 => NP Alias aliases
346 => NP Alias aliases
347 -- ^ specify the subcolumns which together form a primary key.
347 -- ^ specify the subcolumns which together form a primary key.
348− -> TableConstraintExpression schema alias ('PrimaryKey aliases)
348+ -> TableConstraintExpression db alias ('PrimaryKey aliases)
349primaryKey columns = UnsafeTableConstraintExpression $
349primaryKey columns = UnsafeTableConstraintExpression $
350 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
350 "PRIMARY KEY" <+> parenthesized (commaSeparated (renderAliases columns))
351
351
@@ -438,7 +438,7 @@ foreignKey
438 -- ^ what to do when reference is deleted
438 -- ^ what to do when reference is deleted
439 -> OnUpdateClause
439 -> OnUpdateClause
440 -- ^ what to do when reference is updated
440 -- ^ what to do when reference is updated
441− -> TableConstraintExpression schema child
441+ -> TableConstraintExpression db child
442 ('ForeignKey columns parent refcolumns)
442 ('ForeignKey columns parent refcolumns)
443foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
443foreignKey keys parent refs ondel onupd = UnsafeTableConstraintExpression $
444 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
444 "FOREIGN KEY" <+> parenthesized (commaSeparated (renderAliases keys))
@@ -529,7 +529,7 @@ ALTER statements
529alterTable
529alterTable
530 :: HasQualified sch tab db schema ('Table table0)
530 :: HasQualified sch tab db schema ('Table table0)
531 => QualifiedAlias sch tab -- ^ table to alter
531 => QualifiedAlias sch tab -- ^ table to alter
532− -> AlterTable tab table1 schema -- ^ alteration to perform
532+ -> AlterTable tab table1 db -- ^ alteration to perform
533 -> Definition db (Alter sch (Alter tab ('Table table1) schema) db)
533 -> Definition db (Alter sch (Alter tab ('Table table1) schema) db)
534alterTable tab alteration = UnsafeDefinition $
534alterTable tab alteration = UnsafeDefinition $
535 "ALTER TABLE"
535 "ALTER TABLE"
@@ -553,9 +553,9 @@ alterTableRename table0 table1 = UnsafeDefinition $
553-- | An `AlterTable` describes the alteration to perform on the columns
553-- | An `AlterTable` describes the alteration to perform on the columns
554-- of a table.
554-- of a table.
555newtype AlterTable
555newtype AlterTable
556− (alias :: Symbol)
556+ (tab :: Symbol)
557 (table :: TableType)
557 (table :: TableType)
558− (schema :: SchemaType) =
558+ (db :: DBType) =
559 UnsafeAlterTable {renderAlterTable :: ByteString}
559 UnsafeAlterTable {renderAlterTable :: ByteString}
560 deriving (GHC.Generic,Show,Eq,Ord,NFData)
560 deriving (GHC.Generic,Show,Eq,Ord,NFData)
561
561
@@ -576,9 +576,9 @@ addConstraint
576 , table0 ~ (constraints :=> columns)
576 , table0 ~ (constraints :=> columns)
577 , table1 ~ (Create alias constraint constraints :=> columns) )
577 , table1 ~ (Create alias constraint constraints :=> columns) )
578 => Alias alias
578 => Alias alias
579− -> TableConstraintExpression schema tab constraint
579+ -> TableConstraintExpression db tab constraint
580 -- ^ constraint to add
580 -- ^ constraint to add
581− -> AlterTable tab table1 schema
581+ -> AlterTable tab table1 db
582addConstraint alias constraint = UnsafeAlterTable $
582addConstraint alias constraint = UnsafeAlterTable $
583 "ADD" <+> "CONSTRAINT" <+> renderAlias alias
583 "ADD" <+> "CONSTRAINT" <+> renderAlias alias
584 <+> renderTableConstraintExpression constraint
584 <+> renderTableConstraintExpression constraint
@@ -601,10 +601,11 @@ dropConstraint
601 , table1 ~ (Drop constraint constraints :=> columns) )
601 , table1 ~ (Drop constraint constraints :=> columns) )
602 => Alias constraint
602 => Alias constraint
603 -- ^ constraint to drop
603 -- ^ constraint to drop
604− -> AlterTable tab table1 schema
604+ -> AlterTable tab table1 db
605dropConstraint constraint = UnsafeAlterTable $
605dropConstraint constraint = UnsafeAlterTable $
606 "DROP" <+> "CONSTRAINT" <+> renderAlias constraint
606 "DROP" <+> "CONSTRAINT" <+> renderAlias constraint
607
607
608+{---------FIX ADD COLUMN
608-- | An `AddColumn` is either @NULL@ or has @DEFAULT@.
609-- | An `AddColumn` is either @NULL@ or has @DEFAULT@.
609class AddColumn ty where
610class AddColumn ty where
610 -- | `addColumn` adds a new column, initially filled with whatever
611 -- | `addColumn` adds a new column, initially filled with whatever
@@ -635,17 +636,19 @@ class AddColumn ty where
635 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
636 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
636 addColumn
637 addColumn
637 :: ( KnownSymbol column
638 :: ( KnownSymbol column
638− , Has tab schema ('Table table0)
639+ , HasQualified sch tab db schema ('Table table0)
639 , table0 ~ (constraints :=> columns)
640 , table0 ~ (constraints :=> columns)
640 , table1 ~ (constraints :=> Create column ty columns) )
641 , table1 ~ (constraints :=> Create column ty columns) )
641 => Alias column -- ^ column to add
642 => Alias column -- ^ column to add
642− -> ColumnTypeExpression schema ty -- ^ type of the new column
643+ -> ColumnTypeExpression db ty -- ^ type of the new column
643− -> AlterTable tab table1 schema
644+ -> AlterTable tab table1 db
644 addColumn column ty = UnsafeAlterTable $
645 addColumn column ty = UnsafeAlterTable $
645 "ADD COLUMN" <+> renderAlias column <+> renderColumnTypeExpression ty
646 "ADD COLUMN" <+> renderAlias column <+> renderColumnTypeExpression ty
646instance {-# OVERLAPPING #-} AddColumn ('Def :=> ty)
647instance {-# OVERLAPPING #-} AddColumn ('Def :=> ty)
647instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
648instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
648
649
650+-}
651+
649-- | A `dropColumn` removes a column. Whatever data was in the column
652-- | A `dropColumn` removes a column. Whatever data was in the column
650-- disappears. Table constraints involving the column are dropped, too.
653-- disappears. Table constraints involving the column are dropped, too.
651-- However, if the column is referenced by a foreign key constraint of
654-- However, if the column is referenced by a foreign key constraint of
@@ -668,7 +671,7 @@ dropColumn
668 , table0 ~ (constraints :=> columns)
671 , table0 ~ (constraints :=> columns)
669 , table1 ~ (constraints :=> Drop column columns) )
672 , table1 ~ (constraints :=> Drop column columns) )
670 => Alias column -- ^ column to remove
673 => Alias column -- ^ column to remove
671− -> AlterTable tab table1 schema
674+ -> AlterTable tab table1 db
672dropColumn column = UnsafeAlterTable $
675dropColumn column = UnsafeAlterTable $
673 "DROP COLUMN" <+> renderAlias column
676 "DROP COLUMN" <+> renderAlias column
674
677
@@ -691,7 +694,7 @@ renameColumn
691 , table1 ~ (constraints :=> Rename column0 column1 columns) )
694 , table1 ~ (constraints :=> Rename column0 column1 columns) )
692 => Alias column0 -- ^ column to rename
695 => Alias column0 -- ^ column to rename
693 -> Alias column1 -- ^ what to rename the column
696 -> Alias column1 -- ^ what to rename the column
694− -> AlterTable tab table1 schema
697+ -> AlterTable tab table1 db
695renameColumn column0 column1 = UnsafeAlterTable $
698renameColumn column0 column1 = UnsafeAlterTable $
696 "RENAME COLUMN" <+> renderAlias column0 <+> "TO" <+> renderAlias column1
699 "RENAME COLUMN" <+> renderAlias column0 <+> "TO" <+> renderAlias column1
697
700
@@ -703,13 +706,13 @@ alterColumn
703 , Has column columns ty0
706 , Has column columns ty0
704 , tables1 ~ (constraints :=> Alter column ty1 columns))
707 , tables1 ~ (constraints :=> Alter column ty1 columns))
705 => Alias column -- ^ column to alter
708 => Alias column -- ^ column to alter
706− -> AlterColumn schema ty0 ty1 -- ^ alteration to perform
709+ -> AlterColumn db ty0 ty1 -- ^ alteration to perform
707− -> AlterTable tab table1 schema
710+ -> AlterTable tab table1 db
708alterColumn column alteration = UnsafeAlterTable $
711alterColumn column alteration = UnsafeAlterTable $
709 "ALTER COLUMN" <+> renderAlias column <+> renderAlterColumn alteration
712 "ALTER COLUMN" <+> renderAlias column <+> renderAlterColumn alteration
710
713
711-- | An `AlterColumn` describes the alteration to perform on a single column.
714-- | 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) =
713 UnsafeAlterColumn {renderAlterColumn :: ByteString}
716 UnsafeAlterColumn {renderAlterColumn :: ByteString}
714 deriving (GHC.Generic,Show,Eq,Ord,NFData)
717 deriving (GHC.Generic,Show,Eq,Ord,NFData)
715
718
@@ -811,7 +814,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
811createView
814createView
812 :: (KnownSymbol sch, KnownSymbol vw)
815 :: (KnownSymbol sch, KnownSymbol vw)
813 => QualifiedAlias sch vw -- ^ the name of the view to add
816 => QualifiedAlias sch vw -- ^ the name of the view to add
814− -> Query schema '[] view
817+ -> Query db '[] view
815 -- ^ query
818 -- ^ query
816 -> Definition db (Alter sch (Create vw ('View view) schema) db)
819 -> Definition db (Alter sch (Create vw ('View view) schema) db)
817createView alias query = UnsafeDefinition $
820createView alias query = UnsafeDefinition $
@@ -892,7 +895,7 @@ createTypeComposite
892 :: (KnownSymbol ty, Has sch db schema, SOP.SListI fields)
895 :: (KnownSymbol ty, Has sch db schema, SOP.SListI fields)
893 => QualifiedAlias sch ty
896 => QualifiedAlias sch ty
894 -- ^ name of the user defined composite type
897 -- ^ name of the user defined composite type
895− -> NP (Aliased (TypeExpression schema)) fields
898+ -> NP (Aliased (TypeExpression db)) fields
896 -- ^ list of attribute names and data types
899 -- ^ list of attribute names and data types
897 -> Definition db (Alter sch (Create ty ('Typedef ('PGcomposite fields)) schema) db)
900 -> Definition db (Alter sch (Create ty ('Typedef ('PGcomposite fields)) schema) db)
898createTypeComposite ty fields = UnsafeDefinition $
901createTypeComposite ty fields = UnsafeDefinition $
@@ -912,15 +915,15 @@ createTypeComposite ty fields = UnsafeDefinition $
912-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
915-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
913createTypeCompositeFrom
916createTypeCompositeFrom
914 :: forall hask sch ty db schema.
917 :: forall hask sch ty db schema.
915− ( SOP.All (FieldTyped schema) (RowPG hask)
918+ ( SOP.All (FieldTyped db) (RowPG hask)
916 , KnownSymbol ty
919 , KnownSymbol ty
917 , Has sch db schema )
920 , Has sch db schema )
918 => QualifiedAlias sch ty
921 => QualifiedAlias sch ty
919 -- ^ name of the user defined composite type
922 -- ^ name of the user defined composite type
920 -> Definition db (Alter sch (Create ty ( 'Typedef (PG (Composite hask))) schema) db)
923 -> Definition db (Alter sch (Create ty ( 'Typedef (PG (Composite hask))) schema) db)
921createTypeCompositeFrom ty = createTypeComposite ty
924createTypeCompositeFrom ty = createTypeComposite ty
922− (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped schema)) fieldtype
925+ (SOP.hcpure (SOP.Proxy :: SOP.Proxy (FieldTyped db)) fieldtype
923− :: NP (Aliased (TypeExpression schema)) (RowPG hask))
926+ :: NP (Aliased (TypeExpression db)) (RowPG hask))
924
927
925class FieldTyped schema ty where
928class FieldTyped schema ty where
926 fieldtype :: Aliased (TypeExpression schema) ty
929 fieldtype :: Aliased (TypeExpression schema) ty
@@ -943,15 +946,15 @@ dropType
943dropType tydef = UnsafeDefinition $ "DROP" <+> "TYPE" <+> renderQualifiedAlias tydef <> ";"
946dropType tydef = UnsafeDefinition $ "DROP" <+> "TYPE" <+> renderQualifiedAlias tydef <> ";"
944
947
945-- | `ColumnTypeExpression`s are used in `createTable` commands.
948-- | `ColumnTypeExpression`s are used in `createTable` commands.
946−newtype ColumnTypeExpression (schema :: SchemaType) (ty :: ColumnType)
949+newtype ColumnTypeExpression (db :: DBType) (ty :: ColumnType)
947 = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
950 = UnsafeColumnTypeExpression { renderColumnTypeExpression :: ByteString }
948 deriving (GHC.Generic,Show,Eq,Ord,NFData)
951 deriving (GHC.Generic,Show,Eq,Ord,NFData)
949
952
950-- | used in `createTable` commands as a column constraint to note that
953-- | used in `createTable` commands as a column constraint to note that
951-- @NULL@ may be present in a column
954-- @NULL@ may be present in a column
952nullable
955nullable
953− :: TypeExpression schema (nullity ty)
956+ :: TypeExpression db (nullity ty)
954− -> ColumnTypeExpression schema ('NoDef :=> 'Null ty)
957+ -> ColumnTypeExpression db ('NoDef :=> 'Null ty)
955nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
958nullable ty = UnsafeColumnTypeExpression $ renderTypeExpression ty <+> "NULL"
956
959
957-- | used in `createTable` commands as a column constraint to ensure
960-- | 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,
217and other operations.
217and other operations.
218-}
218-}
219newtype Expression
219newtype Expression
220− (schema :: SchemaType)
220+ (db :: DBType)
221 (from :: FromType)
221 (from :: FromType)
222 (grouping :: Grouping)
222 (grouping :: Grouping)
223 (params :: [NullityType])
223 (params :: [NullityType])
@@ -225,7 +225,7 @@ newtype Expression
225 = UnsafeExpression { renderExpression :: ByteString }
225 = UnsafeExpression { renderExpression :: ByteString }
226 deriving (GHC.Generic,Show,Eq,Ord,NFData)
226 deriving (GHC.Generic,Show,Eq,Ord,NFData)
227
227
228−instance RenderSQL (Expression schema from grouping params ty) where
228+instance RenderSQL (Expression db from grouping params ty) where
229 renderSQL = renderExpression
229 renderSQL = renderExpression
230
230
231{- | A `HasParameter` constraint is used to indicate a value that is
231{- | A `HasParameter` constraint is used to indicate a value that is
@@ -238,7 +238,7 @@ refer to the out-of-line data values.
238-}
238-}
239class KnownNat n => HasParameter
239class KnownNat n => HasParameter
240 (n :: Nat)
240 (n :: Nat)
241− (schema :: SchemaType)
241+ (db :: DBType)
242 (params :: [NullityType])
242 (params :: [NullityType])
243 (ty :: NullityType)
243 (ty :: NullityType)
244 | n params -> ty where
244 | n params -> ty where
@@ -248,8 +248,8 @@ class KnownNat n => HasParameter
248 -- >>> printSQL expr
248 -- >>> printSQL expr
249 -- ($1 :: int4)
249 -- ($1 :: int4)
250 parameter
250 parameter
251− :: TypeExpression schema ty
251+ :: TypeExpression db ty
252− -> Expression schema from grouping params ty
252+ -> Expression db from grouping params ty
253 parameter ty = UnsafeExpression $ parenthesized $
253 parameter ty = UnsafeExpression $ parenthesized $
254 "$" <> renderNat @n <+> "::"
254 "$" <> renderNat @n <+> "::"
255 <+> renderTypeExpression ty
255 <+> renderTypeExpression ty
@@ -264,34 +264,34 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) schema params ty)
264-- >>> printSQL expr
264-- >>> printSQL expr
265-- ($1 :: int4)
265-- ($1 :: int4)
266param
266param
267− :: forall n schema params from grouping ty
267+ :: forall n db params from grouping ty
268− . (PGTyped schema ty, HasParameter n schema params ty)
268+ . (PGTyped db ty, HasParameter n db params ty)
269− => Expression schema from grouping params ty -- ^ param
269+ => Expression db from grouping params ty -- ^ param
270param = parameter @n pgtype
270param = parameter @n pgtype
271
271
272instance (HasUnique table from columns, Has column columns ty)
272instance (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
274 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
274 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
275instance (HasUnique table from columns, Has column columns ty)
275instance (HasUnique table from columns, Has column columns ty)
276 => IsLabel column
276 => IsLabel column
277− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
277+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
278 fromLabel = fromLabel @column `As` Alias @column
278 fromLabel = fromLabel @column `As` Alias @column
279instance (HasUnique table from columns, Has column columns ty)
279instance (HasUnique table from columns, Has column columns ty)
280 => IsLabel column
280 => IsLabel column
281− (NP (Aliased (Expression schema from 'Ungrouped params)) '[column ::: ty]) where
281+ (NP (Aliased (Expression db from 'Ungrouped params)) '[column ::: ty]) where
282 fromLabel = fromLabel @column :* Nil
282 fromLabel = fromLabel @column :* Nil
283
283
284instance (Has table from columns, Has column columns ty)
284instance (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
286 table ! column = UnsafeExpression $
286 table ! column = UnsafeExpression $
287 renderAlias table <> "." <> renderAlias column
287 renderAlias table <> "." <> renderAlias column
288instance (Has table from columns, Has column columns ty)
288instance (Has table from columns, Has column columns ty)
289 => IsQualified table column
289 => IsQualified table column
290− (Aliased (Expression schema from 'Ungrouped params) (column ::: ty)) where
290+ (Aliased (Expression db from 'Ungrouped params) (column ::: ty)) where
291 table ! column = table ! column `As` column
291 table ! column = table ! column `As` column
292instance (Has table from columns, Has column columns ty)
292instance (Has table from columns, Has column columns ty)
293 => IsQualified table column
293 => 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
295 table ! column = table ! column :* Nil
295 table ! column = table ! column :* Nil
296
296
297instance
297instance
@@ -299,14 +299,14 @@ instance
299 , Has column columns ty
299 , Has column columns ty
300 , GroupedBy table column bys
300 , GroupedBy table column bys
301 ) => IsLabel column
301 ) => IsLabel column
302− (Expression schema from ('Grouped bys) params ty) where
302+ (Expression db from ('Grouped bys) params ty) where
303 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
303 fromLabel = UnsafeExpression $ renderAlias (Alias @column)
304instance
304instance
305 ( HasUnique table from columns
305 ( HasUnique table from columns
306 , Has column columns ty
306 , Has column columns ty
307 , GroupedBy table column bys
307 , GroupedBy table column bys
308 ) => IsLabel column
308 ) => IsLabel column
309− ( Aliased (Expression schema from ('Grouped bys) params)
309+ ( Aliased (Expression db from ('Grouped bys) params)
310 (column ::: ty) ) where
310 (column ::: ty) ) where
311 fromLabel = fromLabel @column `As` Alias @column
311 fromLabel = fromLabel @column `As` Alias @column
312instance
312instance
@@ -314,7 +314,7 @@ instance
314 , Has column columns ty
314 , Has column columns ty
315 , GroupedBy table column bys
315 , GroupedBy table column bys
316 ) => IsLabel column
316 ) => IsLabel column
317− ( NP (Aliased (Expression schema from ('Grouped bys) params))
317+ ( NP (Aliased (Expression db from ('Grouped bys) params))
318 '[column ::: ty] ) where
318 '[column ::: ty] ) where
319 fromLabel = fromLabel @column :* Nil
319 fromLabel = fromLabel @column :* Nil
320
320
@@ -323,7 +323,7 @@ instance
323 , Has column columns ty
323 , Has column columns ty
324 , GroupedBy table column bys
324 , GroupedBy table column bys
325 ) => IsQualified table column
325 ) => IsQualified table column
326− (Expression schema from ('Grouped bys) params ty) where
326+ (Expression db from ('Grouped bys) params ty) where
327 table ! column = UnsafeExpression $
327 table ! column = UnsafeExpression $
328 renderAlias table <> "." <> renderAlias column
328 renderAlias table <> "." <> renderAlias column
329instance
329instance
@@ -331,7 +331,7 @@ instance
331 , Has column columns ty
331 , Has column columns ty
332 , GroupedBy table column bys
332 , GroupedBy table column bys
333 ) => IsQualified table column
333 ) => IsQualified table column
334− (Aliased (Expression schema from ('Grouped bys) params)
334+ (Aliased (Expression db from ('Grouped bys) params)
335 (column ::: ty)) where
335 (column ::: ty)) where
336 table ! column = table ! column `As` column
336 table ! column = table ! column `As` column
337instance
337instance
@@ -339,7 +339,7 @@ instance
339 , Has column columns ty
339 , Has column columns ty
340 , GroupedBy table column bys
340 , GroupedBy table column bys
341 ) => IsQualified table column
341 ) => IsQualified table column
342− ( NP (Aliased (Expression schema from ('Grouped bys) params))
342+ ( NP (Aliased (Expression db from ('Grouped bys) params))
343 '[column ::: ty]) where
343 '[column ::: ty]) where
344 table ! column = table ! column :* Nil
344 table ! column = table ! column :* Nil
345
345
@@ -347,7 +347,7 @@ instance
347--
347--
348-- >>> printSQL null_
348-- >>> printSQL null_
349-- NULL
349-- NULL
350−null_ :: Expression schema rels grouping params ('Null ty)
350+null_ :: Expression db rels grouping params ('Null ty)
351null_ = UnsafeExpression "NULL"
351null_ = UnsafeExpression "NULL"
352
352
353-- | analagous to `Just`
353-- | analagous to `Just`
@@ -355,8 +355,8 @@ null_ = UnsafeExpression "NULL"
355-- >>> printSQL $ notNull true
355-- >>> printSQL $ notNull true
356-- TRUE
356-- TRUE
357notNull
357notNull
358− :: Expression schema rels grouping params ('NotNull ty)
358+ :: Expression db rels grouping params ('NotNull ty)
359− -> Expression schema rels grouping params ('Null ty)
359+ -> Expression db rels grouping params ('Null ty)
360notNull = UnsafeExpression . renderExpression
360notNull = UnsafeExpression . renderExpression
361
361
362-- | return the leftmost value which is not NULL
362-- | return the leftmost value which is not NULL
@@ -364,11 +364,11 @@ notNull = UnsafeExpression . renderExpression
364-- >>> printSQL $ coalesce [null_, true] false
364-- >>> printSQL $ coalesce [null_, true] false
365-- COALESCE(NULL, TRUE, FALSE)
365-- COALESCE(NULL, TRUE, FALSE)
366coalesce
366coalesce
367− :: [Expression schema from grouping params ('Null ty)]
367+ :: [Expression db from grouping params ('Null ty)]
368 -- ^ @NULL@s may be present
368 -- ^ @NULL@s may be present
369− -> Expression schema from grouping params ('NotNull ty)
369+ -> Expression db from grouping params ('NotNull ty)
370 -- ^ @NULL@ is absent
370 -- ^ @NULL@ is absent
371− -> Expression schema from grouping params ('NotNull ty)
371+ -> Expression db from grouping params ('NotNull ty)
372coalesce nullxs notNullx = UnsafeExpression $
372coalesce nullxs notNullx = UnsafeExpression $
373 "COALESCE" <> parenthesized (commaSeparated
373 "COALESCE" <> parenthesized (commaSeparated
374 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
374 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -378,26 +378,26 @@ coalesce nullxs notNullx = UnsafeExpression $
378-- >>> printSQL $ fromNull true null_
378-- >>> printSQL $ fromNull true null_
379-- COALESCE(NULL, TRUE)
379-- COALESCE(NULL, TRUE)
380fromNull
380fromNull
381− :: Expression schema from grouping params ('NotNull ty)
381+ :: Expression db from grouping params ('NotNull ty)
382 -- ^ what to convert @NULL@ to
382 -- ^ what to convert @NULL@ to
383− -> Expression schema from grouping params ('Null ty)
383+ -> Expression db from grouping params ('Null ty)
384− -> Expression schema from grouping params ('NotNull ty)
384+ -> Expression db from grouping params ('NotNull ty)
385fromNull notNullx nullx = coalesce [nullx] notNullx
385fromNull notNullx nullx = coalesce [nullx] notNullx
386
386
387-- | >>> printSQL $ null_ & isNull
387-- | >>> printSQL $ null_ & isNull
388-- NULL IS NULL
388-- NULL IS NULL
389isNull
389isNull
390− :: Expression schema from grouping params ('Null ty)
390+ :: Expression db from grouping params ('Null ty)
391 -- ^ possibly @NULL@
391 -- ^ possibly @NULL@
392− -> Condition schema from grouping params
392+ -> Condition db from grouping params
393isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
393isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
394
394
395-- | >>> printSQL $ null_ & isNotNull
395-- | >>> printSQL $ null_ & isNotNull
396-- NULL IS NOT NULL
396-- NULL IS NOT NULL
397isNotNull
397isNotNull
398− :: Expression schema from grouping params ('Null ty)
398+ :: Expression db from grouping params ('Null ty)
399 -- ^ possibly @NULL@
399 -- ^ possibly @NULL@
400− -> Condition schema from grouping params
400+ -> Condition db from grouping params
401isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
401isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
402
402
403-- | analagous to `maybe` using @IS NULL@
403-- | analagous to `maybe` using @IS NULL@
@@ -405,13 +405,13 @@ isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
405-- >>> printSQL $ matchNull true not_ null_
405-- >>> printSQL $ matchNull true not_ null_
406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407matchNull
407matchNull
408− :: Expression schema from grouping params (nullty)
408+ :: Expression db from grouping params (nullty)
409 -- ^ what to convert @NULL@ to
409 -- ^ what to convert @NULL@ to
410− -> ( Expression schema from grouping params ('NotNull ty)
410+ -> ( Expression db from grouping params ('NotNull ty)
411− -> Expression schema from grouping params (nullty) )
411+ -> Expression db from grouping params (nullty) )
412 -- ^ function to perform when @NULL@ is absent
412 -- ^ function to perform when @NULL@ is absent
413− -> Expression schema from grouping params ('Null ty)
413+ -> Expression db from grouping params ('Null ty)
414− -> Expression schema from grouping params (nullty)
414+ -> Expression db from grouping params (nullty)
415matchNull y f x = ifThenElse (isNull x) y
415matchNull y f x = ifThenElse (isNull x) y
416 (f (UnsafeExpression (renderExpression x)))
416 (f (UnsafeExpression (renderExpression x)))
417
417
@@ -419,25 +419,25 @@ matchNull y f x = ifThenElse (isNull x) y
419`nullIf` gives @NULL@.
419`nullIf` gives @NULL@.
420
420
421>>> :set -XTypeApplications -XDataKinds
421>>> :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)
423>>> printSQL expr
423>>> printSQL expr
424NULL IF (FALSE, ($1 :: bool))
424NULL IF (FALSE, ($1 :: bool))
425-}
425-}
426nullIf
426nullIf
427− :: Expression schema from grouping params ('NotNull ty)
427+ :: Expression db from grouping params ('NotNull ty)
428 -- ^ @NULL@ is absent
428 -- ^ @NULL@ is absent
429− -> Expression schema from grouping params ('NotNull ty)
429+ -> Expression db from grouping params ('NotNull ty)
430 -- ^ @NULL@ is absent
430 -- ^ @NULL@ is absent
431− -> Expression schema from grouping params ('Null ty)
431+ -> Expression db from grouping params ('Null ty)
432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
433 (renderExpression x <> ", " <> renderExpression y)
433 (renderExpression x <> ", " <> renderExpression y)
434
434
435-- | >>> printSQL $ array [null_, false, true]
435-- | >>> printSQL $ array [null_, false, true]
436-- ARRAY[NULL, FALSE, TRUE]
436-- ARRAY[NULL, FALSE, TRUE]
437array
437array
438− :: [Expression schema from grouping params ty]
438+ :: [Expression db from grouping params ty]
439 -- ^ array elements
439 -- ^ array elements
440− -> Expression schema from grouping params (nullity ('PGvararray ty))
440+ -> Expression db from grouping params (nullity ('PGvararray ty))
441array xs = UnsafeExpression $
441array xs = UnsafeExpression $
442 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
442 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
443
443
@@ -445,13 +445,13 @@ array xs = UnsafeExpression $
445-- (ARRAY[NULL, FALSE, TRUE])[2]
445-- (ARRAY[NULL, FALSE, TRUE])[2]
446index
446index
447 :: Word64 -- ^ index
447 :: Word64 -- ^ index
448− -> Expression schema from grouping params (nullity ('PGvararray ty)) -- ^ array
448+ -> Expression db from grouping params (nullity ('PGvararray ty)) -- ^ array
449− -> Expression schema from grouping params (NullifyType ty)
449+ -> Expression db from grouping params (NullifyType ty)
450index n expr = UnsafeExpression $
450index n expr = UnsafeExpression $
451 parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
451 parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
452
452
453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
453instance (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
455 label = UnsafeExpression $ renderLabel (PGlabel @label)
455 label = UnsafeExpression $ renderLabel (PGlabel @label)
456
456
457-- | A row constructor is an expression that builds a row value
457-- | A row constructor is an expression that builds a row value
@@ -468,9 +468,9 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
468-- ROW(0, 1)
468-- ROW(0, 1)
469row
469row
470 :: SListI row
470 :: SListI row
471− => NP (Aliased (Expression schema from grouping params)) row
471+ => NP (Aliased (Expression db from grouping params)) row
472 -- ^ zero or more expressions for the row field values
472 -- ^ 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))
474row exprs = UnsafeExpression $ "ROW" <> parenthesized
474row exprs = UnsafeExpression $ "ROW" <> parenthesized
475 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
475 (renderCommaSeparated (\ (expr `As` _) -> renderExpression expr) exprs)
476
476
@@ -484,21 +484,22 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
484-- >>> printSQL $ i & field #complex #imaginary
484-- >>> printSQL $ i & field #complex #imaginary
485-- (ROW(0, 1)::"complex")."imaginary"
485-- (ROW(0, 1)::"complex")."imaginary"
486field
486field
487− :: (Has tydef schema ('Typedef ('PGcomposite row)), Has field row ty)
487+ :: ( HasQualified sch tydef db schema ('Typedef ('PGcomposite row))
488+ , Has field row ty)
488− => Alias tydef -- ^ row type
489+ => QualifiedAlias sch tydef -- ^ row type
489 -> Alias field -- ^ field name
490 -> Alias field -- ^ field name
490− -> Expression schema from grouping params ('NotNull ('PGcomposite row))
491+ -> Expression db from grouping params ('NotNull ('PGcomposite row))
491− -> Expression schema from grouping params ty
492+ -> Expression db from grouping params ty
492field td fld expr = UnsafeExpression $
493field td fld expr = UnsafeExpression $
493− parenthesized (renderExpression expr <> "::" <> renderAlias td)
494+ parenthesized (renderExpression expr <> "::" <> renderQualifiedAlias td)
494 <> "." <> renderAlias fld
495 <> "." <> renderAlias fld
495
496
496instance Semigroup
497instance Semigroup
497− (Expression schema from grouping params (nullity ('PGvararray ty))) where
498+ (Expression db from grouping params (nullity ('PGvararray ty))) where
498 (<>) = unsafeBinaryOp "||"
499 (<>) = unsafeBinaryOp "||"
499
500
500instance Monoid
501instance Monoid
501− (Expression schema from grouping params (nullity ('PGvararray ty))) where
502+ (Expression db from grouping params (nullity ('PGvararray ty))) where
502 mempty = array []
503 mempty = array []
503 mappend = (<>)
504 mappend = (<>)
504
505
@@ -506,22 +507,22 @@ instance Monoid
506-- >>> printSQL expr
507-- >>> printSQL expr
507-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
508-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
508greatest
509greatest
509− :: Expression schema from grouping params (nullty)
510+ :: Expression db from grouping params (nullty)
510 -- ^ needs at least 1 argument
511 -- ^ needs at least 1 argument
511− -> [Expression schema from grouping params (nullty)]
512+ -> [Expression db from grouping params (nullty)]
512 -- ^ or more
513 -- ^ or more
513− -> Expression schema from grouping params (nullty)
514+ -> Expression db from grouping params (nullty)
514greatest x xs = UnsafeExpression $ "GREATEST("
515greatest x xs = UnsafeExpression $ "GREATEST("
515 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
516 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
516
517
517-- | >>> printSQL $ least currentTimestamp [null_]
518-- | >>> printSQL $ least currentTimestamp [null_]
518-- LEAST(CURRENT_TIMESTAMP, NULL)
519-- LEAST(CURRENT_TIMESTAMP, NULL)
519least
520least
520− :: Expression schema from grouping params (nullty)
521+ :: Expression db from grouping params (nullty)
521 -- ^ needs at least 1 argument
522 -- ^ needs at least 1 argument
522− -> [Expression schema from grouping params (nullty)]
523+ -> [Expression db from grouping params (nullty)]
523 -- ^ or more
524 -- ^ or more
524− -> Expression schema from grouping params (nullty)
525+ -> Expression db from grouping params (nullty)
525least x xs = UnsafeExpression $ "LEAST("
526least x xs = UnsafeExpression $ "LEAST("
526 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
527 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
527
528
@@ -530,9 +531,9 @@ least x xs = UnsafeExpression $ "LEAST("
530unsafeBinaryOp
531unsafeBinaryOp
531 :: ByteString
532 :: ByteString
532 -- ^ operator
533 -- ^ operator
533− -> Expression schema from grouping params (ty0)
534+ -> Expression db from grouping params (ty0)
534− -> Expression schema from grouping params (ty1)
535+ -> Expression db from grouping params (ty1)
535− -> Expression schema from grouping params (ty2)
536+ -> Expression db from grouping params (ty2)
536unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
537unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
537 renderExpression x <+> op <+> renderExpression y
538 renderExpression x <+> op <+> renderExpression y
538
539
@@ -541,8 +542,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
541unsafeUnaryOp
542unsafeUnaryOp
542 :: ByteString
543 :: ByteString
543 -- ^ operator
544 -- ^ operator
544− -> Expression schema from grouping params (ty0)
545+ -> Expression db from grouping params (ty0)
545− -> Expression schema from grouping params (ty1)
546+ -> Expression db from grouping params (ty1)
546unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
547unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
547 op <+> renderExpression x
548 op <+> renderExpression x
548
549
@@ -551,8 +552,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
551unsafeFunction
552unsafeFunction
552 :: ByteString
553 :: ByteString
553 -- ^ function
554 -- ^ function
554− -> Expression schema from grouping params (xty)
555+ -> Expression db from grouping params (xty)
555− -> Expression schema from grouping params (yty)
556+ -> Expression db from grouping params (yty)
556unsafeFunction fun x = UnsafeExpression $
557unsafeFunction fun x = UnsafeExpression $
557 fun <> parenthesized (renderExpression x)
558 fun <> parenthesized (renderExpression x)
558
559
@@ -561,13 +562,13 @@ unsafeVariadicFunction
561 :: SListI elems
562 :: SListI elems
562 => ByteString
563 => ByteString
563 -- ^ function
564 -- ^ function
564− -> NP (Expression schema from grouping params) elems
565+ -> NP (Expression db from grouping params) elems
565− -> Expression schema from grouping params ret
566+ -> Expression db from grouping params ret
566unsafeVariadicFunction fun x = UnsafeExpression $
567unsafeVariadicFunction fun x = UnsafeExpression $
567 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
568 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderExpression) x)))
568
569
569instance ty `In` PGNum
570instance ty `In` PGNum
570− => Num (Expression schema from grouping params (nullity ty)) where
571+ => Num (Expression db from grouping params (nullity ty)) where
571 (+) = unsafeBinaryOp "+"
572 (+) = unsafeBinaryOp "+"
572 (-) = unsafeBinaryOp "-"
573 (-) = unsafeBinaryOp "-"
573 (*) = unsafeBinaryOp "*"
574 (*) = unsafeBinaryOp "*"
@@ -579,12 +580,12 @@ instance ty `In` PGNum
579 . show
580 . show
580
581
581instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
582instance (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
583 (/) = unsafeBinaryOp "/"
584 (/) = unsafeBinaryOp "/"
584 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
585 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
585
586
586instance (ty `In` PGNum, ty `In` PGFloating) => Floating
587instance (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
588 pi = UnsafeExpression "pi()"
589 pi = UnsafeExpression "pi()"
589 exp = unsafeFunction "exp"
590 exp = unsafeFunction "exp"
590 log = unsafeFunction "ln"
591 log = unsafeFunction "ln"
@@ -607,18 +608,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
607
608
608-- | >>> :{
609-- | >>> :{
609-- let
610-- let
610−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
611+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
611-- expression = atan2_ pi 2
612-- expression = atan2_ pi 2
612-- in printSQL expression
613-- in printSQL expression
613-- :}
614-- :}
614-- atan2(pi(), 2)
615-- atan2(pi(), 2)
615atan2_
616atan2_
616 :: float `In` PGFloating
617 :: float `In` PGFloating
617− => Expression schema from grouping params (nullity float)
618+ => Expression db from grouping params (nullity float)
618 -- ^ numerator
619 -- ^ numerator
619− -> Expression schema from grouping params (nullity float)
620+ -> Expression db from grouping params (nullity float)
620 -- ^ denominator
621 -- ^ denominator
621− -> Expression schema from grouping params (nullity float)
622+ -> Expression db from grouping params (nullity float)
622atan2_ y x = UnsafeExpression $
623atan2_ y x = UnsafeExpression $
623 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
624 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
624
625
@@ -629,11 +630,11 @@ atan2_ y x = UnsafeExpression $
629-- | >>> printSQL $ true & cast int4
630-- | >>> printSQL $ true & cast int4
630-- (TRUE :: int4)
631-- (TRUE :: int4)
631cast
632cast
632− :: TypeExpression schema ty1
633+ :: TypeExpression db ty1
633 -- ^ type to cast as
634 -- ^ type to cast as
634− -> Expression schema from grouping params ty0
635+ -> Expression db from grouping params ty0
635 -- ^ value to convert
636 -- ^ value to convert
636− -> Expression schema from grouping params ty1
637+ -> Expression db from grouping params ty1
637cast ty x = UnsafeExpression $ parenthesized $
638cast ty x = UnsafeExpression $ parenthesized $
638 renderExpression x <+> "::" <+> renderTypeExpression ty
639 renderExpression x <+> "::" <+> renderTypeExpression ty
639
640
@@ -641,136 +642,136 @@ cast ty x = UnsafeExpression $ parenthesized $
641--
642--
642-- >>> :{
643-- >>> :{
643-- let
644-- let
644−-- expression :: Expression schema from grouping params (nullity 'PGint2)
645+-- expression :: Expression db from grouping params (nullity 'PGint2)
645-- expression = 5 `quot_` 2
646-- expression = 5 `quot_` 2
646-- in printSQL expression
647-- in printSQL expression
647-- :}
648-- :}
648-- (5 / 2)
649-- (5 / 2)
649quot_
650quot_
650 :: int `In` PGIntegral
651 :: int `In` PGIntegral
651− => Expression schema from grouping params (nullity int)
652+ => Expression db from grouping params (nullity int)
652 -- ^ numerator
653 -- ^ numerator
653− -> Expression schema from grouping params (nullity int)
654+ -> Expression db from grouping params (nullity int)
654 -- ^ denominator
655 -- ^ denominator
655− -> Expression schema from grouping params (nullity int)
656+ -> Expression db from grouping params (nullity int)
656quot_ = unsafeBinaryOp "/"
657quot_ = unsafeBinaryOp "/"
657
658
658-- | remainder upon integer division
659-- | remainder upon integer division
659--
660--
660-- >>> :{
661-- >>> :{
661-- let
662-- let
662−-- expression :: Expression schema from grouping params (nullity 'PGint2)
663+-- expression :: Expression db from grouping params (nullity 'PGint2)
663-- expression = 5 `rem_` 2
664-- expression = 5 `rem_` 2
664-- in printSQL expression
665-- in printSQL expression
665-- :}
666-- :}
666-- (5 % 2)
667-- (5 % 2)
667rem_
668rem_
668 :: int `In` PGIntegral
669 :: int `In` PGIntegral
669− => Expression schema from grouping params (nullity int)
670+ => Expression db from grouping params (nullity int)
670 -- ^ numerator
671 -- ^ numerator
671− -> Expression schema from grouping params (nullity int)
672+ -> Expression db from grouping params (nullity int)
672 -- ^ denominator
673 -- ^ denominator
673− -> Expression schema from grouping params (nullity int)
674+ -> Expression db from grouping params (nullity int)
674rem_ = unsafeBinaryOp "%"
675rem_ = unsafeBinaryOp "%"
675
676
676-- | >>> :{
677-- | >>> :{
677-- let
678-- let
678−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
679+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
679-- expression = trunc pi
680-- expression = trunc pi
680-- in printSQL expression
681-- in printSQL expression
681-- :}
682-- :}
682-- trunc(pi())
683-- trunc(pi())
683trunc
684trunc
684 :: frac `In` PGFloating
685 :: frac `In` PGFloating
685− => Expression schema from grouping params (nullity frac)
686+ => Expression db from grouping params (nullity frac)
686 -- ^ fractional number
687 -- ^ fractional number
687− -> Expression schema from grouping params (nullity frac)
688+ -> Expression db from grouping params (nullity frac)
688trunc = unsafeFunction "trunc"
689trunc = unsafeFunction "trunc"
689
690
690-- | >>> :{
691-- | >>> :{
691-- let
692-- let
692−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
693+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
693-- expression = round_ pi
694-- expression = round_ pi
694-- in printSQL expression
695-- in printSQL expression
695-- :}
696-- :}
696-- round(pi())
697-- round(pi())
697round_
698round_
698 :: frac `In` PGFloating
699 :: frac `In` PGFloating
699− => Expression schema from grouping params (nullity frac)
700+ => Expression db from grouping params (nullity frac)
700 -- ^ fractional number
701 -- ^ fractional number
701− -> Expression schema from grouping params (nullity frac)
702+ -> Expression db from grouping params (nullity frac)
702round_ = unsafeFunction "round"
703round_ = unsafeFunction "round"
703
704
704-- | >>> :{
705-- | >>> :{
705-- let
706-- let
706−-- expression :: Expression schema from grouping params (nullity 'PGfloat4)
707+-- expression :: Expression db from grouping params (nullity 'PGfloat4)
707-- expression = ceiling_ pi
708-- expression = ceiling_ pi
708-- in printSQL expression
709-- in printSQL expression
709-- :}
710-- :}
710-- ceiling(pi())
711-- ceiling(pi())
711ceiling_
712ceiling_
712 :: frac `In` PGFloating
713 :: frac `In` PGFloating
713− => Expression schema from grouping params (nullity frac)
714+ => Expression db from grouping params (nullity frac)
714 -- ^ fractional number
715 -- ^ fractional number
715− -> Expression schema from grouping params (nullity frac)
716+ -> Expression db from grouping params (nullity frac)
716ceiling_ = unsafeFunction "ceiling"
717ceiling_ = unsafeFunction "ceiling"
717
718
718-- | A `Condition` is an `Expression`, which can evaluate
719-- | A `Condition` is an `Expression`, which can evaluate
719-- to `true`, `false` or `null_`. This is because SQL uses
720-- to `true`, `false` or `null_`. This is because SQL uses
720-- a three valued logic.
721-- a three valued logic.
721−type Condition schema from grouping params =
722+type Condition db from grouping params =
722− Expression schema from grouping params ('Null 'PGbool)
723+ Expression db from grouping params ('Null 'PGbool)
723
724
724-- | >>> printSQL true
725-- | >>> printSQL true
725-- TRUE
726-- TRUE
726−true :: Expression schema from grouping params (nullity 'PGbool)
727+true :: Expression db from grouping params (nullity 'PGbool)
727true = UnsafeExpression "TRUE"
728true = UnsafeExpression "TRUE"
728
729
729-- | >>> printSQL false
730-- | >>> printSQL false
730-- FALSE
731-- FALSE
731−false :: Expression schema from grouping params (nullity 'PGbool)
732+false :: Expression db from grouping params (nullity 'PGbool)
732false = UnsafeExpression "FALSE"
733false = UnsafeExpression "FALSE"
733
734
734-- | >>> printSQL $ not_ true
735-- | >>> printSQL $ not_ true
735-- (NOT TRUE)
736-- (NOT TRUE)
736not_
737not_
737− :: Expression schema from grouping params (nullity 'PGbool)
738+ :: Expression db from grouping params (nullity 'PGbool)
738− -> Expression schema from grouping params (nullity 'PGbool)
739+ -> Expression db from grouping params (nullity 'PGbool)
739not_ = unsafeUnaryOp "NOT"
740not_ = unsafeUnaryOp "NOT"
740
741
741-- | >>> printSQL $ true .&& false
742-- | >>> printSQL $ true .&& false
742-- (TRUE AND FALSE)
743-- (TRUE AND FALSE)
743(.&&)
744(.&&)
744− :: Expression schema from grouping params (nullity 'PGbool)
745+ :: Expression db from grouping params (nullity 'PGbool)
745− -> Expression schema from grouping params (nullity 'PGbool)
746+ -> Expression db from grouping params (nullity 'PGbool)
746− -> Expression schema from grouping params (nullity 'PGbool)
747+ -> Expression db from grouping params (nullity 'PGbool)
747infixr 3 .&&
748infixr 3 .&&
748(.&&) = unsafeBinaryOp "AND"
749(.&&) = unsafeBinaryOp "AND"
749
750
750-- | >>> printSQL $ true .|| false
751-- | >>> printSQL $ true .|| false
751-- (TRUE OR FALSE)
752-- (TRUE OR FALSE)
752(.||)
753(.||)
753− :: Expression schema from grouping params (nullity 'PGbool)
754+ :: Expression db from grouping params (nullity 'PGbool)
754− -> Expression schema from grouping params (nullity 'PGbool)
755+ -> Expression db from grouping params (nullity 'PGbool)
755− -> Expression schema from grouping params (nullity 'PGbool)
756+ -> Expression db from grouping params (nullity 'PGbool)
756infixr 2 .||
757infixr 2 .||
757(.||) = unsafeBinaryOp "OR"
758(.||) = unsafeBinaryOp "OR"
758
759
759-- | >>> :{
760-- | >>> :{
760-- let
761-- let
761−-- expression :: Expression schema from grouping params (nullity 'PGint2)
762+-- expression :: Expression db from grouping params (nullity 'PGint2)
762-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
763-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
763-- in printSQL expression
764-- in printSQL expression
764-- :}
765-- :}
765-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
766-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
766caseWhenThenElse
767caseWhenThenElse
767− :: [ ( Condition schema from grouping params
768+ :: [ ( Condition db from grouping params
768− , Expression schema from grouping params ty
769+ , Expression db from grouping params ty
769 ) ]
770 ) ]
770 -- ^ whens and thens
771 -- ^ whens and thens
771− -> Expression schema from grouping params ty
772+ -> Expression db from grouping params ty
772 -- ^ else
773 -- ^ else
773− -> Expression schema from grouping params ty
774+ -> Expression db from grouping params ty
774caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
775caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
775 [ "CASE"
776 [ "CASE"
776 , mconcat
777 , mconcat
@@ -786,16 +787,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
786
787
787-- | >>> :{
788-- | >>> :{
788-- let
789-- let
789−-- expression :: Expression schema from grouping params (nullity 'PGint2)
790+-- expression :: Expression db from grouping params (nullity 'PGint2)
790-- expression = ifThenElse true 1 0
791-- expression = ifThenElse true 1 0
791-- in printSQL expression
792-- in printSQL expression
792-- :}
793-- :}
793-- CASE WHEN TRUE THEN 1 ELSE 0 END
794-- CASE WHEN TRUE THEN 1 ELSE 0 END
794ifThenElse
795ifThenElse
795− :: Condition schema from grouping params
796+ :: Condition db from grouping params
796− -> Expression schema from grouping params ty -- ^ then
797+ -> Expression db from grouping params ty -- ^ then
797− -> Expression schema from grouping params ty -- ^ else
798+ -> Expression db from grouping params ty -- ^ else
798− -> Expression schema from grouping params ty
799+ -> Expression db from grouping params ty
799ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
800ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
800
801
801-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
802-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -804,85 +805,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
804-- >>> printSQL $ true .== null_
805-- >>> printSQL $ true .== null_
805-- (TRUE = NULL)
806-- (TRUE = NULL)
806(.==)
807(.==)
807− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
808+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
808− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
809+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
809− -> Condition schema from grouping params
810+ -> Condition db from grouping params
810(.==) = unsafeBinaryOp "="
811(.==) = unsafeBinaryOp "="
811infix 4 .==
812infix 4 .==
812
813
813-- | >>> printSQL $ true ./= null_
814-- | >>> printSQL $ true ./= null_
814-- (TRUE <> NULL)
815-- (TRUE <> NULL)
815(./=)
816(./=)
816− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
817+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
817− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
818+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
818− -> Condition schema from grouping params
819+ -> Condition db from grouping params
819(./=) = unsafeBinaryOp "<>"
820(./=) = unsafeBinaryOp "<>"
820infix 4 ./=
821infix 4 ./=
821
822
822-- | >>> printSQL $ true .>= null_
823-- | >>> printSQL $ true .>= null_
823-- (TRUE >= NULL)
824-- (TRUE >= NULL)
824(.>=)
825(.>=)
825− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
826+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
826− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
827+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
827− -> Condition schema from grouping params
828+ -> Condition db from grouping params
828(.>=) = unsafeBinaryOp ">="
829(.>=) = unsafeBinaryOp ">="
829infix 4 .>=
830infix 4 .>=
830
831
831-- | >>> printSQL $ true .< null_
832-- | >>> printSQL $ true .< null_
832-- (TRUE < NULL)
833-- (TRUE < NULL)
833(.<)
834(.<)
834− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
835+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
835− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
836+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
836− -> Condition schema from grouping params
837+ -> Condition db from grouping params
837(.<) = unsafeBinaryOp "<"
838(.<) = unsafeBinaryOp "<"
838infix 4 .<
839infix 4 .<
839
840
840-- | >>> printSQL $ true .<= null_
841-- | >>> printSQL $ true .<= null_
841-- (TRUE <= NULL)
842-- (TRUE <= NULL)
842(.<=)
843(.<=)
843− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
844+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
844− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
845+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
845− -> Condition schema from grouping params
846+ -> Condition db from grouping params
846(.<=) = unsafeBinaryOp "<="
847(.<=) = unsafeBinaryOp "<="
847infix 4 .<=
848infix 4 .<=
848
849
849-- | >>> printSQL $ true .> null_
850-- | >>> printSQL $ true .> null_
850-- (TRUE > NULL)
851-- (TRUE > NULL)
851(.>)
852(.>)
852− :: Expression schema from grouping params (nullity0 ty) -- ^ lhs
853+ :: Expression db from grouping params (nullity0 ty) -- ^ lhs
853− -> Expression schema from grouping params (nullity1 ty) -- ^ rhs
854+ -> Expression db from grouping params (nullity1 ty) -- ^ rhs
854− -> Condition schema from grouping params
855+ -> Condition db from grouping params
855(.>) = unsafeBinaryOp ">"
856(.>) = unsafeBinaryOp ">"
856infix 4 .>
857infix 4 .>
857
858
858-- | >>> printSQL currentDate
859-- | >>> printSQL currentDate
859-- CURRENT_DATE
860-- CURRENT_DATE
860currentDate
861currentDate
861− :: Expression schema from grouping params (nullity 'PGdate)
862+ :: Expression db from grouping params (nullity 'PGdate)
862currentDate = UnsafeExpression "CURRENT_DATE"
863currentDate = UnsafeExpression "CURRENT_DATE"
863
864
864-- | >>> printSQL currentTime
865-- | >>> printSQL currentTime
865-- CURRENT_TIME
866-- CURRENT_TIME
866currentTime
867currentTime
867− :: Expression schema from grouping params (nullity 'PGtimetz)
868+ :: Expression db from grouping params (nullity 'PGtimetz)
868currentTime = UnsafeExpression "CURRENT_TIME"
869currentTime = UnsafeExpression "CURRENT_TIME"
869
870
870-- | >>> printSQL currentTimestamp
871-- | >>> printSQL currentTimestamp
871-- CURRENT_TIMESTAMP
872-- CURRENT_TIMESTAMP
872currentTimestamp
873currentTimestamp
873− :: Expression schema from grouping params (nullity 'PGtimestamptz)
874+ :: Expression db from grouping params (nullity 'PGtimestamptz)
874currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
875currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
875
876
876-- | >>> printSQL localTime
877-- | >>> printSQL localTime
877-- LOCALTIME
878-- LOCALTIME
878localTime
879localTime
879− :: Expression schema from grouping params (nullity 'PGtime)
880+ :: Expression db from grouping params (nullity 'PGtime)
880localTime = UnsafeExpression "LOCALTIME"
881localTime = UnsafeExpression "LOCALTIME"
881
882
882-- | >>> printSQL localTimestamp
883-- | >>> printSQL localTimestamp
883-- LOCALTIMESTAMP
884-- LOCALTIMESTAMP
884localTimestamp
885localTimestamp
885− :: Expression schema from grouping params (nullity 'PGtimestamp)
886+ :: Expression db from grouping params (nullity 'PGtimestamp)
886localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
887localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
887
888
888{-----------------------------------------
889{-----------------------------------------
@@ -890,7 +891,7 @@ text
890-----------------------------------------}
891-----------------------------------------}
891
892
892instance IsString
893instance IsString
893− (Expression schema from grouping params (nullity 'PGtext)) where
894+ (Expression db from grouping params (nullity 'PGtext)) where
894 fromString str = UnsafeExpression $
895 fromString str = UnsafeExpression $
895 "E\'" <> fromString (escape =<< str) <> "\'"
896 "E\'" <> fromString (escape =<< str) <> "\'"
896 where
897 where
@@ -906,36 +907,36 @@ instance IsString
906 c -> [c]
907 c -> [c]
907
908
908instance Semigroup
909instance Semigroup
909− (Expression schema from grouping params (nullity 'PGtext)) where
910+ (Expression db from grouping params (nullity 'PGtext)) where
910 (<>) = unsafeBinaryOp "||"
911 (<>) = unsafeBinaryOp "||"
911
912
912instance Monoid
913instance Monoid
913− (Expression schema from grouping params (nullity 'PGtext)) where
914+ (Expression db from grouping params (nullity 'PGtext)) where
914 mempty = fromString ""
915 mempty = fromString ""
915 mappend = (<>)
916 mappend = (<>)
916
917
917-- | >>> printSQL $ lower "ARRRGGG"
918-- | >>> printSQL $ lower "ARRRGGG"
918-- lower(E'ARRRGGG')
919-- lower(E'ARRRGGG')
919lower
920lower
920− :: Expression schema from grouping params (nullity 'PGtext)
921+ :: Expression db from grouping params (nullity 'PGtext)
921 -- ^ string to lower case
922 -- ^ string to lower case
922− -> Expression schema from grouping params (nullity 'PGtext)
923+ -> Expression db from grouping params (nullity 'PGtext)
923lower = unsafeFunction "lower"
924lower = unsafeFunction "lower"
924
925
925-- | >>> printSQL $ upper "eeee"
926-- | >>> printSQL $ upper "eeee"
926-- upper(E'eeee')
927-- upper(E'eeee')
927upper
928upper
928− :: Expression schema from grouping params (nullity 'PGtext)
929+ :: Expression db from grouping params (nullity 'PGtext)
929 -- ^ string to upper case
930 -- ^ string to upper case
930− -> Expression schema from grouping params (nullity 'PGtext)
931+ -> Expression db from grouping params (nullity 'PGtext)
931upper = unsafeFunction "upper"
932upper = unsafeFunction "upper"
932
933
933-- | >>> printSQL $ charLength "four"
934-- | >>> printSQL $ charLength "four"
934-- char_length(E'four')
935-- char_length(E'four')
935charLength
936charLength
936− :: Expression schema from grouping params (nullity 'PGtext)
937+ :: Expression db from grouping params (nullity 'PGtext)
937 -- ^ string to measure
938 -- ^ string to measure
938− -> Expression schema from grouping params (nullity 'PGint4)
939+ -> Expression db from grouping params (nullity 'PGint4)
939charLength = unsafeFunction "char_length"
940charLength = unsafeFunction "char_length"
940
941
941-- | The `like` expression returns true if the @string@ matches
942-- | The `like` expression returns true if the @string@ matches
@@ -948,11 +949,11 @@ charLength = unsafeFunction "char_length"
948-- >>> printSQL $ "abc" `like` "a%"
949-- >>> printSQL $ "abc" `like` "a%"
949-- (E'abc' LIKE E'a%')
950-- (E'abc' LIKE E'a%')
950like
951like
951− :: Expression schema from grouping params (nullity 'PGtext)
952+ :: Expression db from grouping params (nullity 'PGtext)
952 -- ^ string
953 -- ^ string
953− -> Expression schema from grouping params (nullity 'PGtext)
954+ -> Expression db from grouping params (nullity 'PGtext)
954 -- ^ pattern
955 -- ^ pattern
955− -> Expression schema from grouping params (nullity 'PGbool)
956+ -> Expression db from grouping params (nullity 'PGbool)
956like = unsafeBinaryOp "LIKE"
957like = unsafeBinaryOp "LIKE"
957
958
958{-----------------------------------------
959{-----------------------------------------
@@ -967,36 +968,36 @@ Table 9.44: json and jsonb operators
967-- | Get JSON value (object field or array element) at a key.
968-- | Get JSON value (object field or array element) at a key.
968(.->)
969(.->)
969 :: (json `In` PGJsonType, key `In` PGJsonKey)
970 :: (json `In` PGJsonType, key `In` PGJsonKey)
970− => Expression schema from grouping params (nullity json)
971+ => Expression db from grouping params (nullity json)
971− -> Expression schema from grouping params (nullity key)
972+ -> Expression db from grouping params (nullity key)
972− -> Expression schema from grouping params ('Null json)
973+ -> Expression db from grouping params ('Null json)
973infixl 8 .->
974infixl 8 .->
974(.->) = unsafeBinaryOp "->"
975(.->) = unsafeBinaryOp "->"
975
976
976-- | Get JSON value (object field or array element) at a key, as text.
977-- | Get JSON value (object field or array element) at a key, as text.
977(.->>)
978(.->>)
978 :: (json `In` PGJsonType, key `In` PGJsonKey)
979 :: (json `In` PGJsonType, key `In` PGJsonKey)
979− => Expression schema from grouping params (nullity json)
980+ => Expression db from grouping params (nullity json)
980− -> Expression schema from grouping params (nullity key)
981+ -> Expression db from grouping params (nullity key)
981− -> Expression schema from grouping params ('Null 'PGtext)
982+ -> Expression db from grouping params ('Null 'PGtext)
982infixl 8 .->>
983infixl 8 .->>
983(.->>) = unsafeBinaryOp "->>"
984(.->>) = unsafeBinaryOp "->>"
984
985
985-- | Get JSON value at a specified path.
986-- | Get JSON value at a specified path.
986(.#>)
987(.#>)
987 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
988 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
988− => Expression schema from grouping params (nullity json)
989+ => Expression db from grouping params (nullity json)
989− -> Expression schema from grouping params (nullity path)
990+ -> Expression db from grouping params (nullity path)
990− -> Expression schema from grouping params ('Null json)
991+ -> Expression db from grouping params ('Null json)
991infixl 8 .#>
992infixl 8 .#>
992(.#>) = unsafeBinaryOp "#>"
993(.#>) = unsafeBinaryOp "#>"
993
994
994-- | Get JSON value at a specified path as text.
995-- | Get JSON value at a specified path as text.
995(.#>>)
996(.#>>)
996 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
997 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
997− => Expression schema from grouping params (nullity json)
998+ => Expression db from grouping params (nullity json)
998− -> Expression schema from grouping params (nullity path)
999+ -> Expression db from grouping params (nullity path)
999− -> Expression schema from grouping params ('Null 'PGtext)
1000+ -> Expression db from grouping params ('Null 'PGtext)
1000infixl 8 .#>>
1001infixl 8 .#>>
1001(.#>>) = unsafeBinaryOp "#>>"
1002(.#>>) = unsafeBinaryOp "#>>"
1002
1003
@@ -1005,48 +1006,48 @@ infixl 8 .#>>
1005-- | Does the left JSON value contain the right JSON path/value entries at the
1006-- | Does the left JSON value contain the right JSON path/value entries at the
1006-- top level?
1007-- top level?
1007(.@>)
1008(.@>)
1008− :: Expression schema from grouping params (nullity 'PGjsonb)
1009+ :: Expression db from grouping params (nullity 'PGjsonb)
1009− -> Expression schema from grouping params (nullity 'PGjsonb)
1010+ -> Expression db from grouping params (nullity 'PGjsonb)
1010− -> Condition schema from grouping params
1011+ -> Condition db from grouping params
1011infixl 9 .@>
1012infixl 9 .@>
1012(.@>) = unsafeBinaryOp "@>"
1013(.@>) = unsafeBinaryOp "@>"
1013
1014
1014-- | Are the left JSON path/value entries contained at the top level within the
1015-- | Are the left JSON path/value entries contained at the top level within the
1015-- right JSON value?
1016-- right JSON value?
1016(.<@)
1017(.<@)
1017− :: Expression schema from grouping params (nullity 'PGjsonb)
1018+ :: Expression db from grouping params (nullity 'PGjsonb)
1018− -> Expression schema from grouping params (nullity 'PGjsonb)
1019+ -> Expression db from grouping params (nullity 'PGjsonb)
1019− -> Condition schema from grouping params
1020+ -> Condition db from grouping params
1020infixl 9 .<@
1021infixl 9 .<@
1021(.<@) = unsafeBinaryOp "<@"
1022(.<@) = unsafeBinaryOp "<@"
1022
1023
1023-- | Does the string exist as a top-level key within the JSON value?
1024-- | Does the string exist as a top-level key within the JSON value?
1024(.?)
1025(.?)
1025− :: Expression schema from grouping params (nullity 'PGjsonb)
1026+ :: Expression db from grouping params (nullity 'PGjsonb)
1026− -> Expression schema from grouping params (nullity 'PGtext)
1027+ -> Expression db from grouping params (nullity 'PGtext)
1027− -> Condition schema from grouping params
1028+ -> Condition db from grouping params
1028infixl 9 .?
1029infixl 9 .?
1029(.?) = unsafeBinaryOp "?"
1030(.?) = unsafeBinaryOp "?"
1030
1031
1031-- | Do any of these array strings exist as top-level keys?
1032-- | Do any of these array strings exist as top-level keys?
1032(.?|)
1033(.?|)
1033− :: Expression schema from grouping params (nullity 'PGjsonb)
1034+ :: Expression db from grouping params (nullity 'PGjsonb)
1034− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1035+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1035− -> Condition schema from grouping params
1036+ -> Condition db from grouping params
1036infixl 9 .?|
1037infixl 9 .?|
1037(.?|) = unsafeBinaryOp "?|"
1038(.?|) = unsafeBinaryOp "?|"
1038
1039
1039-- | Do all of these array strings exist as top-level keys?
1040-- | Do all of these array strings exist as top-level keys?
1040(.?&)
1041(.?&)
1041− :: Expression schema from grouping params (nullity 'PGjsonb)
1042+ :: Expression db from grouping params (nullity 'PGjsonb)
1042− -> Expression schema from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1043+ -> Expression db from grouping params (nullity ('PGvararray ('NotNull 'PGtext)))
1043− -> Condition schema from grouping params
1044+ -> Condition db from grouping params
1044infixl 9 .?&
1045infixl 9 .?&
1045(.?&) = unsafeBinaryOp "?&"
1046(.?&) = unsafeBinaryOp "?&"
1046
1047
1047-- | Concatenate two jsonb values into a new jsonb value.
1048-- | Concatenate two jsonb values into a new jsonb value.
1048instance
1049instance
1049− Semigroup (Expression schema from grouping param (nullity 'PGjsonb)) where
1050+ Semigroup (Expression db from grouping param (nullity 'PGjsonb)) where
1050 (<>) = unsafeBinaryOp "||"
1051 (<>) = unsafeBinaryOp "||"
1051
1052
1052-- | Delete a key or keys from a JSON object, or remove an array element.
1053-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1063,9 +1064,9 @@ instance
1063-- count from the end). Throws an error if top level container is not an array.
1064-- count from the end). Throws an error if top level container is not an array.
1064(.-.)
1065(.-.)
1065 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1066 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1066− => Expression schema from grouping params (nullity 'PGjsonb)
1067+ => Expression db from grouping params (nullity 'PGjsonb)
1067− -> Expression schema from grouping params (nullity key)
1068+ -> Expression db from grouping params (nullity key)
1068− -> Expression schema from grouping params (nullity 'PGjsonb)
1069+ -> Expression db from grouping params (nullity 'PGjsonb)
1069infixl 6 .-.
1070infixl 6 .-.
1070(.-.) = unsafeBinaryOp "-"
1071(.-.) = unsafeBinaryOp "-"
1071
1072
@@ -1073,9 +1074,9 @@ infixl 6 .-.
1073-- integers count from the end)
1074-- integers count from the end)
1074(#-.)
1075(#-.)
1075 :: PGTextArray "(#-.)" arrayty
1076 :: PGTextArray "(#-.)" arrayty
1076− => Expression schema from grouping params (nullity 'PGjsonb)
1077+ => Expression db from grouping params (nullity 'PGjsonb)
1077− -> Expression schema from grouping params (nullity arrayty)
1078+ -> Expression db from grouping params (nullity arrayty)
1078− -> Expression schema from grouping params (nullity 'PGjsonb)
1079+ -> Expression db from grouping params (nullity 'PGjsonb)
1079infixl 6 #-.
1080infixl 6 #-.
1080(#-.) = unsafeBinaryOp "#-"
1081(#-.) = unsafeBinaryOp "#-"
1081
1082
@@ -1086,14 +1087,14 @@ Table 9.45: JSON creation functions
1086-- | Literal binary JSON
1087-- | Literal binary JSON
1087jsonbLit
1088jsonbLit
1088 :: JSON.ToJSON x
1089 :: JSON.ToJSON x
1089− => x -> Expression schema from grouping params (nullity 'PGjsonb)
1090+ => x -> Expression db from grouping params (nullity 'PGjsonb)
1090jsonbLit = cast jsonb . UnsafeExpression
1091jsonbLit = cast jsonb . UnsafeExpression
1091 . singleQuotedUtf8 . toStrict . JSON.encode
1092 . singleQuotedUtf8 . toStrict . JSON.encode
1092
1093
1093-- | Literal JSON
1094-- | Literal JSON
1094jsonLit
1095jsonLit
1095 :: JSON.ToJSON x
1096 :: JSON.ToJSON x
1096− => x -> Expression schema from grouping params (nullity 'PGjson)
1097+ => x -> Expression db from grouping params (nullity 'PGjson)
1097jsonLit = cast json . UnsafeExpression
1098jsonLit = cast json . UnsafeExpression
1098 . singleQuotedUtf8 . toStrict . JSON.encode
1099 . singleQuotedUtf8 . toStrict . JSON.encode
1099
1100
@@ -1104,8 +1105,8 @@ jsonLit = cast json . UnsafeExpression
1104-- number, a Boolean, or a null value, the text representation will be used, in
1105-- number, a Boolean, or a null value, the text representation will be used, in
1105-- such a fashion that it is a valid json value.
1106-- such a fashion that it is a valid json value.
1106toJson
1107toJson
1107− :: Expression schema from grouping params (nullity ty)
1108+ :: Expression db from grouping params (nullity ty)
1108− -> Expression schema from grouping params (nullity 'PGjson)
1109+ -> Expression db from grouping params (nullity 'PGjson)
1109toJson = unsafeFunction "to_json"
1110toJson = unsafeFunction "to_json"
1110
1111
1111-- | Returns the value as jsonb. Arrays and composites are converted
1112-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1115,43 +1116,43 @@ toJson = unsafeFunction "to_json"
1115-- number, a Boolean, or a null value, the text representation will be used, in
1116-- number, a Boolean, or a null value, the text representation will be used, in
1116-- such a fashion that it is a valid jsonb value.
1117-- such a fashion that it is a valid jsonb value.
1117toJsonb
1118toJsonb
1118− :: Expression schema from grouping params (nullity ty)
1119+ :: Expression db from grouping params (nullity ty)
1119− -> Expression schema from grouping params (nullity 'PGjsonb)
1120+ -> Expression db from grouping params (nullity 'PGjsonb)
1120toJsonb = unsafeFunction "to_jsonb"
1121toJsonb = unsafeFunction "to_jsonb"
1121
1122
1122-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1123-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1123-- becomes a JSON array of arrays.
1124-- becomes a JSON array of arrays.
1124arrayToJson
1125arrayToJson
1125 :: PGArray "arrayToJson" arr
1126 :: PGArray "arrayToJson" arr
1126− => Expression schema from grouping params (nullity arr)
1127+ => Expression db from grouping params (nullity arr)
1127− -> Expression schema from grouping params (nullity 'PGjson)
1128+ -> Expression db from grouping params (nullity 'PGjson)
1128arrayToJson = unsafeFunction "array_to_json"
1129arrayToJson = unsafeFunction "array_to_json"
1129
1130
1130-- | Returns the row as a JSON object.
1131-- | Returns the row as a JSON object.
1131rowToJson
1132rowToJson
1132− :: Expression schema from grouping params (nullity ('PGcomposite ty))
1133+ :: Expression db from grouping params (nullity ('PGcomposite ty))
1133− -> Expression schema from grouping params (nullity 'PGjson)
1134+ -> Expression db from grouping params (nullity 'PGjson)
1134rowToJson = unsafeFunction "row_to_json"
1135rowToJson = unsafeFunction "row_to_json"
1135
1136
1136-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1137-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1137-- argument list.
1138-- argument list.
1138jsonBuildArray
1139jsonBuildArray
1139 :: SListI elems
1140 :: SListI elems
1140− => NP (Expression schema from grouping params) elems
1141+ => NP (Expression db from grouping params) elems
1141− -> Expression schema from grouping params (nullity 'PGjson)
1142+ -> Expression db from grouping params (nullity 'PGjson)
1142jsonBuildArray = unsafeVariadicFunction "json_build_array"
1143jsonBuildArray = unsafeVariadicFunction "json_build_array"
1143
1144
1144-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1145-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1145-- variadic argument list.
1146-- variadic argument list.
1146jsonbBuildArray
1147jsonbBuildArray
1147 :: SListI elems
1148 :: SListI elems
1148− => NP (Expression schema from grouping params) elems
1149+ => NP (Expression db from grouping params) elems
1149− -> Expression schema from grouping params (nullity 'PGjsonb)
1150+ -> Expression db from grouping params (nullity 'PGjsonb)
1150jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1151jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1151
1152
1152unsafeRowFunction
1153unsafeRowFunction
1153 :: All Top elems
1154 :: All Top elems
1154− => NP (Aliased (Expression schema from grouping params)) elems
1155+ => NP (Aliased (Expression db from grouping params)) elems
1155 -> [ByteString]
1156 -> [ByteString]
1156unsafeRowFunction =
1157unsafeRowFunction =
1157 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
1158 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1163,8 +1164,8 @@ unsafeRowFunction =
1163-- and values.
1164-- and values.
1164jsonBuildObject
1165jsonBuildObject
1165 :: All Top elems
1166 :: All Top elems
1166− => NP (Aliased (Expression schema from grouping params)) elems
1167+ => NP (Aliased (Expression db from grouping params)) elems
1167− -> Expression schema from grouping params (nullity 'PGjson)
1168+ -> Expression db from grouping params (nullity 'PGjson)
1168jsonBuildObject
1169jsonBuildObject
1169 = unsafeFunction "json_build_object"
1170 = unsafeFunction "json_build_object"
1170 . UnsafeExpression
1171 . UnsafeExpression
@@ -1176,8 +1177,8 @@ jsonBuildObject
1176-- between text and values.
1177-- between text and values.
1177jsonbBuildObject
1178jsonbBuildObject
1178 :: All Top elems
1179 :: All Top elems
1179− => NP (Aliased (Expression schema from grouping params)) elems
1180+ => NP (Aliased (Expression db from grouping params)) elems
1180− -> Expression schema from grouping params (nullity 'PGjsonb)
1181+ -> Expression db from grouping params (nullity 'PGjsonb)
1181jsonbBuildObject
1182jsonbBuildObject
1182 = unsafeFunction "jsonb_build_object"
1183 = unsafeFunction "jsonb_build_object"
1183 . UnsafeExpression
1184 . UnsafeExpression
@@ -1190,8 +1191,8 @@ jsonbBuildObject
1190-- array has exactly two elements, which are taken as a key/value pair.
1191-- array has exactly two elements, which are taken as a key/value pair.
1191jsonObject
1192jsonObject
1192 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1193 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1193− => Expression schema from grouping params (nullity arr)
1194+ => Expression db from grouping params (nullity arr)
1194− -> Expression schema from grouping params (nullity 'PGjson)
1195+ -> Expression db from grouping params (nullity 'PGjson)
1195jsonObject = unsafeFunction "json_object"
1196jsonObject = unsafeFunction "json_object"
1196
1197
1197-- | Builds a binary JSON object out of a text array. The array must have either
1198-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1200,8 +1201,8 @@ jsonObject = unsafeFunction "json_object"
1200-- array has exactly two elements, which are taken as a key/value pair.
1201-- array has exactly two elements, which are taken as a key/value pair.
1201jsonbObject
1202jsonbObject
1202 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1203 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1203− => Expression schema from grouping params (nullity arr)
1204+ => Expression db from grouping params (nullity arr)
1204− -> Expression schema from grouping params (nullity 'PGjsonb)
1205+ -> Expression db from grouping params (nullity 'PGjsonb)
1205jsonbObject = unsafeFunction "jsonb_object"
1206jsonbObject = unsafeFunction "jsonb_object"
1206
1207
1207-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1208-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1209,9 +1210,9 @@ jsonbObject = unsafeFunction "jsonb_object"
1209jsonZipObject
1210jsonZipObject
1210 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1211 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1211 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1212 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1212− => Expression schema from grouping params (nullity keysArray)
1213+ => Expression db from grouping params (nullity keysArray)
1213− -> Expression schema from grouping params (nullity valuesArray)
1214+ -> Expression db from grouping params (nullity valuesArray)
1214− -> Expression schema from grouping params (nullity 'PGjson)
1215+ -> Expression db from grouping params (nullity 'PGjson)
1215jsonZipObject ks vs =
1216jsonZipObject ks vs =
1216 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1217 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1217
1218
@@ -1221,9 +1222,9 @@ jsonZipObject ks vs =
1221jsonbZipObject
1222jsonbZipObject
1222 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1223 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1223 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1224 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1224− => Expression schema from grouping params (nullity keysArray)
1225+ => Expression db from grouping params (nullity keysArray)
1225− -> Expression schema from grouping params (nullity valuesArray)
1226+ -> Expression db from grouping params (nullity valuesArray)
1226− -> Expression schema from grouping params (nullity 'PGjsonb)
1227+ -> Expression db from grouping params (nullity 'PGjsonb)
1227jsonbZipObject ks vs =
1228jsonbZipObject ks vs =
1228 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1229 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1229
1230
@@ -1233,23 +1234,23 @@ Table 9.46: JSON processing functions
1233
1234
1234-- | Returns the number of elements in the outermost JSON array.
1235-- | Returns the number of elements in the outermost JSON array.
1235jsonArrayLength
1236jsonArrayLength
1236− :: Expression schema from grouping params (nullity 'PGjson)
1237+ :: Expression db from grouping params (nullity 'PGjson)
1237− -> Expression schema from grouping params (nullity 'PGint4)
1238+ -> Expression db from grouping params (nullity 'PGint4)
1238jsonArrayLength = unsafeFunction "json_array_length"
1239jsonArrayLength = unsafeFunction "json_array_length"
1239
1240
1240-- | Returns the number of elements in the outermost binary JSON array.
1241-- | Returns the number of elements in the outermost binary JSON array.
1241jsonbArrayLength
1242jsonbArrayLength
1242− :: Expression schema from grouping params (nullity 'PGjsonb)
1243+ :: Expression db from grouping params (nullity 'PGjsonb)
1243− -> Expression schema from grouping params (nullity 'PGint4)
1244+ -> Expression db from grouping params (nullity 'PGint4)
1244jsonbArrayLength = unsafeFunction "jsonb_array_length"
1245jsonbArrayLength = unsafeFunction "jsonb_array_length"
1245
1246
1246-- | Returns JSON value pointed to by the given path (equivalent to #>
1247-- | Returns JSON value pointed to by the given path (equivalent to #>
1247-- operator).
1248-- operator).
1248jsonExtractPath
1249jsonExtractPath
1249 :: SListI elems
1250 :: SListI elems
1250− => Expression schema from grouping params (nullity 'PGjson)
1251+ => Expression db from grouping params (nullity 'PGjson)
1251− -> NP (Expression schema from grouping params) elems
1252+ -> NP (Expression db from grouping params) elems
1252− -> Expression schema from grouping params (nullity 'PGjsonb)
1253+ -> Expression db from grouping params (nullity 'PGjsonb)
1253jsonExtractPath x xs =
1254jsonExtractPath x xs =
1254 unsafeVariadicFunction "json_extract_path" (x :* xs)
1255 unsafeVariadicFunction "json_extract_path" (x :* xs)
1255
1256
@@ -1257,9 +1258,9 @@ jsonExtractPath x xs =
1257-- operator).
1258-- operator).
1258jsonbExtractPath
1259jsonbExtractPath
1259 :: SListI elems
1260 :: SListI elems
1260− => Expression schema from grouping params (nullity 'PGjsonb)
1261+ => Expression db from grouping params (nullity 'PGjsonb)
1261− -> NP (Expression schema from grouping params) elems
1262+ -> NP (Expression db from grouping params) elems
1262− -> Expression schema from grouping params (nullity 'PGjsonb)
1263+ -> Expression db from grouping params (nullity 'PGjsonb)
1263jsonbExtractPath x xs =
1264jsonbExtractPath x xs =
1264 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1265 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1265
1266
@@ -1267,9 +1268,9 @@ jsonbExtractPath x xs =
1267-- operator), as text.
1268-- operator), as text.
1268jsonExtractPathAsText
1269jsonExtractPathAsText
1269 :: SListI elems
1270 :: SListI elems
1270− => Expression schema from grouping params (nullity 'PGjson)
1271+ => Expression db from grouping params (nullity 'PGjson)
1271− -> NP (Expression schema from grouping params) elems
1272+ -> NP (Expression db from grouping params) elems
1272− -> Expression schema from grouping params (nullity 'PGjson)
1273+ -> Expression db from grouping params (nullity 'PGjson)
1273jsonExtractPathAsText x xs =
1274jsonExtractPathAsText x xs =
1274 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1275 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1275
1276
@@ -1277,38 +1278,38 @@ jsonExtractPathAsText x xs =
1277-- operator), as text.
1278-- operator), as text.
1278jsonbExtractPathAsText
1279jsonbExtractPathAsText
1279 :: SListI elems
1280 :: SListI elems
1280− => Expression schema from grouping params (nullity 'PGjsonb)
1281+ => Expression db from grouping params (nullity 'PGjsonb)
1281− -> NP (Expression schema from grouping params) elems
1282+ -> NP (Expression db from grouping params) elems
1282− -> Expression schema from grouping params (nullity 'PGjsonb)
1283+ -> Expression db from grouping params (nullity 'PGjsonb)
1283jsonbExtractPathAsText x xs =
1284jsonbExtractPathAsText x xs =
1284 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1285 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1285
1286
1286-- | Returns the type of the outermost JSON value as a text string. Possible
1287-- | Returns the type of the outermost JSON value as a text string. Possible
1287-- types are object, array, string, number, boolean, and null.
1288-- types are object, array, string, number, boolean, and null.
1288jsonTypeof
1289jsonTypeof
1289− :: Expression schema from grouping params (nullity 'PGjson)
1290+ :: Expression db from grouping params (nullity 'PGjson)
1290− -> Expression schema from grouping params (nullity 'PGtext)
1291+ -> Expression db from grouping params (nullity 'PGtext)
1291jsonTypeof = unsafeFunction "json_typeof"
1292jsonTypeof = unsafeFunction "json_typeof"
1292
1293
1293-- | Returns the type of the outermost binary JSON value as a text string.
1294-- | Returns the type of the outermost binary JSON value as a text string.
1294-- Possible types are object, array, string, number, boolean, and null.
1295-- Possible types are object, array, string, number, boolean, and null.
1295jsonbTypeof
1296jsonbTypeof
1296− :: Expression schema from grouping params (nullity 'PGjsonb)
1297+ :: Expression db from grouping params (nullity 'PGjsonb)
1297− -> Expression schema from grouping params (nullity 'PGtext)
1298+ -> Expression db from grouping params (nullity 'PGtext)
1298jsonbTypeof = unsafeFunction "jsonb_typeof"
1299jsonbTypeof = unsafeFunction "jsonb_typeof"
1299
1300
1300-- | Returns its argument with all object fields that have null values omitted.
1301-- | Returns its argument with all object fields that have null values omitted.
1301-- Other null values are untouched.
1302-- Other null values are untouched.
1302jsonStripNulls
1303jsonStripNulls
1303− :: Expression schema from grouping params (nullity 'PGjson)
1304+ :: Expression db from grouping params (nullity 'PGjson)
1304− -> Expression schema from grouping params (nullity 'PGjson)
1305+ -> Expression db from grouping params (nullity 'PGjson)
1305jsonStripNulls = unsafeFunction "json_strip_nulls"
1306jsonStripNulls = unsafeFunction "json_strip_nulls"
1306
1307
1307-- | Returns its argument with all object fields that have null values omitted.
1308-- | Returns its argument with all object fields that have null values omitted.
1308-- Other null values are untouched.
1309-- Other null values are untouched.
1309jsonbStripNulls
1310jsonbStripNulls
1310− :: Expression schema from grouping params (nullity 'PGjsonb)
1311+ :: Expression db from grouping params (nullity 'PGjsonb)
1311− -> Expression schema from grouping params (nullity 'PGjsonb)
1312+ -> Expression db from grouping params (nullity 'PGjsonb)
1312jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1313jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1313
1314
1314-- | @ jsonbSet target path new_value create_missing @
1315-- | @ jsonbSet target path new_value create_missing @
@@ -1320,11 +1321,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1320-- arrays.
1321-- arrays.
1321jsonbSet
1322jsonbSet
1322 :: PGTextArray "jsonbSet" arr
1323 :: PGTextArray "jsonbSet" arr
1323− => Expression schema from grouping params (nullity 'PGjsonb)
1324+ => Expression db from grouping params (nullity 'PGjsonb)
1324− -> Expression schema from grouping params (nullity arr)
1325+ -> Expression db from grouping params (nullity arr)
1325− -> Expression schema from grouping params (nullity 'PGjsonb)
1326+ -> Expression db from grouping params (nullity 'PGjsonb)
1326− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1327+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1327− -> Expression schema from grouping params (nullity 'PGjsonb)
1328+ -> Expression db from grouping params (nullity 'PGjsonb)
1328jsonbSet tgt path val createMissing = case createMissing of
1329jsonbSet tgt path val createMissing = case createMissing of
1329 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1330 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1330 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
1331 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1339,19 +1340,19 @@ jsonbSet tgt path val createMissing = case createMissing of
1339-- in path count from the end of JSON arrays.
1340-- in path count from the end of JSON arrays.
1340jsonbInsert
1341jsonbInsert
1341 :: PGTextArray "jsonbInsert" arr
1342 :: PGTextArray "jsonbInsert" arr
1342− => Expression schema from grouping params (nullity 'PGjsonb)
1343+ => Expression db from grouping params (nullity 'PGjsonb)
1343− -> Expression schema from grouping params (nullity arr)
1344+ -> Expression db from grouping params (nullity arr)
1344− -> Expression schema from grouping params (nullity 'PGjsonb)
1345+ -> Expression db from grouping params (nullity 'PGjsonb)
1345− -> Maybe (Expression schema from grouping params (nullity 'PGbool))
1346+ -> Maybe (Expression db from grouping params (nullity 'PGbool))
1346− -> Expression schema from grouping params (nullity 'PGjsonb)
1347+ -> Expression db from grouping params (nullity 'PGjsonb)
1347jsonbInsert tgt path val insertAfter = case insertAfter of
1348jsonbInsert tgt path val insertAfter = case insertAfter of
1348 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1349 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1349 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1350 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1350
1351
1351-- | Returns its argument as indented JSON text.
1352-- | Returns its argument as indented JSON text.
1352jsonbPretty
1353jsonbPretty
1353− :: Expression schema from grouping params (nullity 'PGjsonb)
1354+ :: Expression db from grouping params (nullity 'PGjsonb)
1354− -> Expression schema from grouping params (nullity 'PGtext)
1355+ -> Expression db from grouping params (nullity 'PGtext)
1355jsonbPretty = unsafeFunction "jsonb_pretty"
1356jsonbPretty = unsafeFunction "jsonb_pretty"
1356
1357
1357{-----------------------------------------
1358{-----------------------------------------
@@ -1361,54 +1362,54 @@ aggregation
1361-- | escape hatch to define aggregate functions
1362-- | escape hatch to define aggregate functions
1362unsafeAggregate
1363unsafeAggregate
1363 :: ByteString -- ^ aggregate function
1364 :: ByteString -- ^ aggregate function
1364− -> Expression schema from 'Ungrouped params (xty)
1365+ -> Expression db from 'Ungrouped params (xty)
1365− -> Expression schema from ('Grouped bys) params (yty)
1366+ -> Expression db from ('Grouped bys) params (yty)
1366unsafeAggregate fun x = UnsafeExpression $ mconcat
1367unsafeAggregate fun x = UnsafeExpression $ mconcat
1367 [fun, "(", renderExpression x, ")"]
1368 [fun, "(", renderExpression x, ")"]
1368
1369
1369-- | escape hatch to define aggregate functions over distinct values
1370-- | escape hatch to define aggregate functions over distinct values
1370unsafeAggregateDistinct
1371unsafeAggregateDistinct
1371 :: ByteString -- ^ aggregate function
1372 :: ByteString -- ^ aggregate function
1372− -> Expression schema from 'Ungrouped params (xty)
1373+ -> Expression db from 'Ungrouped params (xty)
1373− -> Expression schema from ('Grouped bys) params (yty)
1374+ -> Expression db from ('Grouped bys) params (yty)
1374unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1375unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1375 [fun, "(DISTINCT ", renderExpression x, ")"]
1376 [fun, "(DISTINCT ", renderExpression x, ")"]
1376
1377
1377-- | >>> :{
1378-- | >>> :{
1378-- let
1379-- 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)
1380-- expression = sum_ #col
1381-- expression = sum_ #col
1381-- in printSQL expression
1382-- in printSQL expression
1382-- :}
1383-- :}
1383-- sum("col")
1384-- sum("col")
1384sum_
1385sum_
1385 :: ty `In` PGNum
1386 :: ty `In` PGNum
1386− => Expression schema from 'Ungrouped params (nullity ty)
1387+ => Expression db from 'Ungrouped params (nullity ty)
1387 -- ^ what to sum
1388 -- ^ what to sum
1388− -> Expression schema from ('Grouped bys) params (nullity ty)
1389+ -> Expression db from ('Grouped bys) params (nullity ty)
1389sum_ = unsafeAggregate "sum"
1390sum_ = unsafeAggregate "sum"
1390
1391
1391-- | >>> :{
1392-- | >>> :{
1392-- let
1393-- 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)
1394-- expression = sumDistinct #col
1395-- expression = sumDistinct #col
1395-- in printSQL expression
1396-- in printSQL expression
1396-- :}
1397-- :}
1397-- sum(DISTINCT "col")
1398-- sum(DISTINCT "col")
1398sumDistinct
1399sumDistinct
1399 :: ty `In` PGNum
1400 :: ty `In` PGNum
1400− => Expression schema from 'Ungrouped params (nullity ty)
1401+ => Expression db from 'Ungrouped params (nullity ty)
1401 -- ^ what to sum
1402 -- ^ what to sum
1402− -> Expression schema from ('Grouped bys) params (nullity ty)
1403+ -> Expression db from ('Grouped bys) params (nullity ty)
1403sumDistinct = unsafeAggregateDistinct "sum"
1404sumDistinct = unsafeAggregateDistinct "sum"
1404
1405
1405-- | A constraint for `PGType`s that you can take averages of and the resulting
1406-- | A constraint for `PGType`s that you can take averages of and the resulting
1406-- `PGType`.
1407-- `PGType`.
1407class PGAvg ty avg | ty -> avg where
1408class PGAvg ty avg | ty -> avg where
1408 avg, avgDistinct
1409 avg, avgDistinct
1409− :: Expression schema from 'Ungrouped params (nullity ty)
1410+ :: Expression db from 'Ungrouped params (nullity ty)
1410 -- ^ what to average
1411 -- ^ what to average
1411− -> Expression schema from ('Grouped bys) params (nullity avg)
1412+ -> Expression db from ('Grouped bys) params (nullity avg)
1412 avg = unsafeAggregate "avg"
1413 avg = unsafeAggregate "avg"
1413 avgDistinct = unsafeAggregateDistinct "avg"
1414 avgDistinct = unsafeAggregateDistinct "avg"
1414instance PGAvg 'PGint2 'PGnumeric
1415instance PGAvg 'PGint2 'PGnumeric
@@ -1421,110 +1422,110 @@ instance PGAvg 'PGinterval 'PGinterval
1421
1422
1422-- | >>> :{
1423-- | >>> :{
1423-- let
1424-- 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)
1425-- expression = bitAnd #col
1426-- expression = bitAnd #col
1426-- in printSQL expression
1427-- in printSQL expression
1427-- :}
1428-- :}
1428-- bit_and("col")
1429-- bit_and("col")
1429bitAnd
1430bitAnd
1430 :: int `In` PGIntegral
1431 :: int `In` PGIntegral
1431− => Expression schema from 'Ungrouped params (nullity int)
1432+ => Expression db from 'Ungrouped params (nullity int)
1432 -- ^ what to aggregate
1433 -- ^ what to aggregate
1433− -> Expression schema from ('Grouped bys) params (nullity int)
1434+ -> Expression db from ('Grouped bys) params (nullity int)
1434bitAnd = unsafeAggregate "bit_and"
1435bitAnd = unsafeAggregate "bit_and"
1435
1436
1436-- | >>> :{
1437-- | >>> :{
1437-- let
1438-- 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)
1439-- expression = bitOr #col
1440-- expression = bitOr #col
1440-- in printSQL expression
1441-- in printSQL expression
1441-- :}
1442-- :}
1442-- bit_or("col")
1443-- bit_or("col")
1443bitOr
1444bitOr
1444 :: int `In` PGIntegral
1445 :: int `In` PGIntegral
1445− => Expression schema from 'Ungrouped params (nullity int)
1446+ => Expression db from 'Ungrouped params (nullity int)
1446 -- ^ what to aggregate
1447 -- ^ what to aggregate
1447− -> Expression schema from ('Grouped bys) params (nullity int)
1448+ -> Expression db from ('Grouped bys) params (nullity int)
1448bitOr = unsafeAggregate "bit_or"
1449bitOr = unsafeAggregate "bit_or"
1449
1450
1450-- | >>> :{
1451-- | >>> :{
1451-- let
1452-- 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)
1453-- expression = bitAndDistinct #col
1454-- expression = bitAndDistinct #col
1454-- in printSQL expression
1455-- in printSQL expression
1455-- :}
1456-- :}
1456-- bit_and(DISTINCT "col")
1457-- bit_and(DISTINCT "col")
1457bitAndDistinct
1458bitAndDistinct
1458 :: int `In` PGIntegral
1459 :: int `In` PGIntegral
1459− => Expression schema from 'Ungrouped params (nullity int)
1460+ => Expression db from 'Ungrouped params (nullity int)
1460 -- ^ what to aggregate
1461 -- ^ what to aggregate
1461− -> Expression schema from ('Grouped bys) params (nullity int)
1462+ -> Expression db from ('Grouped bys) params (nullity int)
1462bitAndDistinct = unsafeAggregateDistinct "bit_and"
1463bitAndDistinct = unsafeAggregateDistinct "bit_and"
1463
1464
1464-- | >>> :{
1465-- | >>> :{
1465-- let
1466-- 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)
1467-- expression = bitOrDistinct #col
1468-- expression = bitOrDistinct #col
1468-- in printSQL expression
1469-- in printSQL expression
1469-- :}
1470-- :}
1470-- bit_or(DISTINCT "col")
1471-- bit_or(DISTINCT "col")
1471bitOrDistinct
1472bitOrDistinct
1472 :: int `In` PGIntegral
1473 :: int `In` PGIntegral
1473− => Expression schema from 'Ungrouped params (nullity int)
1474+ => Expression db from 'Ungrouped params (nullity int)
1474 -- ^ what to aggregate
1475 -- ^ what to aggregate
1475− -> Expression schema from ('Grouped bys) params (nullity int)
1476+ -> Expression db from ('Grouped bys) params (nullity int)
1476bitOrDistinct = unsafeAggregateDistinct "bit_or"
1477bitOrDistinct = unsafeAggregateDistinct "bit_or"
1477
1478
1478-- | >>> :{
1479-- | >>> :{
1479-- let
1480-- 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)
1481-- expression = boolAnd #col
1482-- expression = boolAnd #col
1482-- in printSQL expression
1483-- in printSQL expression
1483-- :}
1484-- :}
1484-- bool_and("col")
1485-- bool_and("col")
1485boolAnd
1486boolAnd
1486− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1487+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
1487 -- ^ what to aggregate
1488 -- ^ what to aggregate
1488− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1489+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1489boolAnd = unsafeAggregate "bool_and"
1490boolAnd = unsafeAggregate "bool_and"
1490
1491
1491-- | >>> :{
1492-- | >>> :{
1492-- let
1493-- 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)
1494-- expression = boolOr #col
1495-- expression = boolOr #col
1495-- in printSQL expression
1496-- in printSQL expression
1496-- :}
1497-- :}
1497-- bool_or("col")
1498-- bool_or("col")
1498boolOr
1499boolOr
1499− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1500+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
1500 -- ^ what to aggregate
1501 -- ^ what to aggregate
1501− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1502+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1502boolOr = unsafeAggregate "bool_or"
1503boolOr = unsafeAggregate "bool_or"
1503
1504
1504-- | >>> :{
1505-- | >>> :{
1505-- let
1506-- 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)
1507-- expression = boolAndDistinct #col
1508-- expression = boolAndDistinct #col
1508-- in printSQL expression
1509-- in printSQL expression
1509-- :}
1510-- :}
1510-- bool_and(DISTINCT "col")
1511-- bool_and(DISTINCT "col")
1511boolAndDistinct
1512boolAndDistinct
1512− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1513+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
1513 -- ^ what to aggregate
1514 -- ^ what to aggregate
1514− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1515+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1515boolAndDistinct = unsafeAggregateDistinct "bool_and"
1516boolAndDistinct = unsafeAggregateDistinct "bool_and"
1516
1517
1517-- | >>> :{
1518-- | >>> :{
1518-- let
1519-- 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)
1520-- expression = boolOrDistinct #col
1521-- expression = boolOrDistinct #col
1521-- in printSQL expression
1522-- in printSQL expression
1522-- :}
1523-- :}
1523-- bool_or(DISTINCT "col")
1524-- bool_or(DISTINCT "col")
1524boolOrDistinct
1525boolOrDistinct
1525− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1526+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
1526 -- ^ what to aggregate
1527 -- ^ what to aggregate
1527− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1528+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1528boolOrDistinct = unsafeAggregateDistinct "bool_or"
1529boolOrDistinct = unsafeAggregateDistinct "bool_or"
1529
1530
1530-- | A special aggregation that does not require an input
1531-- | A special aggregation that does not require an input
@@ -1532,70 +1533,70 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
1532-- >>> printSQL countStar
1533-- >>> printSQL countStar
1533-- count(*)
1534-- count(*)
1534countStar
1535countStar
1535− :: Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1536+ :: Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1536countStar = UnsafeExpression $ "count(*)"
1537countStar = UnsafeExpression $ "count(*)"
1537
1538
1538-- | >>> :{
1539-- | >>> :{
1539-- let
1540-- 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)
1541-- expression = count #col
1542-- expression = count #col
1542-- in printSQL expression
1543-- in printSQL expression
1543-- :}
1544-- :}
1544-- count("col")
1545-- count("col")
1545count
1546count
1546− :: Expression schema from 'Ungrouped params ty
1547+ :: Expression db from 'Ungrouped params ty
1547 -- ^ what to count
1548 -- ^ what to count
1548− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1549+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1549count = unsafeAggregate "count"
1550count = unsafeAggregate "count"
1550
1551
1551-- | >>> :{
1552-- | >>> :{
1552-- let
1553-- 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)
1554-- expression = countDistinct #col
1555-- expression = countDistinct #col
1555-- in printSQL expression
1556-- in printSQL expression
1556-- :}
1557-- :}
1557-- count(DISTINCT "col")
1558-- count(DISTINCT "col")
1558countDistinct
1559countDistinct
1559− :: Expression schema from 'Ungrouped params ty
1560+ :: Expression db from 'Ungrouped params ty
1560 -- ^ what to count
1561 -- ^ what to count
1561− -> Expression schema from ('Grouped bys) params ('NotNull 'PGint8)
1562+ -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1562countDistinct = unsafeAggregateDistinct "count"
1563countDistinct = unsafeAggregateDistinct "count"
1563
1564
1564-- | synonym for `boolAnd`
1565-- | synonym for `boolAnd`
1565--
1566--
1566-- >>> :{
1567-- >>> :{
1567-- let
1568-- 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)
1569-- expression = every #col
1570-- expression = every #col
1570-- in printSQL expression
1571-- in printSQL expression
1571-- :}
1572-- :}
1572-- every("col")
1573-- every("col")
1573every
1574every
1574− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1575+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
1575 -- ^ what to aggregate
1576 -- ^ what to aggregate
1576− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1577+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1577every = unsafeAggregate "every"
1578every = unsafeAggregate "every"
1578
1579
1579-- | synonym for `boolAndDistinct`
1580-- | synonym for `boolAndDistinct`
1580--
1581--
1581-- >>> :{
1582-- >>> :{
1582-- let
1583-- 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)
1584-- expression = everyDistinct #col
1585-- expression = everyDistinct #col
1585-- in printSQL expression
1586-- in printSQL expression
1586-- :}
1587-- :}
1587-- every(DISTINCT "col")
1588-- every(DISTINCT "col")
1588everyDistinct
1589everyDistinct
1589− :: Expression schema from 'Ungrouped params (nullity 'PGbool)
1590+ :: Expression db from 'Ungrouped params (nullity 'PGbool)
1590 -- ^ what to aggregate
1591 -- ^ what to aggregate
1591− -> Expression schema from ('Grouped bys) params (nullity 'PGbool)
1592+ -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1592everyDistinct = unsafeAggregateDistinct "every"
1593everyDistinct = unsafeAggregateDistinct "every"
1593
1594
1594-- | minimum and maximum aggregation
1595-- | minimum and maximum aggregation
1595max_, min_, maxDistinct, minDistinct
1596max_, min_, maxDistinct, minDistinct
1596− :: Expression schema from 'Ungrouped params (nullity ty)
1597+ :: Expression db from 'Ungrouped params (nullity ty)
1597 -- ^ what to aggregate
1598 -- ^ what to aggregate
1598− -> Expression schema from ('Grouped bys) params (nullity ty)
1599+ -> Expression db from ('Grouped bys) params (nullity ty)
1599max_ = unsafeAggregate "max"
1600max_ = unsafeAggregate "max"
1600min_ = unsafeAggregate "min"
1601min_ = unsafeAggregate "min"
1601maxDistinct = unsafeAggregateDistinct "max"
1602maxDistinct = unsafeAggregateDistinct "max"
@@ -1606,153 +1607,153 @@ type expressions
1606-----------------------------------------}
1607-----------------------------------------}
1607
1608
1608-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1609-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1609−newtype TypeExpression (schema :: SchemaType) (ty :: NullityType)
1610+newtype TypeExpression (db :: DBType) (ty :: NullityType)
1610 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1611 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1611 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1612 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1612
1613
1613-- | The enum or composite type in a `Typedef` can be expressed by its alias.
1614-- | The enum or composite type in a `Typedef` can be expressed by its alias.
1614typedef
1615typedef
1615− :: Has alias schema ('Typedef ty)
1616+ :: HasQualified sch td db schema ('Typedef ty)
1616− => Alias alias
1617+ => QualifiedAlias sch td
1617− -> TypeExpression schema (nullity ty)
1618+ -> TypeExpression db (nullity ty)
1618−typedef = UnsafeTypeExpression . renderAlias
1619+typedef = UnsafeTypeExpression . renderQualifiedAlias
1619
1620
1620-- | The composite type corresponding to a `Table` definition can be expressed
1621-- | The composite type corresponding to a `Table` definition can be expressed
1621-- by its alias.
1622-- by its alias.
1622typetable
1623typetable
1623− :: Has alias schema ('Table tab)
1624+ :: HasQualified sch tab db schema ('Table table)
1624− => Alias alias
1625+ => QualifiedAlias sch tab
1625− -> TypeExpression schema (nullity ('PGcomposite (TableToRow tab)))
1626+ -> TypeExpression db (nullity ('PGcomposite (TableToRow table)))
1626−typetable = UnsafeTypeExpression . renderAlias
1627+typetable = UnsafeTypeExpression . renderQualifiedAlias
1627
1628
1628-- | The composite type corresponding to a `View` definition can be expressed
1629-- | The composite type corresponding to a `View` definition can be expressed
1629-- by its alias.
1630-- by its alias.
1630typeview
1631typeview
1631− :: Has alias schema ('View view)
1632+ :: HasQualified sch vw db schema ('View view)
1632− => Alias alias
1633+ => QualifiedAlias sch vw
1633− -> TypeExpression schema (nullity ('PGcomposite view))
1634+ -> TypeExpression db (nullity ('PGcomposite view))
1634−typeview = UnsafeTypeExpression . renderAlias
1635+typeview = UnsafeTypeExpression . renderQualifiedAlias
1635
1636
1636-- | logical Boolean (true/false)
1637-- | logical Boolean (true/false)
1637−bool :: TypeExpression schema (nullity 'PGbool)
1638+bool :: TypeExpression db (nullity 'PGbool)
1638bool = UnsafeTypeExpression "bool"
1639bool = UnsafeTypeExpression "bool"
1639-- | signed two-byte integer
1640-- | signed two-byte integer
1640−int2, smallint :: TypeExpression schema (nullity 'PGint2)
1641+int2, smallint :: TypeExpression db (nullity 'PGint2)
1641int2 = UnsafeTypeExpression "int2"
1642int2 = UnsafeTypeExpression "int2"
1642smallint = UnsafeTypeExpression "smallint"
1643smallint = UnsafeTypeExpression "smallint"
1643-- | signed four-byte integer
1644-- | signed four-byte integer
1644−int4, int, integer :: TypeExpression schema (nullity 'PGint4)
1645+int4, int, integer :: TypeExpression db (nullity 'PGint4)
1645int4 = UnsafeTypeExpression "int4"
1646int4 = UnsafeTypeExpression "int4"
1646int = UnsafeTypeExpression "int"
1647int = UnsafeTypeExpression "int"
1647integer = UnsafeTypeExpression "integer"
1648integer = UnsafeTypeExpression "integer"
1648-- | signed eight-byte integer
1649-- | signed eight-byte integer
1649−int8, bigint :: TypeExpression schema (nullity 'PGint8)
1650+int8, bigint :: TypeExpression db (nullity 'PGint8)
1650int8 = UnsafeTypeExpression "int8"
1651int8 = UnsafeTypeExpression "int8"
1651bigint = UnsafeTypeExpression "bigint"
1652bigint = UnsafeTypeExpression "bigint"
1652-- | arbitrary precision numeric type
1653-- | arbitrary precision numeric type
1653−numeric :: TypeExpression schema (nullity 'PGnumeric)
1654+numeric :: TypeExpression db (nullity 'PGnumeric)
1654numeric = UnsafeTypeExpression "numeric"
1655numeric = UnsafeTypeExpression "numeric"
1655-- | single precision floating-point number (4 bytes)
1656-- | single precision floating-point number (4 bytes)
1656−float4, real :: TypeExpression schema (nullity 'PGfloat4)
1657+float4, real :: TypeExpression db (nullity 'PGfloat4)
1657float4 = UnsafeTypeExpression "float4"
1658float4 = UnsafeTypeExpression "float4"
1658real = UnsafeTypeExpression "real"
1659real = UnsafeTypeExpression "real"
1659-- | double precision floating-point number (8 bytes)
1660-- | double precision floating-point number (8 bytes)
1660−float8, doublePrecision :: TypeExpression schema (nullity 'PGfloat8)
1661+float8, doublePrecision :: TypeExpression db (nullity 'PGfloat8)
1661float8 = UnsafeTypeExpression "float8"
1662float8 = UnsafeTypeExpression "float8"
1662doublePrecision = UnsafeTypeExpression "double precision"
1663doublePrecision = UnsafeTypeExpression "double precision"
1663-- | variable-length character string
1664-- | variable-length character string
1664−text :: TypeExpression schema (nullity 'PGtext)
1665+text :: TypeExpression db (nullity 'PGtext)
1665text = UnsafeTypeExpression "text"
1666text = UnsafeTypeExpression "text"
1666-- | fixed-length character string
1667-- | fixed-length character string
1667char, character
1668char, character
1668− :: forall n schema nullity. (KnownNat n, 1 <= n)
1669+ :: forall n db nullity. (KnownNat n, 1 <= n)
1669− => TypeExpression schema (nullity ('PGchar n))
1670+ => TypeExpression db (nullity ('PGchar n))
1670char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
1671char = UnsafeTypeExpression $ "char(" <> renderNat @n <> ")"
1671character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
1672character = UnsafeTypeExpression $ "character(" <> renderNat @n <> ")"
1672-- | variable-length character string
1673-- | variable-length character string
1673varchar, characterVarying
1674varchar, characterVarying
1674− :: forall n schema nullity. (KnownNat n, 1 <= n)
1675+ :: forall n db nullity. (KnownNat n, 1 <= n)
1675− => TypeExpression schema (nullity ('PGvarchar n))
1676+ => TypeExpression db (nullity ('PGvarchar n))
1676varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
1677varchar = UnsafeTypeExpression $ "varchar(" <> renderNat @n <> ")"
1677characterVarying = UnsafeTypeExpression $
1678characterVarying = UnsafeTypeExpression $
1678 "character varying(" <> renderNat @n <> ")"
1679 "character varying(" <> renderNat @n <> ")"
1679-- | binary data ("byte array")
1680-- | binary data ("byte array")
1680−bytea :: TypeExpression schema (nullity 'PGbytea)
1681+bytea :: TypeExpression db (nullity 'PGbytea)
1681bytea = UnsafeTypeExpression "bytea"
1682bytea = UnsafeTypeExpression "bytea"
1682-- | date and time (no time zone)
1683-- | date and time (no time zone)
1683−timestamp :: TypeExpression schema (nullity 'PGtimestamp)
1684+timestamp :: TypeExpression db (nullity 'PGtimestamp)
1684timestamp = UnsafeTypeExpression "timestamp"
1685timestamp = UnsafeTypeExpression "timestamp"
1685-- | date and time, including time zone
1686-- | date and time, including time zone
1686−timestampWithTimeZone :: TypeExpression schema (nullity 'PGtimestamptz)
1687+timestampWithTimeZone :: TypeExpression db (nullity 'PGtimestamptz)
1687timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1688timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1688-- | calendar date (year, month, day)
1689-- | calendar date (year, month, day)
1689−date :: TypeExpression schema (nullity 'PGdate)
1690+date :: TypeExpression db (nullity 'PGdate)
1690date = UnsafeTypeExpression "date"
1691date = UnsafeTypeExpression "date"
1691-- | time of day (no time zone)
1692-- | time of day (no time zone)
1692−time :: TypeExpression schema (nullity 'PGtime)
1693+time :: TypeExpression db (nullity 'PGtime)
1693time = UnsafeTypeExpression "time"
1694time = UnsafeTypeExpression "time"
1694-- | time of day, including time zone
1695-- | time of day, including time zone
1695−timeWithTimeZone :: TypeExpression schema (nullity 'PGtimetz)
1696+timeWithTimeZone :: TypeExpression db (nullity 'PGtimetz)
1696timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1697timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1697-- | time span
1698-- | time span
1698−interval :: TypeExpression schema (nullity 'PGinterval)
1699+interval :: TypeExpression db (nullity 'PGinterval)
1699interval = UnsafeTypeExpression "interval"
1700interval = UnsafeTypeExpression "interval"
1700-- | universally unique identifier
1701-- | universally unique identifier
1701−uuid :: TypeExpression schema (nullity 'PGuuid)
1702+uuid :: TypeExpression db (nullity 'PGuuid)
1702uuid = UnsafeTypeExpression "uuid"
1703uuid = UnsafeTypeExpression "uuid"
1703-- | IPv4 or IPv6 host address
1704-- | IPv4 or IPv6 host address
1704−inet :: TypeExpression schema (nullity 'PGinet)
1705+inet :: TypeExpression db (nullity 'PGinet)
1705inet = UnsafeTypeExpression "inet"
1706inet = UnsafeTypeExpression "inet"
1706-- | textual JSON data
1707-- | textual JSON data
1707−json :: TypeExpression schema (nullity 'PGjson)
1708+json :: TypeExpression db (nullity 'PGjson)
1708json = UnsafeTypeExpression "json"
1709json = UnsafeTypeExpression "json"
1709-- | binary JSON data, decomposed
1710-- | binary JSON data, decomposed
1710−jsonb :: TypeExpression schema (nullity 'PGjsonb)
1711+jsonb :: TypeExpression db (nullity 'PGjsonb)
1711jsonb = UnsafeTypeExpression "jsonb"
1712jsonb = UnsafeTypeExpression "jsonb"
1712-- | variable length array
1713-- | variable length array
1713vararray
1714vararray
1714− :: TypeExpression schema pg
1715+ :: TypeExpression db pg
1715− -> TypeExpression schema (nullity ('PGvararray pg))
1716+ -> TypeExpression db (nullity ('PGvararray pg))
1716vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1717vararray ty = UnsafeTypeExpression $ renderTypeExpression ty <> "[]"
1717-- | fixed length array
1718-- | fixed length array
1718--
1719--
1719-- >>> renderTypeExpression (fixarray @2 json)
1720-- >>> renderTypeExpression (fixarray @2 json)
1720-- "json[2]"
1721-- "json[2]"
1721fixarray
1722fixarray
1722− :: forall n schema nullity pg. KnownNat n
1723+ :: forall n db nullity pg. KnownNat n
1723− => TypeExpression schema pg
1724+ => TypeExpression db pg
1724− -> TypeExpression schema (nullity ('PGfixarray n pg))
1725+ -> TypeExpression db (nullity ('PGfixarray n pg))
1725fixarray ty = UnsafeTypeExpression $
1726fixarray ty = UnsafeTypeExpression $
1726 renderTypeExpression ty <> "[" <> renderNat @n <> "]"
1727 renderTypeExpression ty <> "[" <> renderNat @n <> "]"
1727
1728
1728-- | `pgtype` is a demoted version of a `PGType`
1729-- | `pgtype` is a demoted version of a `PGType`
1729−class PGTyped schema (ty :: NullityType) where
1730+class PGTyped db (ty :: NullityType) where
1730− pgtype :: TypeExpression schema ty
1731+ pgtype :: TypeExpression db ty
1731−instance PGTyped schema (nullity 'PGbool) where pgtype = bool
1732+instance PGTyped db (nullity 'PGbool) where pgtype = bool
1732−instance PGTyped schema (nullity 'PGint2) where pgtype = int2
1733+instance PGTyped db (nullity 'PGint2) where pgtype = int2
1733−instance PGTyped schema (nullity 'PGint4) where pgtype = int4
1734+instance PGTyped db (nullity 'PGint4) where pgtype = int4
1734−instance PGTyped schema (nullity 'PGint8) where pgtype = int8
1735+instance PGTyped db (nullity 'PGint8) where pgtype = int8
1735−instance PGTyped schema (nullity 'PGnumeric) where pgtype = numeric
1736+instance PGTyped db (nullity 'PGnumeric) where pgtype = numeric
1736−instance PGTyped schema (nullity 'PGfloat4) where pgtype = float4
1737+instance PGTyped db (nullity 'PGfloat4) where pgtype = float4
1737−instance PGTyped schema (nullity 'PGfloat8) where pgtype = float8
1738+instance PGTyped db (nullity 'PGfloat8) where pgtype = float8
1738−instance PGTyped schema (nullity 'PGtext) where pgtype = text
1739+instance PGTyped db (nullity 'PGtext) where pgtype = text
1739instance (KnownNat n, 1 <= n)
1740instance (KnownNat n, 1 <= n)
1740− => PGTyped schema (nullity ('PGchar n)) where pgtype = char @n
1741+ => PGTyped db (nullity ('PGchar n)) where pgtype = char @n
1741instance (KnownNat n, 1 <= n)
1742instance (KnownNat n, 1 <= n)
1742− => PGTyped schema (nullity ('PGvarchar n)) where pgtype = varchar @n
1743+ => PGTyped db (nullity ('PGvarchar n)) where pgtype = varchar @n
1743−instance PGTyped schema (nullity 'PGbytea) where pgtype = bytea
1744+instance PGTyped db (nullity 'PGbytea) where pgtype = bytea
1744−instance PGTyped schema (nullity 'PGtimestamp) where pgtype = timestamp
1745+instance PGTyped db (nullity 'PGtimestamp) where pgtype = timestamp
1745−instance PGTyped schema (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1746+instance PGTyped db (nullity 'PGtimestamptz) where pgtype = timestampWithTimeZone
1746−instance PGTyped schema (nullity 'PGdate) where pgtype = date
1747+instance PGTyped db (nullity 'PGdate) where pgtype = date
1747−instance PGTyped schema (nullity 'PGtime) where pgtype = time
1748+instance PGTyped db (nullity 'PGtime) where pgtype = time
1748−instance PGTyped schema (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1749+instance PGTyped db (nullity 'PGtimetz) where pgtype = timeWithTimeZone
1749−instance PGTyped schema (nullity 'PGinterval) where pgtype = interval
1750+instance PGTyped db (nullity 'PGinterval) where pgtype = interval
1750−instance PGTyped schema (nullity 'PGuuid) where pgtype = uuid
1751+instance PGTyped db (nullity 'PGuuid) where pgtype = uuid
1751−instance PGTyped schema (nullity 'PGjson) where pgtype = json
1752+instance PGTyped db (nullity 'PGjson) where pgtype = json
1752−instance PGTyped schema (nullity 'PGjsonb) where pgtype = jsonb
1753+instance PGTyped db (nullity 'PGjsonb) where pgtype = jsonb
1753−instance PGTyped schema ty
1754+instance PGTyped db ty
1754− => PGTyped schema (nullity ('PGvararray ty)) where
1755+ => PGTyped db (nullity ('PGvararray ty)) where
1755− pgtype = vararray (pgtype @schema @ty)
1756+ pgtype = vararray (pgtype @db @ty)
1756−instance (KnownNat n, PGTyped schema ty)
1757+instance (KnownNat n, PGTyped db ty)
1757− => PGTyped schema (nullity ('PGfixarray n ty)) where
1758+ => PGTyped db (nullity ('PGfixarray n ty)) where
1758− pgtype = fixarray @n (pgtype @schema @ty)
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
197-}
197-}
198
198
199newtype Manipulation
199newtype Manipulation
200− (schema :: SchemaType)
200+ (db :: DBType)
201 (params :: [NullityType])
201 (params :: [NullityType])
202 (columns :: RowType)
202 (columns :: RowType)
203 = UnsafeManipulation { renderManipulation :: ByteString }
203 = UnsafeManipulation { renderManipulation :: ByteString }
204 deriving (GHC.Generic,Show,Eq,Ord,NFData)
204 deriving (GHC.Generic,Show,Eq,Ord,NFData)
205−instance RenderSQL (Manipulation schema params columns) where
205+instance RenderSQL (Manipulation db params columns) where
206 renderSQL = renderManipulation
206 renderSQL = renderManipulation
207+{--------------FIX WITH
208+
207instance With Manipulation where
209instance With Manipulation where
208 with Done manip = manip
210 with Done manip = manip
209 with (cte :>> ctes) manip = UnsafeManipulation $
211 with (cte :>> ctes) manip = UnsafeManipulation $
210 "WITH" <+> renderCommonTableExpressions renderManipulation cte ctes
212 "WITH" <+> renderCommonTableExpressions renderManipulation cte ctes
211 <+> renderManipulation manip
213 <+> renderManipulation manip
212−
214+-}
213-- | Convert a `Query` into a `Manipulation`.
215-- | Convert a `Query` into a `Manipulation`.
214queryStatement
216queryStatement
215− :: Query schema params columns
217+ :: Query db params columns
216− -> Manipulation schema params columns
218+ -> Manipulation db params columns
217queryStatement q = UnsafeManipulation $ renderQuery q
219queryStatement q = UnsafeManipulation $ renderQuery q
218
220
219{-----------------------------------------
221{-----------------------------------------
@@ -230,18 +232,18 @@ INSERT statements
230insertRows
232insertRows
231 :: ( SOP.SListI columns
233 :: ( SOP.SListI columns
232 , SOP.SListI results
234 , SOP.SListI results
233− , Has tab schema ('Table table)
235+ , HasQualified sch tab db schema ('Table table)
234 , row ~ TableToRow table
236 , row ~ TableToRow table
235 , columns ~ TableToColumns table )
237 , columns ~ TableToColumns table )
236− => Alias tab -- ^ table to insert into
238+ => QualifiedAlias sch tab -- ^ table to insert into
237− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
239+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
238− -> [NP (Aliased (ColumnValue schema '[] params)) columns] -- ^ more rows to insert
240+ -> [NP (Aliased (ColumnValue db '[] params)) columns] -- ^ more rows to insert
239− -> ConflictClause schema table params
241+ -> ConflictClause db table params
240 -- ^ what to do in case of constraint conflict
242 -- ^ what to do in case of constraint conflict
241− -> ReturningClause schema params row results -- ^ results to return
243+ -> ReturningClause db params row results -- ^ results to return
242− -> Manipulation schema params results
244+ -> Manipulation db params results
243insertRows tab rw rws conflict returning = UnsafeManipulation $
245insertRows tab rw rws conflict returning = UnsafeManipulation $
244− "INSERT" <+> "INTO" <+> renderAlias tab
246+ "INSERT" <+> "INTO" <+> renderQualifiedAlias tab
245 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
247 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
246 <+> "VALUES"
248 <+> "VALUES"
247 <+> commaSeparated
249 <+> commaSeparated
@@ -261,54 +263,54 @@ insertRows tab rw rws conflict returning = UnsafeManipulation $
261insertRow
263insertRow
262 :: ( SOP.SListI columns
264 :: ( SOP.SListI columns
263 , SOP.SListI results
265 , SOP.SListI results
264− , Has tab schema ('Table table)
266+ , HasQualified sch tab db schema ('Table table)
265 , row ~ TableToRow table
267 , row ~ TableToRow table
266 , columns ~ TableToColumns table )
268 , columns ~ TableToColumns table )
267− => Alias tab -- ^ table to insert into
269+ => QualifiedAlias sch tab -- ^ table to insert into
268− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
270+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
269− -> ConflictClause schema table params
271+ -> ConflictClause db table params
270 -- ^ what to do in case of constraint conflict
272 -- ^ what to do in case of constraint conflict
271− -> ReturningClause schema params row results -- ^ results to return
273+ -> ReturningClause db params row results -- ^ results to return
272− -> Manipulation schema params results
274+ -> Manipulation db params results
273insertRow tab rw = insertRows tab rw []
275insertRow tab rw = insertRows tab rw []
274
276
275-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
277-- | Insert multiple rows returning `Nil` and raising an error on conflicts.
276insertRows_
278insertRows_
277 :: ( SOP.SListI columns
279 :: ( SOP.SListI columns
278− , Has tab schema ('Table table)
280+ , HasQualified sch tab db schema ('Table table)
279 , columns ~ TableToColumns table )
281 , columns ~ TableToColumns table )
280− => Alias tab -- ^ table to insert into
282+ => QualifiedAlias sch tab -- ^ table to insert into
281− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
283+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
282− -> [NP (Aliased (ColumnValue schema '[] params)) columns] -- ^ more rows to insert
284+ -> [NP (Aliased (ColumnValue db '[] params)) columns] -- ^ more rows to insert
283− -> Manipulation schema params '[]
285+ -> Manipulation db params '[]
284insertRows_ tab rw rws =
286insertRows_ tab rw rws =
285 insertRows tab rw rws OnConflictDoRaise (Returning Nil)
287 insertRows tab rw rws OnConflictDoRaise (Returning Nil)
286
288
287-- | Insert a single row returning `Nil` and raising an error on conflicts.
289-- | Insert a single row returning `Nil` and raising an error on conflicts.
288insertRow_
290insertRow_
289 :: ( SOP.SListI columns
291 :: ( SOP.SListI columns
290− , Has tab schema ('Table table)
292+ , HasQualified sch tab db schema ('Table table)
291 , columns ~ TableToColumns table )
293 , columns ~ TableToColumns table )
292− => Alias tab -- ^ table to insert into
294+ => QualifiedAlias sch tab -- ^ table to insert into
293− -> NP (Aliased (ColumnValue schema '[] params)) columns -- ^ row to insert
295+ -> NP (Aliased (ColumnValue db '[] params)) columns -- ^ row to insert
294− -> Manipulation schema params '[]
296+ -> Manipulation db params '[]
295insertRow_ tab rw = insertRow tab rw OnConflictDoRaise (Returning Nil)
297insertRow_ tab rw = insertRow tab rw OnConflictDoRaise (Returning Nil)
296
298
297-- | Insert a `Query`.
299-- | Insert a `Query`.
298insertQuery
300insertQuery
299 :: ( SOP.SListI columns
301 :: ( SOP.SListI columns
300 , SOP.SListI results
302 , SOP.SListI results
301− , Has tab schema ('Table table)
303+ , HasQualified sch tab db schema ('Table table)
302 , row ~ TableToRow table
304 , row ~ TableToRow table
303 , columns ~ TableToColumns table )
305 , columns ~ TableToColumns table )
304− => Alias tab -- ^ table to insert into
306+ => QualifiedAlias sch tab -- ^ table to insert into
305− -> Query schema params (TableToRow table)
307+ -> Query db params (TableToRow table)
306− -> ConflictClause schema table params
308+ -> ConflictClause db table params
307 -- ^ what to do in case of constraint conflict
309 -- ^ what to do in case of constraint conflict
308− -> ReturningClause schema params row results -- ^ results to return
310+ -> ReturningClause db params row results -- ^ results to return
309− -> Manipulation schema params results
311+ -> Manipulation db params results
310insertQuery tab query conflict returning = UnsafeManipulation $
312insertQuery tab query conflict returning = UnsafeManipulation $
311− "INSERT" <+> "INTO" <+> renderAlias tab
313+ "INSERT" <+> "INTO" <+> renderQualifiedAlias tab
312 <+> renderQuery query
314 <+> renderQuery query
313 <> renderConflictClause conflict
315 <> renderConflictClause conflict
314 <> renderReturningClause returning
316 <> renderReturningClause returning
@@ -316,11 +318,11 @@ insertQuery tab query conflict returning = UnsafeManipulation $
316-- | Insert a `Query` returning `Nil` and raising an error on conflicts.
318-- | Insert a `Query` returning `Nil` and raising an error on conflicts.
317insertQuery_
319insertQuery_
318 :: ( SOP.SListI columns
320 :: ( SOP.SListI columns
319− , Has tab schema ('Table table)
321+ , HasQualified sch tab db schema ('Table table)
320 , columns ~ TableToColumns table )
322 , columns ~ TableToColumns table )
321− => Alias tab -- ^ table to insert into
323+ => QualifiedAlias sch tab -- ^ table to insert into
322− -> Query schema params (TableToRow table)
324+ -> Query db params (TableToRow table)
323− -> Manipulation schema params '[]
325+ -> Manipulation db params '[]
324insertQuery_ tab query =
326insertQuery_ tab query =
325 insertQuery tab query OnConflictDoRaise (Returning Nil)
327 insertQuery tab query OnConflictDoRaise (Returning Nil)
326
328
@@ -330,16 +332,16 @@ insertQuery_ tab query =
330-- `Set` sets a value to be an `Expression`, which can refer to
332-- `Set` sets a value to be an `Expression`, which can refer to
331-- existing value in the row for an update.
333-- existing value in the row for an update.
332data ColumnValue
334data ColumnValue
333− (schema :: SchemaType)
335+ (db :: DBType)
334 (columns :: RowType)
336 (columns :: RowType)
335 (params :: [NullityType])
337 (params :: [NullityType])
336 (ty :: ColumnType)
338 (ty :: ColumnType)
337 where
339 where
338− Same :: ColumnValue schema (column ': columns) params ty
340+ Same :: ColumnValue db (column ': columns) params ty
339− Default :: ColumnValue schema columns params ('Def :=> ty)
341+ Default :: ColumnValue db columns params ('Def :=> ty)
340 Set
342 Set
341− :: (forall table. Expression schema '[table ::: columns] 'Ungrouped params ty)
343+ :: (forall table. Expression db '[table ::: columns] 'Ungrouped params ty)
342− -> ColumnValue schema columns params (constraint :=> ty)
344+ -> ColumnValue db columns params (constraint :=> ty)
343
345
344-- | A `ReturningClause` computes and return value(s) based
346-- | A `ReturningClause` computes and return value(s) based
345-- on each row actually inserted, updated or deleted. This is primarily
347-- on each row actually inserted, updated or deleted. This is primarily
@@ -352,16 +354,16 @@ data ColumnValue
352-- in the row. Use @Returning Nil@ in the common case where no return
354-- in the row. Use @Returning Nil@ in the common case where no return
353-- values are desired.
355-- values are desired.
354data ReturningClause
356data ReturningClause
355− (schema :: SchemaType)
357+ (db :: DBType)
356 (params :: [NullityType])
358 (params :: [NullityType])
357 (row0 :: RowType)
359 (row0 :: RowType)
358 (row1 :: RowType)
360 (row1 :: RowType)
359 where
361 where
360 ReturningStar
362 ReturningStar
361− :: ReturningClause schema params row row
363+ :: ReturningClause db params row row
362 Returning
364 Returning
363− :: NP (Aliased (Expression schema '[table ::: row0] 'Ungrouped params)) row1
365+ :: NP (Aliased (Expression db '[table ::: row0] 'Ungrouped params)) row1
364− -> ReturningClause schema params row0 row1
366+ -> ReturningClause db params row0 row1
365
367
366-- | Render a `ReturningClause`.
368-- | Render a `ReturningClause`.
367renderReturningClause
369renderReturningClause
@@ -380,16 +382,16 @@ renderReturningClause = \case
380-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
382-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
381-- proposed for insertion.
383-- proposed for insertion.
382data ConflictClause
384data ConflictClause
383− (schema :: SchemaType)
385+ (db :: DBType)
384 (table :: TableType)
386 (table :: TableType)
385 (params :: [NullityType]) where
387 (params :: [NullityType]) where
386− OnConflictDoRaise :: ConflictClause schema table params
388+ OnConflictDoRaise :: ConflictClause db table params
387− OnConflictDoNothing :: ConflictClause schema table params
389+ OnConflictDoNothing :: ConflictClause db table params
388 OnConflictDoUpdate
390 OnConflictDoUpdate
389 :: (row ~ TableToRow table, columns ~ TableToColumns table)
391 :: (row ~ TableToRow table, columns ~ TableToColumns table)
390− => NP (Aliased (ColumnValue schema row params)) columns
392+ => NP (Aliased (ColumnValue db row params)) columns
391− -> [Condition schema '[t ::: row] 'Ungrouped params]
393+ -> [Condition db '[t ::: row] 'Ungrouped params]
392− -> ConflictClause schema table params
394+ -> ConflictClause db table params
393
395
394-- | Render a `ConflictClause`.
396-- | Render a `ConflictClause`.
395renderConflictClause
397renderConflictClause
@@ -425,19 +427,19 @@ UPDATE statements
425update
427update
426 :: ( SOP.SListI columns
428 :: ( SOP.SListI columns
427 , SOP.SListI results
429 , SOP.SListI results
428− , Has tab schema ('Table table)
430+ , HasQualified sch tab db schema ('Table table)
429 , row ~ TableToRow table
431 , row ~ TableToRow table
430 , columns ~ TableToColumns table )
432 , columns ~ TableToColumns table )
431− => Alias tab -- ^ table to update
433+ => QualifiedAlias sch tab -- ^ table to update
432− -> NP (Aliased (ColumnValue schema row params)) columns
434+ -> NP (Aliased (ColumnValue db row params)) columns
433 -- ^ modified values to replace old values
435 -- ^ modified values to replace old values
434− -> (forall t. Condition schema '[t ::: row] 'Ungrouped params)
436+ -> (forall t. Condition db '[t ::: row] 'Ungrouped params)
435 -- ^ condition under which to perform update on a row
437 -- ^ condition under which to perform update on a row
436− -> ReturningClause schema params row results -- ^ results to return
438+ -> ReturningClause db params row results -- ^ results to return
437− -> Manipulation schema params results
439+ -> Manipulation db params results
438update tab columns wh returning = UnsafeManipulation $
440update tab columns wh returning = UnsafeManipulation $
439 "UPDATE"
441 "UPDATE"
440− <+> renderAlias tab
442+ <+> renderQualifiedAlias tab
441 <+> "SET"
443 <+> "SET"
442 <+> renderCommaSeparatedMaybe renderUpdate columns
444 <+> renderCommaSeparatedMaybe renderUpdate columns
443 <+> "WHERE" <+> renderExpression wh
445 <+> "WHERE" <+> renderExpression wh
@@ -456,15 +458,15 @@ update tab columns wh returning = UnsafeManipulation $
456-- | Update a row returning `Nil`.
458-- | Update a row returning `Nil`.
457update_
459update_
458 :: ( SOP.SListI columns
460 :: ( SOP.SListI columns
459− , Has tab schema ('Table table)
461+ , HasQualified sch tab db schema ('Table table)
460 , row ~ TableToRow table
462 , row ~ TableToRow table
461 , columns ~ TableToColumns table )
463 , columns ~ TableToColumns table )
462− => Alias tab -- ^ table to update
464+ => QualifiedAlias sch tab -- ^ table to update
463− -> NP (Aliased (ColumnValue schema row params)) columns
465+ -> NP (Aliased (ColumnValue db row params)) columns
464 -- ^ modified values to replace old values
466 -- ^ modified values to replace old values
465− -> (forall t. Condition schema '[t ::: row] 'Ungrouped params)
467+ -> (forall t. Condition db '[t ::: row] 'Ungrouped params)
466 -- ^ condition under which to perform update on a row
468 -- ^ condition under which to perform update on a row
467− -> Manipulation schema params '[]
469+ -> Manipulation db params '[]
468update_ tab columns wh = update tab columns wh (Returning Nil)
470update_ tab columns wh = update tab columns wh (Returning Nil)
469
471
470{-----------------------------------------
472{-----------------------------------------
@@ -474,26 +476,26 @@ DELETE statements
474-- | Delete rows of a table.
476-- | Delete rows of a table.
475deleteFrom
477deleteFrom
476 :: ( SOP.SListI results
478 :: ( SOP.SListI results
477− , Has tab schema ('Table table)
479+ , HasQualified sch tab db schema ('Table table)
478 , row ~ TableToRow table
480 , row ~ TableToRow table
479 , columns ~ TableToColumns table )
481 , columns ~ TableToColumns table )
480− => Alias tab -- ^ table to delete from
482+ => QualifiedAlias sch tab -- ^ table to delete from
481− -> Condition schema '[tab ::: row] 'Ungrouped params
483+ -> Condition db '[tab ::: row] 'Ungrouped params
482 -- ^ condition under which to delete a row
484 -- ^ condition under which to delete a row
483− -> ReturningClause schema params row results -- ^ results to return
485+ -> ReturningClause db params row results -- ^ results to return
484− -> Manipulation schema params results
486+ -> Manipulation db params results
485deleteFrom tab wh returning = UnsafeManipulation $
487deleteFrom tab wh returning = UnsafeManipulation $
486− "DELETE FROM" <+> renderAlias tab
488+ "DELETE FROM" <+> renderQualifiedAlias tab
487 <+> "WHERE" <+> renderExpression wh
489 <+> "WHERE" <+> renderExpression wh
488 <> renderReturningClause returning
490 <> renderReturningClause returning
489
491
490-- | Delete rows returning `Nil`.
492-- | Delete rows returning `Nil`.
491deleteFrom_
493deleteFrom_
492− :: ( Has tab schema ('Table table)
494+ :: ( HasQualified sch tab db schema ('Table table)
493 , row ~ TableToRow table
495 , row ~ TableToRow table
494 , columns ~ TableToColumns table )
496 , columns ~ TableToColumns table )
495− => Alias tab -- ^ table to delete from
497+ => QualifiedAlias sch tab -- ^ table to delete from
496− -> (forall t. Condition schema '[t ::: row] 'Ungrouped params)
498+ -> (forall t. Condition db '[t ::: row] 'Ungrouped params)
497 -- ^ condition under which to delete a row
499 -- ^ condition under which to delete a row
498− -> Manipulation schema params '[]
500+ -> Manipulation db params '[]
499deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
501deleteFrom_ tab wh = deleteFrom tab wh (Returning Nil)
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+90−86
@@ -47,7 +47,7 @@ module Squeal.PostgreSQL.Query
47 , except
47 , except
48 , exceptAll
48 , exceptAll
49 -- ** With
49 -- ** With
50− , With (with)
50+ -- , With (with)
51 , CommonTableExpression (..)
51 , CommonTableExpression (..)
52 , renderCommonTableExpression
52 , renderCommonTableExpression
53 , renderCommonTableExpressions
53 , renderCommonTableExpressions
@@ -357,19 +357,19 @@ in printSQL query
357WITH "t2" AS (SELECT * FROM "t1" AS "t1"), "t3" AS (SELECT * FROM "t2" AS "t2") SELECT * FROM "t3" AS "t3"
357WITH "t2" AS (SELECT * FROM "t1" AS "t1"), "t3" AS (SELECT * FROM "t2" AS "t2") SELECT * FROM "t3" AS "t3"
358-}
358-}
359newtype Query
359newtype Query
360− (schema :: SchemaType)
360+ (db :: DBType)
361 (params :: [NullityType])
361 (params :: [NullityType])
362 (columns :: RowType)
362 (columns :: RowType)
363 = UnsafeQuery { renderQuery :: ByteString }
363 = UnsafeQuery { renderQuery :: ByteString }
364 deriving (GHC.Generic,Show,Eq,Ord,NFData)
364 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
366
366
367-- | The results of two queries can be combined using the set operation
367-- | The results of two queries can be combined using the set operation
368-- `union`. Duplicate rows are eliminated.
368-- `union`. Duplicate rows are eliminated.
369union
369union
370− :: Query schema params columns
370+ :: Query db params columns
371− -> Query schema params columns
371+ -> Query db params columns
372− -> Query schema params columns
372+ -> Query db params columns
373q1 `union` q2 = UnsafeQuery $
373q1 `union` q2 = UnsafeQuery $
374 parenthesized (renderQuery q1)
374 parenthesized (renderQuery q1)
375 <+> "UNION"
375 <+> "UNION"
@@ -378,9 +378,9 @@ q1 `union` q2 = UnsafeQuery $
378-- | The results of two queries can be combined using the set operation
378-- | The results of two queries can be combined using the set operation
379-- `unionAll`, the disjoint union. Duplicate rows are retained.
379-- `unionAll`, the disjoint union. Duplicate rows are retained.
380unionAll
380unionAll
381− :: Query schema params columns
381+ :: Query db params columns
382− -> Query schema params columns
382+ -> Query db params columns
383− -> Query schema params columns
383+ -> Query db params columns
384q1 `unionAll` q2 = UnsafeQuery $
384q1 `unionAll` q2 = UnsafeQuery $
385 parenthesized (renderQuery q1)
385 parenthesized (renderQuery q1)
386 <+> "UNION" <+> "ALL"
386 <+> "UNION" <+> "ALL"
@@ -389,9 +389,9 @@ q1 `unionAll` q2 = UnsafeQuery $
389-- | The results of two queries can be combined using the set operation
389-- | The results of two queries can be combined using the set operation
390-- `intersect`, the intersection. Duplicate rows are eliminated.
390-- `intersect`, the intersection. Duplicate rows are eliminated.
391intersect
391intersect
392− :: Query schema params columns
392+ :: Query db params columns
393− -> Query schema params columns
393+ -> Query db params columns
394− -> Query schema params columns
394+ -> Query db params columns
395q1 `intersect` q2 = UnsafeQuery $
395q1 `intersect` q2 = UnsafeQuery $
396 parenthesized (renderQuery q1)
396 parenthesized (renderQuery q1)
397 <+> "INTERSECT"
397 <+> "INTERSECT"
@@ -400,9 +400,9 @@ q1 `intersect` q2 = UnsafeQuery $
400-- | The results of two queries can be combined using the set operation
400-- | The results of two queries can be combined using the set operation
401-- `intersectAll`, the intersection. Duplicate rows are retained.
401-- `intersectAll`, the intersection. Duplicate rows are retained.
402intersectAll
402intersectAll
403− :: Query schema params columns
403+ :: Query db params columns
404− -> Query schema params columns
404+ -> Query db params columns
405− -> Query schema params columns
405+ -> Query db params columns
406q1 `intersectAll` q2 = UnsafeQuery $
406q1 `intersectAll` q2 = UnsafeQuery $
407 parenthesized (renderQuery q1)
407 parenthesized (renderQuery q1)
408 <+> "INTERSECT" <+> "ALL"
408 <+> "INTERSECT" <+> "ALL"
@@ -411,9 +411,9 @@ q1 `intersectAll` q2 = UnsafeQuery $
411-- | The results of two queries can be combined using the set operation
411-- | The results of two queries can be combined using the set operation
412-- `except`, the set difference. Duplicate rows are eliminated.
412-- `except`, the set difference. Duplicate rows are eliminated.
413except
413except
414− :: Query schema params columns
414+ :: Query db params columns
415− -> Query schema params columns
415+ -> Query db params columns
416− -> Query schema params columns
416+ -> Query db params columns
417q1 `except` q2 = UnsafeQuery $
417q1 `except` q2 = UnsafeQuery $
418 parenthesized (renderQuery q1)
418 parenthesized (renderQuery q1)
419 <+> "EXCEPT"
419 <+> "EXCEPT"
@@ -422,9 +422,9 @@ q1 `except` q2 = UnsafeQuery $
422-- | The results of two queries can be combined using the set operation
422-- | The results of two queries can be combined using the set operation
423-- `exceptAll`, the set difference. Duplicate rows are retained.
423-- `exceptAll`, the set difference. Duplicate rows are retained.
424exceptAll
424exceptAll
425− :: Query schema params columns
425+ :: Query db params columns
426− -> Query schema params columns
426+ -> Query db params columns
427− -> Query schema params columns
427+ -> Query db params columns
428q1 `exceptAll` q2 = UnsafeQuery $
428q1 `exceptAll` q2 = UnsafeQuery $
429 parenthesized (renderQuery q1)
429 parenthesized (renderQuery q1)
430 <+> "EXCEPT" <+> "ALL"
430 <+> "EXCEPT" <+> "ALL"
@@ -440,12 +440,12 @@ SELECT queries
440-- the select list. The select list determines which columns of
440-- the select list. The select list determines which columns of
441-- the intermediate table are actually output.
441-- the intermediate table are actually output.
442select
442select
443− :: SListI columns
443+ :: (SListI columns, columns ~ (col ': cols))
444− => NP (Aliased (Expression schema from grouping params)) (column ': columns)
444+ => NP (Aliased (Expression db from grouping params)) columns
445 -- ^ select list
445 -- ^ select list
446− -> TableExpression schema params from grouping
446+ -> TableExpression db params from grouping
447 -- ^ intermediate virtual table
447 -- ^ intermediate virtual table
448− -> Query schema params (column ': columns)
448+ -> Query db params columns
449select list rels = UnsafeQuery $
449select list rels = UnsafeQuery $
450 "SELECT"
450 "SELECT"
451 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
451 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
@@ -454,12 +454,12 @@ select list rels = UnsafeQuery $
454-- | After the select list has been processed, the result table can
454-- | After the select list has been processed, the result table can
455-- be subject to the elimination of duplicate rows using `selectDistinct`.
455-- be subject to the elimination of duplicate rows using `selectDistinct`.
456selectDistinct
456selectDistinct
457− :: SListI columns
457+ :: (SListI columns, columns ~ (col ': cols))
458− => NP (Aliased (Expression schema from 'Ungrouped params)) (column ': columns)
458+ => NP (Aliased (Expression db from 'Ungrouped params)) columns
459 -- ^ select list
459 -- ^ select list
460− -> TableExpression schema params from 'Ungrouped
460+ -> TableExpression db params from 'Ungrouped
461 -- ^ intermediate virtual table
461 -- ^ intermediate virtual table
462− -> Query schema params (column ': columns)
462+ -> Query db params columns
463selectDistinct list rels = UnsafeQuery $
463selectDistinct list rels = UnsafeQuery $
464 "SELECT DISTINCT"
464 "SELECT DISTINCT"
465 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
465 <+> renderCommaSeparated (renderAliasedAs renderExpression) list
@@ -471,7 +471,7 @@ selectStar
471 :: HasUnique table from columns
471 :: HasUnique table from columns
472 => TableExpression schema params from 'Ungrouped
472 => TableExpression schema params from 'Ungrouped
473 -- ^ intermediate virtual table
473 -- ^ intermediate virtual table
474− -> Query schema params columns
474+ -> Query db params columns
475selectStar rels = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression rels
475selectStar rels = UnsafeQuery $ "SELECT" <+> "*" <+> renderTableExpression rels
476
476
477-- | A `selectDistinctStar` emits all columns that the table expression
477-- | A `selectDistinctStar` emits all columns that the table expression
@@ -480,7 +480,7 @@ selectDistinctStar
480 :: HasUnique table from columns
480 :: HasUnique table from columns
481 => TableExpression schema params from 'Ungrouped
481 => TableExpression schema params from 'Ungrouped
482 -- ^ intermediate virtual table
482 -- ^ intermediate virtual table
483− -> Query schema params columns
483+ -> Query db params columns
484selectDistinctStar rels = UnsafeQuery $
484selectDistinctStar rels = UnsafeQuery $
485 "SELECT DISTINCT" <+> "*" <+> renderTableExpression rels
485 "SELECT DISTINCT" <+> "*" <+> renderTableExpression rels
486
486
@@ -492,7 +492,7 @@ selectDotStar
492 -- ^ particular virtual subtable
492 -- ^ particular virtual subtable
493 -> TableExpression schema params from 'Ungrouped
493 -> TableExpression schema params from 'Ungrouped
494 -- ^ intermediate virtual table
494 -- ^ intermediate virtual table
495− -> Query schema params columns
495+ -> Query db params columns
496selectDotStar rel tab = UnsafeQuery $
496selectDotStar rel tab = UnsafeQuery $
497 "SELECT" <+> renderAlias rel <> ".*" <+> renderTableExpression tab
497 "SELECT" <+> renderAlias rel <> ".*" <+> renderTableExpression tab
498
498
@@ -504,7 +504,7 @@ selectDistinctDotStar
504 -- ^ particular virtual table
504 -- ^ particular virtual table
505 -> TableExpression schema params from 'Ungrouped
505 -> TableExpression schema params from 'Ungrouped
506 -- ^ intermediate virtual table
506 -- ^ intermediate virtual table
507− -> Query schema params columns
507+ -> Query db params columns
508selectDistinctDotStar rel tab = UnsafeQuery $
508selectDistinctDotStar rel tab = UnsafeQuery $
509 "SELECT DISTINCT" <+> renderAlias rel <> ".*"
509 "SELECT DISTINCT" <+> renderAlias rel <> ".*"
510 <+> renderTableExpression tab
510 <+> renderTableExpression tab
@@ -524,7 +524,7 @@ values
524 -> [NP (Aliased (Expression schema '[] 'Ungrouped params)) cols]
524 -> [NP (Aliased (Expression schema '[] 'Ungrouped params)) cols]
525 -- ^ When more than one row is specified, all the rows must
525 -- ^ When more than one row is specified, all the rows must
526 -- must have the same number of elements
526 -- must have the same number of elements
527− -> Query schema params cols
527+ -> Query db params cols
528values rw rws = UnsafeQuery $ "SELECT * FROM"
528values rw rws = UnsafeQuery $ "SELECT * FROM"
529 <+> parenthesized (
529 <+> parenthesized (
530 "VALUES"
530 "VALUES"
@@ -545,7 +545,7 @@ values_
545 :: SListI cols
545 :: SListI cols
546 => NP (Aliased (Expression schema '[] 'Ungrouped params)) cols
546 => NP (Aliased (Expression schema '[] 'Ungrouped params)) cols
547 -- ^ one row of values
547 -- ^ one row of values
548− -> Query schema params cols
548+ -> Query db params cols
549values_ rw = values rw []
549values_ rw = values rw []
550
550
551{-----------------------------------------
551{-----------------------------------------
@@ -559,15 +559,15 @@ Table Expressions
559-- to a table on disk, a so-called base table, but more complex expressions
559-- to a table on disk, a so-called base table, but more complex expressions
560-- can be used to modify or combine base tables in various ways.
560-- can be used to modify or combine base tables in various ways.
561data TableExpression
561data TableExpression
562− (schema :: SchemaType)
562+ (db :: DBType)
563 (params :: [NullityType])
563 (params :: [NullityType])
564 (from :: FromType)
564 (from :: FromType)
565 (grouping :: Grouping)
565 (grouping :: Grouping)
566 = TableExpression
566 = TableExpression
567− { fromClause :: FromClause schema params from
567+ { fromClause :: FromClause db params from
568 -- ^ A table reference that can be a table name, or a derived table such
568 -- ^ A table reference that can be a table name, or a derived table such
569 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
569 -- 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]
571 -- ^ optional search coditions, combined with `.&&`. After the processing
571 -- ^ optional search coditions, combined with `.&&`. After the processing
572 -- of the `fromClause` is done, each row of the derived virtual table
572 -- of the `fromClause` is done, each row of the derived virtual table
573 -- is checked against the search condition. If the result of the
573 -- is checked against the search condition. If the result of the
@@ -583,13 +583,13 @@ data TableExpression
583 -- set of rows having common values into one group row that represents all
583 -- set of rows having common values into one group row that represents all
584 -- rows in the group. This is done to eliminate redundancy in the output
584 -- rows in the group. This is done to eliminate redundancy in the output
585 -- and/or compute aggregates that apply to these groups.
585 -- and/or compute aggregates that apply to these groups.
586− , havingClause :: HavingClause schema from grouping params
586+ , havingClause :: HavingClause db from grouping params
587 -- ^ If a table has been grouped using `groupBy`, but only certain groups
587 -- ^ If a table has been grouped using `groupBy`, but only certain groups
588 -- are of interest, the `havingClause` can be used, much like a
588 -- are of interest, the `havingClause` can be used, much like a
589 -- `whereClause`, to eliminate groups from the result. Expressions in the
589 -- `whereClause`, to eliminate groups from the result. Expressions in the
590 -- `havingClause` can refer both to grouped expressions and to ungrouped
590 -- `havingClause` can refer both to grouped expressions and to ungrouped
591 -- expressions (which necessarily involve an aggregate function).
591 -- expressions (which necessarily involve an aggregate function).
592− , orderByClause :: [SortExpression schema from grouping params]
592+ , orderByClause :: [SortExpression db from grouping params]
593 -- ^ The `orderByClause` is for optional sorting. When more than one
593 -- ^ The `orderByClause` is for optional sorting. When more than one
594 -- `SortExpression` is specified, the later (right) values are used to sort
594 -- `SortExpression` is specified, the later (right) values are used to sort
595 -- rows that are equal according to the earlier (left) values.
595 -- rows that are equal according to the earlier (left) values.
@@ -711,55 +711,55 @@ JSON stuff
711unsafeSetOfFunction
711unsafeSetOfFunction
712 :: ByteString
712 :: ByteString
713 -> Expression schema '[] 'Ungrouped params ty
713 -> Expression schema '[] 'Ungrouped params ty
714− -> Query schema params row
714+ -> Query db params row
715unsafeSetOfFunction fun expr = UnsafeQuery $
715unsafeSetOfFunction fun expr = UnsafeQuery $
716 "SELECT * FROM " <> fun <> "(" <> renderExpression expr <> ")"
716 "SELECT * FROM " <> fun <> "(" <> renderExpression expr <> ")"
717
717
718-- | Expands the outermost JSON object into a set of key/value pairs.
718-- | Expands the outermost JSON object into a set of key/value pairs.
719jsonEach
719jsonEach
720 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
720 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
721− -> Query schema params
721+ -> Query db params
722 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
722 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
723jsonEach = unsafeSetOfFunction "json_each"
723jsonEach = unsafeSetOfFunction "json_each"
724
724
725-- | Expands the outermost binary JSON object into a set of key/value pairs.
725-- | Expands the outermost binary JSON object into a set of key/value pairs.
726jsonbEach
726jsonbEach
727 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
727 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
728− -> Query schema params
728+ -> Query db params
729 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
729 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
730jsonbEach = unsafeSetOfFunction "jsonb_each"
730jsonbEach = unsafeSetOfFunction "jsonb_each"
731
731
732-- | Expands the outermost JSON object into a set of key/value pairs.
732-- | Expands the outermost JSON object into a set of key/value pairs.
733jsonEachAsText
733jsonEachAsText
734 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
734 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
735− -> Query schema params
735+ -> Query db params
736 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
736 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
737jsonEachAsText = unsafeSetOfFunction "json_each_text"
737jsonEachAsText = unsafeSetOfFunction "json_each_text"
738
738
739-- | Expands the outermost binary JSON object into a set of key/value pairs.
739-- | Expands the outermost binary JSON object into a set of key/value pairs.
740jsonbEachAsText
740jsonbEachAsText
741 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
741 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
742− -> Query schema params
742+ -> Query db params
743 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
743 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
744jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
744jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
745
745
746-- | Returns set of keys in the outermost JSON object.
746-- | Returns set of keys in the outermost JSON object.
747jsonObjectKeys
747jsonObjectKeys
748 :: Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
748 :: 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]
750jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
750jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
751
751
752-- | Returns set of keys in the outermost JSON object.
752-- | Returns set of keys in the outermost JSON object.
753jsonbObjectKeys
753jsonbObjectKeys
754 :: Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
754 :: 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]
756jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
756jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
757
757
758unsafePopulateFunction
758unsafePopulateFunction
759 :: ByteString
759 :: ByteString
760 -> TypeExpression schema (nullity ('PGcomposite row))
760 -> TypeExpression schema (nullity ('PGcomposite row))
761 -> Expression schema '[] 'Ungrouped params ty
761 -> Expression schema '[] 'Ungrouped params ty
762− -> Query schema params row
762+ -> Query db params row
763unsafePopulateFunction fun ty expr = UnsafeQuery $
763unsafePopulateFunction fun ty expr = UnsafeQuery $
764 "SELECT * FROM " <> fun <> "("
764 "SELECT * FROM " <> fun <> "("
765 <> "null::" <> renderTypeExpression ty <> ", "
765 <> "null::" <> renderTypeExpression ty <> ", "
@@ -770,7 +770,7 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
770jsonPopulateRecord
770jsonPopulateRecord
771 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
771 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
772 -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
772 -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
773− -> Query schema params row
773+ -> Query db params row
774jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
774jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
775
775
776-- | Expands the binary JSON expression to a row whose columns match the record
776-- | Expands the binary JSON expression to a row whose columns match the record
@@ -778,7 +778,7 @@ jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
778jsonbPopulateRecord
778jsonbPopulateRecord
779 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
779 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
780 -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
780 -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
781− -> Query schema params row
781+ -> Query db params row
782jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
782jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
783
783
784-- | Expands the outermost array of objects in the given JSON expression to a
784-- | Expands the outermost array of objects in the given JSON expression to a
@@ -786,7 +786,7 @@ jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
786jsonPopulateRecordSet
786jsonPopulateRecordSet
787 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
787 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
788 -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
788 -> Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
789− -> Query schema params row
789+ -> Query db params row
790jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
790jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
791
791
792-- | Expands the outermost array of objects in the given binary JSON expression
792-- | Expands the outermost array of objects in the given binary JSON expression
@@ -795,7 +795,7 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
795jsonbPopulateRecordSet
795jsonbPopulateRecordSet
796 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
796 :: TypeExpression schema (nullity ('PGcomposite row)) -- ^ row type
797 -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
797 -> Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
798− -> Query schema params row
798+ -> Query db params row
799jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
799jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
800
800
801unsafeRecordFunction
801unsafeRecordFunction
@@ -803,7 +803,7 @@ unsafeRecordFunction
803 => ByteString
803 => ByteString
804 -> Expression schema '[] 'Ungrouped params (nullity json)
804 -> Expression schema '[] 'Ungrouped params (nullity json)
805 -> NP (Aliased (TypeExpression schema)) record
805 -> NP (Aliased (TypeExpression schema)) record
806− -> Query schema params record
806+ -> Query db params record
807unsafeRecordFunction fun expr types = UnsafeQuery $
807unsafeRecordFunction fun expr types = UnsafeQuery $
808 "SELECT * FROM " <> fun <> "("
808 "SELECT * FROM " <> fun <> "("
809 <> renderExpression expr <> ")"
809 <> renderExpression expr <> ")"
@@ -818,7 +818,7 @@ jsonToRecord
818 :: SListI record
818 :: SListI record
819 => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
819 => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json object
820 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
820 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
821− -> Query schema params record
821+ -> Query db params record
822jsonToRecord = unsafeRecordFunction "json_to_record"
822jsonToRecord = unsafeRecordFunction "json_to_record"
823
823
824-- | Builds an arbitrary record from a binary JSON object.
824-- | Builds an arbitrary record from a binary JSON object.
@@ -826,7 +826,7 @@ jsonbToRecord
826 :: SListI record
826 :: SListI record
827 => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
827 => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb object
828 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
828 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
829− -> Query schema params record
829+ -> Query db params record
830jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
830jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
831
831
832-- | Builds an arbitrary set of records from a JSON array of objects.
832-- | Builds an arbitrary set of records from a JSON array of objects.
@@ -834,7 +834,7 @@ jsonToRecordSet
834 :: SListI record
834 :: SListI record
835 => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
835 => Expression schema '[] 'Ungrouped params (nullity 'PGjson) -- ^ json array
836 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
836 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
837− -> Query schema params record
837+ -> Query db params record
838jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
838jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
839
839
840-- | Builds an arbitrary set of records from a binary JSON array of objects.
840-- | Builds an arbitrary set of records from a binary JSON array of objects.
@@ -842,7 +842,7 @@ jsonbToRecordSet
842 :: SListI record
842 :: SListI record
843 => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
843 => Expression schema '[] 'Ungrouped params (nullity 'PGjsonb) -- ^ jsonb array
844 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
844 -> NP (Aliased (TypeExpression schema)) record -- ^ record types
845− -> Query schema params record
845+ -> Query db params record
846jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
846jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
847
847
848{-----------------------------------------
848{-----------------------------------------
@@ -867,7 +867,7 @@ table (tab `As` alias) = UnsafeFromClause $
867
867
868-- | `subquery` derives a table from a `Query`.
868-- | `subquery` derives a table from a `Query`.
869subquery
869subquery
870− :: Aliased (Query schema params) rel
870+ :: Aliased (Query db params) rel
871 -> FromClause schema params '[rel]
871 -> FromClause schema params '[rel]
872subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
872subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
873
873
@@ -1094,7 +1094,7 @@ renderSortExpression = \case
1094unsafeSubqueryExpression
1094unsafeSubqueryExpression
1095 :: ByteString
1095 :: ByteString
1096 -> Expression schema from grp params ty
1096 -> Expression schema from grp params ty
1097− -> Query schema params '[alias ::: ty]
1097+ -> Query db params '[alias ::: ty]
1098 -> Expression schema from grp params (nullity 'PGbool)
1098 -> Expression schema from grp params (nullity 'PGbool)
1099unsafeSubqueryExpression op x q = UnsafeExpression $
1099unsafeSubqueryExpression op x q = UnsafeExpression $
1100 renderExpression x <+> op <+> parenthesized (renderQuery q)
1100 renderExpression x <+> op <+> parenthesized (renderQuery q)
@@ -1103,7 +1103,7 @@ unsafeRowSubqueryExpression
1103 :: SListI row
1103 :: SListI row
1104 => ByteString
1104 => ByteString
1105 -> NP (Aliased (Expression schema from grp params)) row
1105 -> NP (Aliased (Expression schema from grp params)) row
1106− -> Query schema params row
1106+ -> Query db params row
1107 -> Expression schema from grp params (nullity 'PGbool)
1107 -> Expression schema from grp params (nullity 'PGbool)
1108unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1108unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1109 renderExpression (row xs) <+> op <+> parenthesized (renderQuery q)
1109 renderExpression (row xs) <+> op <+> parenthesized (renderQuery q)
@@ -1118,7 +1118,7 @@ unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1118-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1118-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1119in_
1119in_
1120 :: Expression schema from grp params ty -- ^ expression
1120 :: Expression schema from grp params ty -- ^ expression
1121− -> Query schema params '[alias ::: ty] -- ^ subquery
1121+ -> Query db params '[alias ::: ty] -- ^ subquery
1122 -> Expression schema from grp params (nullity 'PGbool)
1122 -> Expression schema from grp params (nullity 'PGbool)
1123in_ = unsafeSubqueryExpression "IN"
1123in_ = unsafeSubqueryExpression "IN"
1124
1124
@@ -1139,7 +1139,7 @@ ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1139rowIn
1139rowIn
1140 :: SListI row
1140 :: SListI row
1141 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1141 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1142− -> Query schema params row -- ^ subquery
1142+ -> Query db params row -- ^ subquery
1143 -> Expression schema from grp params (nullity 'PGbool)
1143 -> Expression schema from grp params (nullity 'PGbool)
1144rowIn = unsafeRowSubqueryExpression "IN"
1144rowIn = unsafeRowSubqueryExpression "IN"
1145
1145
@@ -1147,7 +1147,7 @@ rowIn = unsafeRowSubqueryExpression "IN"
1147-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1147-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1148eqAll
1148eqAll
1149 :: Expression schema from grp params ty -- ^ expression
1149 :: Expression schema from grp params ty -- ^ expression
1150− -> Query schema params '[alias ::: ty] -- ^ subquery
1150+ -> Query db params '[alias ::: ty] -- ^ subquery
1151 -> Expression schema from grp params (nullity 'PGbool)
1151 -> Expression schema from grp params (nullity 'PGbool)
1152eqAll = unsafeSubqueryExpression "= ALL"
1152eqAll = unsafeSubqueryExpression "= ALL"
1153
1153
@@ -1157,7 +1157,7 @@ eqAll = unsafeSubqueryExpression "= ALL"
1157rowEqAll
1157rowEqAll
1158 :: SListI row
1158 :: SListI row
1159 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1159 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1160− -> Query schema params row -- ^ subquery
1160+ -> Query db params row -- ^ subquery
1161 -> Expression schema from grp params (nullity 'PGbool)
1161 -> Expression schema from grp params (nullity 'PGbool)
1162rowEqAll = unsafeRowSubqueryExpression "= ALL"
1162rowEqAll = unsafeRowSubqueryExpression "= ALL"
1163
1163
@@ -1165,7 +1165,7 @@ rowEqAll = unsafeRowSubqueryExpression "= ALL"
1165-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1165-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1166eqAny
1166eqAny
1167 :: Expression schema from grp params ty -- ^ expression
1167 :: Expression schema from grp params ty -- ^ expression
1168− -> Query schema params '[alias ::: ty] -- ^ subquery
1168+ -> Query db params '[alias ::: ty] -- ^ subquery
1169 -> Expression schema from grp params (nullity 'PGbool)
1169 -> Expression schema from grp params (nullity 'PGbool)
1170eqAny = unsafeSubqueryExpression "= ANY"
1170eqAny = unsafeSubqueryExpression "= ANY"
1171
1171
@@ -1175,7 +1175,7 @@ eqAny = unsafeSubqueryExpression "= ANY"
1175rowEqAny
1175rowEqAny
1176 :: SListI row
1176 :: SListI row
1177 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1177 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1178− -> Query schema params row -- ^ subquery
1178+ -> Query db params row -- ^ subquery
1179 -> Expression schema from grp params (nullity 'PGbool)
1179 -> Expression schema from grp params (nullity 'PGbool)
1180rowEqAny = unsafeRowSubqueryExpression "= ANY"
1180rowEqAny = unsafeRowSubqueryExpression "= ANY"
1181
1181
@@ -1183,7 +1183,7 @@ rowEqAny = unsafeRowSubqueryExpression "= ANY"
1183-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1183-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1184neqAll
1184neqAll
1185 :: Expression schema from grp params ty -- ^ expression
1185 :: Expression schema from grp params ty -- ^ expression
1186− -> Query schema params '[alias ::: ty] -- ^ subquery
1186+ -> Query db params '[alias ::: ty] -- ^ subquery
1187 -> Expression schema from grp params (nullity 'PGbool)
1187 -> Expression schema from grp params (nullity 'PGbool)
1188neqAll = unsafeSubqueryExpression "<> ALL"
1188neqAll = unsafeSubqueryExpression "<> ALL"
1189
1189
@@ -1193,7 +1193,7 @@ neqAll = unsafeSubqueryExpression "<> ALL"
1193rowNeqAll
1193rowNeqAll
1194 :: SListI row
1194 :: SListI row
1195 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1195 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1196− -> Query schema params row -- ^ subquery
1196+ -> Query db params row -- ^ subquery
1197 -> Expression schema from grp params (nullity 'PGbool)
1197 -> Expression schema from grp params (nullity 'PGbool)
1198rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1198rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1199
1199
@@ -1201,7 +1201,7 @@ rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1201-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1201-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1202neqAny
1202neqAny
1203 :: Expression schema from grp params ty -- ^ expression
1203 :: Expression schema from grp params ty -- ^ expression
1204− -> Query schema params '[alias ::: ty] -- ^ subquery
1204+ -> Query db params '[alias ::: ty] -- ^ subquery
1205 -> Expression schema from grp params (nullity 'PGbool)
1205 -> Expression schema from grp params (nullity 'PGbool)
1206neqAny = unsafeSubqueryExpression "<> ANY"
1206neqAny = unsafeSubqueryExpression "<> ANY"
1207
1207
@@ -1211,7 +1211,7 @@ neqAny = unsafeSubqueryExpression "<> ANY"
1211rowNeqAny
1211rowNeqAny
1212 :: SListI row
1212 :: SListI row
1213 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1213 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1214− -> Query schema params row -- ^ subquery
1214+ -> Query db params row -- ^ subquery
1215 -> Expression schema from grp params (nullity 'PGbool)
1215 -> Expression schema from grp params (nullity 'PGbool)
1216rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1216rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1217
1217
@@ -1219,7 +1219,7 @@ rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1219-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1219-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1220allLt
1220allLt
1221 :: Expression schema from grp params ty -- ^ expression
1221 :: Expression schema from grp params ty -- ^ expression
1222− -> Query schema params '[alias ::: ty] -- ^ subquery
1222+ -> Query db params '[alias ::: ty] -- ^ subquery
1223 -> Expression schema from grp params (nullity 'PGbool)
1223 -> Expression schema from grp params (nullity 'PGbool)
1224allLt = unsafeSubqueryExpression "ALL <"
1224allLt = unsafeSubqueryExpression "ALL <"
1225
1225
@@ -1229,7 +1229,7 @@ allLt = unsafeSubqueryExpression "ALL <"
1229rowLtAll
1229rowLtAll
1230 :: SListI row
1230 :: SListI row
1231 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1231 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1232− -> Query schema params row -- ^ subquery
1232+ -> Query db params row -- ^ subquery
1233 -> Expression schema from grp params (nullity 'PGbool)
1233 -> Expression schema from grp params (nullity 'PGbool)
1234rowLtAll = unsafeRowSubqueryExpression "ALL <"
1234rowLtAll = unsafeRowSubqueryExpression "ALL <"
1235
1235
@@ -1237,7 +1237,7 @@ rowLtAll = unsafeRowSubqueryExpression "ALL <"
1237-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1237-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1238ltAny
1238ltAny
1239 :: Expression schema from grp params ty -- ^ expression
1239 :: Expression schema from grp params ty -- ^ expression
1240− -> Query schema params '[alias ::: ty] -- ^ subquery
1240+ -> Query db params '[alias ::: ty] -- ^ subquery
1241 -> Expression schema from grp params (nullity 'PGbool)
1241 -> Expression schema from grp params (nullity 'PGbool)
1242ltAny = unsafeSubqueryExpression "ANY <"
1242ltAny = unsafeSubqueryExpression "ANY <"
1243
1243
@@ -1247,7 +1247,7 @@ ltAny = unsafeSubqueryExpression "ANY <"
1247rowLtAny
1247rowLtAny
1248 :: SListI row
1248 :: SListI row
1249 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1249 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1250− -> Query schema params row -- ^ subquery
1250+ -> Query db params row -- ^ subquery
1251 -> Expression schema from grp params (nullity 'PGbool)
1251 -> Expression schema from grp params (nullity 'PGbool)
1252rowLtAny = unsafeRowSubqueryExpression "ANY <"
1252rowLtAny = unsafeRowSubqueryExpression "ANY <"
1253
1253
@@ -1255,7 +1255,7 @@ rowLtAny = unsafeRowSubqueryExpression "ANY <"
1255-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1255-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1256lteAll
1256lteAll
1257 :: Expression schema from grp params ty -- ^ expression
1257 :: Expression schema from grp params ty -- ^ expression
1258− -> Query schema params '[alias ::: ty] -- ^ subquery
1258+ -> Query db params '[alias ::: ty] -- ^ subquery
1259 -> Expression schema from grp params (nullity 'PGbool)
1259 -> Expression schema from grp params (nullity 'PGbool)
1260lteAll = unsafeSubqueryExpression "<= ALL"
1260lteAll = unsafeSubqueryExpression "<= ALL"
1261
1261
@@ -1265,7 +1265,7 @@ lteAll = unsafeSubqueryExpression "<= ALL"
1265rowLteAll
1265rowLteAll
1266 :: SListI row
1266 :: SListI row
1267 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1267 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1268− -> Query schema params row -- ^ subquery
1268+ -> Query db params row -- ^ subquery
1269 -> Expression schema from grp params (nullity 'PGbool)
1269 -> Expression schema from grp params (nullity 'PGbool)
1270rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1270rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1271
1271
@@ -1273,7 +1273,7 @@ rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1273-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1273-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1274lteAny
1274lteAny
1275 :: Expression schema from grp params ty -- ^ expression
1275 :: Expression schema from grp params ty -- ^ expression
1276− -> Query schema params '[alias ::: ty] -- ^ subquery
1276+ -> Query db params '[alias ::: ty] -- ^ subquery
1277 -> Expression schema from grp params (nullity 'PGbool)
1277 -> Expression schema from grp params (nullity 'PGbool)
1278lteAny = unsafeSubqueryExpression "<= ANY"
1278lteAny = unsafeSubqueryExpression "<= ANY"
1279
1279
@@ -1283,7 +1283,7 @@ lteAny = unsafeSubqueryExpression "<= ANY"
1283rowLteAny
1283rowLteAny
1284 :: SListI row
1284 :: SListI row
1285 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1285 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1286− -> Query schema params row -- ^ subquery
1286+ -> Query db params row -- ^ subquery
1287 -> Expression schema from grp params (nullity 'PGbool)
1287 -> Expression schema from grp params (nullity 'PGbool)
1288rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1288rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1289
1289
@@ -1291,7 +1291,7 @@ rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1291-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1291-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1292gtAll
1292gtAll
1293 :: Expression schema from grp params ty -- ^ expression
1293 :: Expression schema from grp params ty -- ^ expression
1294− -> Query schema params '[alias ::: ty] -- ^ subquery
1294+ -> Query db params '[alias ::: ty] -- ^ subquery
1295 -> Expression schema from grp params (nullity 'PGbool)
1295 -> Expression schema from grp params (nullity 'PGbool)
1296gtAll = unsafeSubqueryExpression "> ALL"
1296gtAll = unsafeSubqueryExpression "> ALL"
1297
1297
@@ -1301,7 +1301,7 @@ gtAll = unsafeSubqueryExpression "> ALL"
1301rowGtAll
1301rowGtAll
1302 :: SListI row
1302 :: SListI row
1303 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1303 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1304− -> Query schema params row -- ^ subquery
1304+ -> Query db params row -- ^ subquery
1305 -> Expression schema from grp params (nullity 'PGbool)
1305 -> Expression schema from grp params (nullity 'PGbool)
1306rowGtAll = unsafeRowSubqueryExpression "> ALL"
1306rowGtAll = unsafeRowSubqueryExpression "> ALL"
1307
1307
@@ -1309,7 +1309,7 @@ rowGtAll = unsafeRowSubqueryExpression "> ALL"
1309-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1309-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1310gtAny
1310gtAny
1311 :: Expression schema from grp params ty -- ^ expression
1311 :: Expression schema from grp params ty -- ^ expression
1312− -> Query schema params '[alias ::: ty] -- ^ subquery
1312+ -> Query db params '[alias ::: ty] -- ^ subquery
1313 -> Expression schema from grp params (nullity 'PGbool)
1313 -> Expression schema from grp params (nullity 'PGbool)
1314gtAny = unsafeSubqueryExpression "> ANY"
1314gtAny = unsafeSubqueryExpression "> ANY"
1315
1315
@@ -1319,7 +1319,7 @@ gtAny = unsafeSubqueryExpression "> ANY"
1319rowGtAny
1319rowGtAny
1320 :: SListI row
1320 :: SListI row
1321 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1321 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1322− -> Query schema params row -- ^ subquery
1322+ -> Query db params row -- ^ subquery
1323 -> Expression schema from grp params (nullity 'PGbool)
1323 -> Expression schema from grp params (nullity 'PGbool)
1324rowGtAny = unsafeRowSubqueryExpression "> ANY"
1324rowGtAny = unsafeRowSubqueryExpression "> ANY"
1325
1325
@@ -1327,7 +1327,7 @@ rowGtAny = unsafeRowSubqueryExpression "> ANY"
1327-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1327-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1328gteAll
1328gteAll
1329 :: Expression schema from grp params ty -- ^ expression
1329 :: Expression schema from grp params ty -- ^ expression
1330− -> Query schema params '[alias ::: ty] -- ^ subquery
1330+ -> Query db params '[alias ::: ty] -- ^ subquery
1331 -> Expression schema from grp params (nullity 'PGbool)
1331 -> Expression schema from grp params (nullity 'PGbool)
1332gteAll = unsafeSubqueryExpression ">= ALL"
1332gteAll = unsafeSubqueryExpression ">= ALL"
1333
1333
@@ -1337,7 +1337,7 @@ gteAll = unsafeSubqueryExpression ">= ALL"
1337rowGteAll
1337rowGteAll
1338 :: SListI row
1338 :: SListI row
1339 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1339 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1340− -> Query schema params row -- ^ subquery
1340+ -> Query db params row -- ^ subquery
1341 -> Expression schema from grp params (nullity 'PGbool)
1341 -> Expression schema from grp params (nullity 'PGbool)
1342rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1342rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1343
1343
@@ -1345,7 +1345,7 @@ rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1345-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1345-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1346gteAny
1346gteAny
1347 :: Expression schema from grp params ty -- ^ expression
1347 :: Expression schema from grp params ty -- ^ expression
1348− -> Query schema params '[alias ::: ty] -- ^ subquery
1348+ -> Query db params '[alias ::: ty] -- ^ subquery
1349 -> Expression schema from grp params (nullity 'PGbool)
1349 -> Expression schema from grp params (nullity 'PGbool)
1350gteAny = unsafeSubqueryExpression ">= ANY"
1350gteAny = unsafeSubqueryExpression ">= ANY"
1351
1351
@@ -1355,7 +1355,7 @@ gteAny = unsafeSubqueryExpression ">= ANY"
1355rowGteAny
1355rowGteAny
1356 :: SListI row
1356 :: SListI row
1357 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1357 => NP (Aliased (Expression schema from grp params)) row -- ^ row constructor
1358− -> Query schema params row -- ^ subquery
1358+ -> Query db params row -- ^ subquery
1359 -> Expression schema from grp params (nullity 'PGbool)
1359 -> Expression schema from grp params (nullity 'PGbool)
1360rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1360rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1361
1361
@@ -1398,6 +1398,8 @@ renderCommonTableExpressions renderStatement cte ctes =
1398 cte' :>> ctes' -> "," <+>
1398 cte' :>> ctes' -> "," <+>
1399 renderCommonTableExpressions renderStatement cte' ctes'
1399 renderCommonTableExpressions renderStatement cte' ctes'
1400
1400
1401+{---------------FIX WITH
1402+
1401-- | `with` provides a way to write auxiliary statements for use in a larger query.
1403-- | `with` provides a way to write auxiliary statements for use in a larger query.
1402-- These statements, referred to as `CommonTableExpression`s, can be thought of as
1404-- These statements, referred to as `CommonTableExpression`s, can be thought of as
1403-- defining temporary tables that exist just for one query.
1405-- defining temporary tables that exist just for one query.
@@ -1413,3 +1415,5 @@ instance With Query where
1413 with (cte :>> ctes) query = UnsafeQuery $
1415 with (cte :>> ctes) query = UnsafeQuery $
1414 "WITH" <+> renderCommonTableExpressions renderQuery cte ctes
1416 "WITH" <+> renderCommonTableExpressions renderQuery cte ctes
1415 <+> renderQuery query
1417 <+> renderQuery query
1418+
1419+-}