on dev help sign in
Merge pull request #88 from morphismtech/dev-underscore

Add `Query_` and `Manipulation_` type families

commitfb99bd27c7a1037b3df9b4f279b494fa8e49c906 authorEitan Chatav <eitan.chatav@gmail.com> dateThu 10 Jan 2019, 20:53 (8 years ago) parent2762bb47b9b2af
11 files changed+743−747
squeal-postgresql/exe/Example.hs+3−5 squeal-postgresql/src/Squeal/PostgreSQL.hs+12−16 squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+4−4 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+308−308 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+98−93 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+14−14 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+297−292 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−6 squeal-postgresql/test/Specs/ExceptionHandling.hs+1−3
squeal-postgresql/exe/Example.hs+3−5
@@ -43,8 +43,6 @@ type Schema =
4343
4444type Schemas = Public Schema
4545
46−type DB = DBof Schemas
47−
4846setup :: Definition (Public '[]) Schemas
4947setup =
5048 createTable #users
@@ -64,17 +62,17 @@ setup =
6462teardown :: Definition Schemas (Public '[])
6563teardown = dropTable #emails >>> dropTable #users
6664
67−insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
65+insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
6866 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
6967insertUser = insertInto #users
7068 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))
7169 (OnConflict (OnConstraint #pk_users) DoNothing) (Returning_ (#id `as` #fromOnly))
7270
73−insertEmail :: Manipulation DB '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
71+insertEmail :: Manipulation '[] Schemas '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
7472insertEmail = insertInto_ #emails
7573 (Values_ (defaultAs #id :* param @1 `as` #user_id :* param @2 `as` #email))
7674
77−getUsers :: Query DB '[]
75+getUsers :: Query '[] Schemas '[]
7876 '[ "userName" ::: 'NotNull 'PGtext
7977 , "userEmail" ::: 'Null 'PGtext
8078 , "userVec" ::: 'NotNull ('PGvararray ('Null 'PGint2))]
squeal-postgresql/src/Squeal/PostgreSQL.hs+12−16
@@ -47,7 +47,6 @@ type Schema =
4747 '[ "users" ::: 'Table (UsersConstraints :=> UsersColumns)
4848 , "emails" ::: 'Table (EmailsConstraints :=> EmailsColumns) ]
4949type Schemas = Public Schema
50−type DB = DBof Schemas
5150:}
5251
5352Notice the use of type operators.
@@ -116,9 +115,18 @@ need to retrieve the user id that the insert generates and insert it into
116115the emails table. Take a careful look at the type and definition of both
117116of our inserts.
118117
118+We'll need a Haskell type for users. We give the type `Generics.SOP.Generic` and
119+`Generics.SOP.HasDatatypeInfo` instances so that we can decode the rows
120+we receive when we run @getUsers@. Notice that the record fields of the
121+@User@ type match the column names of @getUsers@.
122+
123+>>> data User = User { userName :: Text, userEmail :: Maybe Text } deriving (Show, GHC.Generic)
124+>>> instance SOP.Generic User
125+>>> instance SOP.HasDatatypeInfo User
126+
119127>>> :{
120128let
121− insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'Null 'PGtext ] '[]
129+ insertUser :: Manipulation_ Schemas User ()
122130 insertUser = with (u `as` #u) e
123131 where
124132 u = insertInto #users
@@ -138,9 +146,7 @@ need to use an inner join to get the right result. A `Query` is like a
138146
139147>>> :{
140148let
141− getUsers :: Query DB '[]
142− '[ "userName" ::: 'NotNull 'PGtext
143− , "userEmail" ::: 'Null 'PGtext ]
149+ getUsers :: Query_ Schemas () User
144150 getUsers = select_
145151 (#u ! #name `as` #userName :* #e ! #email `as` #userEmail)
146152 ( from (table (#users `as` #u)
@@ -151,17 +157,7 @@ let
151157>>> printSQL getUsers
152158SELECT "u"."name" AS "userName", "e"."email" AS "userEmail" FROM "users" AS "u" INNER JOIN "emails" AS "e" ON ("u"."id" = "e"."user_id")
153159
154−Now that we've defined the SQL side of things, we'll need a Haskell type
155−for users. We give the type `Generics.SOP.Generic` and
156−`Generics.SOP.HasDatatypeInfo` instances so that we can decode the rows
157−we receive when we run @getUsers@. Notice that the record fields of the
158−@User@ type match the column names of @getUsers@.
159−
160−>>> data User = User { userName :: Text, userEmail :: Maybe Text } deriving (Show, GHC.Generic)
161−>>> instance SOP.Generic User
162−>>> instance SOP.HasDatatypeInfo User
163−
164−Let's also create some users to add to the database.
160+Let's create some users to add to the database.
165161
166162>>> :{
167163let
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3
@@ -27,7 +27,7 @@ round trip query.
2727>>> instance HasDatatypeInfo Row
2828>>> :{
2929let
30− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
30+ roundTrip :: Query_ (Public '[]) Row Row
3131 roundTrip = values_ $
3232 parameter @1 int2 `as` #col1 :*
3333 parameter @2 text `as` #col2 :*
@@ -68,7 +68,7 @@ Once again, we define a simple round trip query.
6868
6969>>> :{
7070let
71− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
71+ roundTrip :: Query_ (Public '[]) Row Row
7272 roundTrip = values_ $
7373 parameter @1 (int2 & vararray) `as` #col1 :*
7474 parameter @2 (int2 & fixarray @2) `as` #col2 :*
@@ -146,7 +146,7 @@ Once again, define a round trip query.
146146
147147>>> :{
148148let
149− roundTrip :: Query (DBof (Public Schema)) (TuplePG Row) (RowPG Row)
149+ roundTrip :: Query_ (Public Schema) Row Row
150150 roundTrip = values_ $
151151 parameter @1 (typedef #schwarma) `as` #schwarma :*
152152 parameter @2 (typedef #person) `as` #person1 :*
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+4−4
@@ -297,7 +297,7 @@ check
297297 , HasAll aliases (TableToRow table) subcolumns )
298298 => NP Alias aliases
299299 -- ^ specify the subcolumns which are getting checked
300− -> (forall t. Condition ('[] :=> schemas) '[] 'Ungrouped '[t ::: subcolumns])
300+ -> (forall t. Condition '[] schemas '[] 'Ungrouped '[t ::: subcolumns])
301301 -- ^ a closed `Condition` on those subcolumns
302302 -> TableConstraintExpression sch tab schemas ('Check aliases)
303303check _cols condition = UnsafeTableConstraintExpression $
@@ -758,7 +758,7 @@ newtype AlterColumn (schemas :: SchemasType) (ty0 :: ColumnType) (ty1 :: ColumnT
758758-- :}
759759-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
760760setDefault
761− :: Expression ('[] :=> schemas) '[] 'Ungrouped '[] ty -- ^ default value to set
761+ :: Expression '[] schemas '[] 'Ungrouped '[] ty -- ^ default value to set
762762 -> AlterColumn schemas (constraint :=> ty) ('Def :=> ty)
763763setDefault expression = UnsafeAlterColumn $
764764 "SET DEFAULT" <+> renderExpression expression
@@ -843,7 +843,7 @@ CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
843843createView
844844 :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
845845 => QualifiedAlias sch vw -- ^ the name of the view to add
846− -> Query ('[] :=> schemas) '[] view -- ^ query
846+ -> Query '[] schemas '[] view -- ^ query
847847 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
848848createView alias query = UnsafeDefinition $
849849 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
@@ -1009,7 +1009,7 @@ notNullable ty = UnsafeColumnTypeExpression $ renderSQL ty <+> "NOT NULL"
10091009
10101010-- | used in `createTable` commands as a column constraint to give a default
10111011default_
1012− :: Expression ('[] :=> schemas) '[] 'Ungrouped '[] ty
1012+ :: Expression '[] schemas '[] 'Ungrouped '[] ty
10131013 -> ColumnTypeExpression schemas ('NoDef :=> ty)
10141014 -> ColumnTypeExpression schemas ('Def :=> ty)
10151015default_ x ty = UnsafeColumnTypeExpression $
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+308−308
@@ -218,7 +218,8 @@ values from primitive expression using arithmetic, logical,
218218and other operations.
219219-}
220220newtype Expression
221− (db :: DBType)
221+ (commons :: FromType)
222+ (schemas :: SchemasType)
222223 (params :: [NullityType])
223224 (grp :: Grouping)
224225 (from :: FromType)
@@ -226,7 +227,7 @@ newtype Expression
226227 = UnsafeExpression { renderExpression :: ByteString }
227228 deriving (GHC.Generic,Show,Eq,Ord,NFData)
228229
229−instance RenderSQL (Expression db params grp from ty) where
230+instance RenderSQL (Expression commons schemas params grp from ty) where
230231 renderSQL = renderExpression
231232
232233{- | A `HasParameter` constraint is used to indicate a value that is
@@ -244,12 +245,12 @@ class KnownNat n => HasParameter
244245 | n params -> ty where
245246 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
246247 --
247− -- >>> let expr = parameter @1 int4 :: Expression (DBof schemas) '[ 'Null 'PGint4] grp from ('Null 'PGint4)
248+ -- >>> let expr = parameter @1 int4 :: Expression '[] schemas '[ 'Null 'PGint4] grp from ('Null 'PGint4)
248249 -- >>> printSQL expr
249250 -- ($1 :: int4)
250251 parameter
251252 :: TypeExpression schemas ty
252− -> Expression (commons :=> schemas) params grp from ty
253+ -> Expression commons schemas params grp from ty
253254 parameter ty = UnsafeExpression $ parenthesized $
254255 "$" <> renderNat @n <+> "::"
255256 <+> renderSQL ty
@@ -260,38 +261,38 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
260261-- | `param` takes a `Nat` using type application and for basic types,
261262-- infers a `TypeExpression`.
262263--
263−-- >>> let expr = param @1 :: Expression (commons :=> schemas) '[ 'Null 'PGint4] grp from ('Null 'PGint4)
264+-- >>> let expr = param @1 :: Expression commons schemas '[ 'Null 'PGint4] grp from ('Null 'PGint4)
264265-- >>> printSQL expr
265266-- ($1 :: int4)
266267param
267− :: forall n db commons schemas params from grp ty
268− . (db ~ (commons :=> schemas), PGTyped schemas ty, HasParameter n params ty)
269− => Expression db params grp from ty -- ^ param
268+ :: forall n commons schemas params from grp ty
269+ . (PGTyped schemas ty, HasParameter n params ty)
270+ => Expression commons schemas params grp from ty -- ^ param
270271param = parameter @n (pgtype @schemas)
271272
272273instance (HasUnique tab from row, Has col row ty)
273− => IsLabel col (Expression db params 'Ungrouped from ty) where
274+ => IsLabel col (Expression commons schemas params 'Ungrouped from ty) where
274275 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
275276instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
276277 => IsLabel col
277− (Aliased (Expression db params 'Ungrouped from) column) where
278+ (Aliased (Expression commons schemas params 'Ungrouped from) column) where
278279 fromLabel = fromLabel @col `As` Alias
279280instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: ty])
280281 => IsLabel col
281− (NP (Aliased (Expression db params 'Ungrouped from)) columns) where
282+ (NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns) where
282283 fromLabel = fromLabel @col :* Nil
283284
284285instance (Has tab from row, Has col row ty)
285− => IsQualified tab col (Expression db params 'Ungrouped from ty) where
286+ => IsQualified tab col (Expression commons schemas params 'Ungrouped from ty) where
286287 tab ! col = UnsafeExpression $
287288 renderSQL tab <> "." <> renderSQL col
288289instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
289290 => IsQualified tab col
290− (Aliased (Expression db params 'Ungrouped from) column) where
291+ (Aliased (Expression commons schemas params 'Ungrouped from) column) where
291292 tab ! col = tab ! col `As` col
292293instance (Has tab from row, Has col row ty, columns ~ '[col ::: ty])
293294 => IsQualified tab col
294− (NP (Aliased (Expression db params 'Ungrouped from)) columns) where
295+ (NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns) where
295296 tab ! col = tab ! col :* Nil
296297
297298instance
@@ -299,7 +300,7 @@ instance
299300 , Has col row ty
300301 , GroupedBy tab col bys
301302 ) => IsLabel col
302− (Expression db params ('Grouped bys) from ty) where
303+ (Expression commons schemas params ('Grouped bys) from ty) where
303304 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
304305instance
305306 ( HasUnique tab from row
@@ -307,7 +308,7 @@ instance
307308 , GroupedBy tab col bys
308309 , column ~ (col ::: ty)
309310 ) => IsLabel col
310− (Aliased (Expression db params ('Grouped bys) from) column) where
311+ (Aliased (Expression commons schemas params ('Grouped bys) from) column) where
311312 fromLabel = fromLabel @col `As` Alias
312313instance
313314 ( HasUnique tab from row
@@ -315,7 +316,7 @@ instance
315316 , GroupedBy tab col bys
316317 , columns ~ '[col ::: ty]
317318 ) => IsLabel col
318− (NP (Aliased (Expression db params ('Grouped bys) from)) columns) where
319+ (NP (Aliased (Expression commons schemas params ('Grouped bys) from)) columns) where
319320 fromLabel = fromLabel @col :* Nil
320321
321322instance
@@ -323,7 +324,7 @@ instance
323324 , Has col row ty
324325 , GroupedBy tab col bys
325326 ) => IsQualified tab col
326− (Expression db params ('Grouped bys) from ty) where
327+ (Expression commons schemas params ('Grouped bys) from ty) where
327328 tab ! col = UnsafeExpression $
328329 renderSQL tab <> "." <> renderSQL col
329330instance
@@ -332,7 +333,7 @@ instance
332333 , GroupedBy tab col bys
333334 , column ~ (col ::: ty)
334335 ) => IsQualified tab col
335− (Aliased (Expression db params ('Grouped bys) from) column) where
336+ (Aliased (Expression commons schemas params ('Grouped bys) from) column) where
336337 tab ! col = tab ! col `As` col
337338instance
338339 ( Has tab from row
@@ -340,14 +341,14 @@ instance
340341 , GroupedBy tab col bys
341342 , columns ~ '[col ::: ty]
342343 ) => IsQualified tab col
343− (NP (Aliased (Expression db params ('Grouped bys) from)) columns) where
344+ (NP (Aliased (Expression commons schemas params ('Grouped bys) from)) columns) where
344345 tab ! col = tab ! col :* Nil
345346
346347-- | analagous to `Nothing`
347348--
348349-- >>> printSQL null_
349350-- NULL
350−null_ :: Expression db rels grouping params ('Null ty)
351+null_ :: Expression commons schemas rels grouping params ('Null ty)
351352null_ = UnsafeExpression "NULL"
352353
353354-- | analagous to `Just`
@@ -355,8 +356,8 @@ null_ = UnsafeExpression "NULL"
355356-- >>> printSQL $ notNull true
356357-- TRUE
357358notNull
358− :: Expression db rels grouping params ('NotNull ty)
359− -> Expression db rels grouping params ('Null ty)
359+ :: Expression commons schemas rels grouping params ('NotNull ty)
360+ -> Expression commons schemas rels grouping params ('Null ty)
360361notNull = UnsafeExpression . renderSQL
361362
362363-- | return the leftmost value which is not NULL
@@ -364,11 +365,11 @@ notNull = UnsafeExpression . renderSQL
364365-- >>> printSQL $ coalesce [null_, true] false
365366-- COALESCE(NULL, TRUE, FALSE)
366367coalesce
367− :: [Expression db params grp from ('Null ty)]
368+ :: [Expression commons schemas params grp from ('Null ty)]
368369 -- ^ @NULL@s may be present
369− -> Expression db params grp from ('NotNull ty)
370+ -> Expression commons schemas params grp from ('NotNull ty)
370371 -- ^ @NULL@ is absent
371− -> Expression db params grp from ('NotNull ty)
372+ -> Expression commons schemas params grp from ('NotNull ty)
372373coalesce nullxs notNullx = UnsafeExpression $
373374 "COALESCE" <> parenthesized (commaSeparated
374375 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
@@ -378,26 +379,26 @@ coalesce nullxs notNullx = UnsafeExpression $
378379-- >>> printSQL $ fromNull true null_
379380-- COALESCE(NULL, TRUE)
380381fromNull
381− :: Expression db params grp from ('NotNull ty)
382+ :: Expression commons schemas params grp from ('NotNull ty)
382383 -- ^ what to convert @NULL@ to
383− -> Expression db params grp from ('Null ty)
384− -> Expression db params grp from ('NotNull ty)
384+ -> Expression commons schemas params grp from ('Null ty)
385+ -> Expression commons schemas params grp from ('NotNull ty)
385386fromNull notNullx nullx = coalesce [nullx] notNullx
386387
387388-- | >>> printSQL $ null_ & isNull
388389-- NULL IS NULL
389390isNull
390− :: Expression db params grp from ('Null ty)
391+ :: Expression commons schemas params grp from ('Null ty)
391392 -- ^ possibly @NULL@
392− -> Condition db params grp from
393+ -> Condition commons schemas params grp from
393394isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
394395
395396-- | >>> printSQL $ null_ & isNotNull
396397-- NULL IS NOT NULL
397398isNotNull
398− :: Expression db params grp from ('Null ty)
399+ :: Expression commons schemas params grp from ('Null ty)
399400 -- ^ possibly @NULL@
400− -> Condition db params grp from
401+ -> Condition commons schemas params grp from
401402isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
402403
403404-- | analagous to `maybe` using @IS NULL@
@@ -405,13 +406,13 @@ isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
405406-- >>> printSQL $ matchNull true not_ null_
406407-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407408matchNull
408− :: Expression db params grp from (nullty)
409+ :: Expression commons schemas params grp from (nullty)
409410 -- ^ what to convert @NULL@ to
410− -> ( Expression db params grp from ('NotNull ty)
411− -> Expression db params grp from (nullty) )
411+ -> ( Expression commons schemas params grp from ('NotNull ty)
412+ -> Expression commons schemas params grp from (nullty) )
412413 -- ^ function to perform when @NULL@ is absent
413− -> Expression db params grp from ('Null ty)
414− -> Expression db params grp from (nullty)
414+ -> Expression commons schemas params grp from ('Null ty)
415+ -> Expression commons schemas params grp from (nullty)
415416matchNull y f x = ifThenElse (isNull x) y
416417 (f (UnsafeExpression (renderSQL x)))
417418
@@ -419,25 +420,25 @@ matchNull y f x = ifThenElse (isNull x) y
419420`nullIf` gives @NULL@.
420421
421422>>> :set -XTypeApplications -XDataKinds
422−>>> let expr = nullIf false (param @1) :: Expression (commons :=> schema) '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
423+>>> let expr = nullIf false (param @1) :: Expression commons schemas '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
423424>>> printSQL expr
424425NULL IF (FALSE, ($1 :: bool))
425426-}
426427nullIf
427− :: Expression db params grp from ('NotNull ty)
428+ :: Expression commons schemas params grp from ('NotNull ty)
428429 -- ^ @NULL@ is absent
429− -> Expression db params grp from ('NotNull ty)
430+ -> Expression commons schemas params grp from ('NotNull ty)
430431 -- ^ @NULL@ is absent
431− -> Expression db params grp from ('Null ty)
432+ -> Expression commons schemas params grp from ('Null ty)
432433nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
433434 (renderSQL x <> ", " <> renderSQL y)
434435
435436-- | >>> printSQL $ array [null_, false, true]
436437-- ARRAY[NULL, FALSE, TRUE]
437438array
438− :: [Expression db params grp from ty]
439+ :: [Expression commons schemas params grp from ty]
439440 -- ^ array elements
440− -> Expression db params grp from (nullity ('PGvararray ty))
441+ -> Expression commons schemas params grp from (nullity ('PGvararray ty))
441442array xs = UnsafeExpression $
442443 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
443444
@@ -445,13 +446,13 @@ array xs = UnsafeExpression $
445446-- (ARRAY[NULL, FALSE, TRUE])[2]
446447index
447448 :: Word64 -- ^ index
448− -> Expression db params grp from (nullity ('PGvararray ty)) -- ^ array
449− -> Expression db params grp from (NullifyType ty)
449+ -> Expression commons schemas params grp from (nullity ('PGvararray ty)) -- ^ array
450+ -> Expression commons schemas params grp from (NullifyType ty)
450451index n expr = UnsafeExpression $
451452 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
452453
453454instance (KnownSymbol label, label `In` labels) => IsPGlabel label
454− (Expression db params grp from (nullity ('PGenum labels))) where
455+ (Expression commons schemas params grp from (nullity ('PGenum labels))) where
455456 label = UnsafeExpression $ renderSQL (PGlabel @label)
456457
457458-- | A row constructor is an expression that builds a row value
@@ -463,14 +464,14 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
463464-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
464465-- :}
465466--
466−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression db from grp params ('NotNull Complex)
467+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression commons schemas from grp params ('NotNull Complex)
467468-- >>> printSQL i
468469-- ROW(0, 1)
469470row
470471 :: SListI row
471− => NP (Aliased (Expression db params grp from)) row
472+ => NP (Aliased (Expression commons schemas params grp from)) row
472473 -- ^ zero or more expressions for the row field values
473− -> Expression db params grp from (nullity ('PGcomposite row))
474+ -> Expression commons schemas params grp from (nullity ('PGcomposite row))
474475row exprs = UnsafeExpression $ "ROW" <> parenthesized
475476 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
476477
@@ -479,10 +480,9 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
479480-- '[ "real" ::: 'NotNull 'PGfloat8
480481-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
481482-- type Schema = '["complex" ::: 'Typedef Complex]
482−-- type DB = DBof (Public Schema)
483483-- :}
484484--
485−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression DB from grp params ('NotNull Complex)
485+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] (Public Schema) from grp params ('NotNull Complex)
486486-- >>> printSQL $ i & field #complex #imaginary
487487-- (ROW(0, 1)::"complex")."imaginary"
488488field
@@ -491,41 +491,41 @@ field
491491 , Has field row ty)
492492 => QualifiedAlias sch tydef -- ^ row type
493493 -> Alias field -- ^ field name
494− -> Expression (commons :=> schemas) params grp from ('NotNull ('PGcomposite row))
495− -> Expression (commons :=> schemas) params grp from ty
494+ -> Expression commons schemas params grp from ('NotNull ('PGcomposite row))
495+ -> Expression commons schemas params grp from ty
496496field td fld expr = UnsafeExpression $
497497 parenthesized (renderSQL expr <> "::" <> renderSQL td)
498498 <> "." <> renderSQL fld
499499
500500instance Semigroup
501− (Expression db params grp from (nullity ('PGvararray ty))) where
501+ (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
502502 (<>) = unsafeBinaryOp "||"
503503
504504instance Monoid
505− (Expression db params grp from (nullity ('PGvararray ty))) where
505+ (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
506506 mempty = array []
507507 mappend = (<>)
508508
509−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression (commons :=> schemas) '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
509+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression commons schemas '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
510510-- >>> printSQL expr
511511-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
512512greatest
513− :: Expression db params grp from (nullty)
513+ :: Expression commons schemas params grp from (nullty)
514514 -- ^ needs at least 1 argument
515− -> [Expression db params grp from (nullty)]
515+ -> [Expression commons schemas params grp from (nullty)]
516516 -- ^ or more
517− -> Expression db params grp from (nullty)
517+ -> Expression commons schemas params grp from (nullty)
518518greatest x xs = UnsafeExpression $ "GREATEST("
519519 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
520520
521521-- | >>> printSQL $ least currentTimestamp [null_]
522522-- LEAST(CURRENT_TIMESTAMP, NULL)
523523least
524− :: Expression db params grp from (nullty)
524+ :: Expression commons schemas params grp from (nullty)
525525 -- ^ needs at least 1 argument
526− -> [Expression db params grp from (nullty)]
526+ -> [Expression commons schemas params grp from (nullty)]
527527 -- ^ or more
528− -> Expression db params grp from (nullty)
528+ -> Expression commons schemas params grp from (nullty)
529529least x xs = UnsafeExpression $ "LEAST("
530530 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
531531
@@ -534,9 +534,9 @@ least x xs = UnsafeExpression $ "LEAST("
534534unsafeBinaryOp
535535 :: ByteString
536536 -- ^ operator
537− -> Expression db params grp from (ty0)
538− -> Expression db params grp from (ty1)
539− -> Expression db params grp from (ty2)
537+ -> Expression commons schemas params grp from (ty0)
538+ -> Expression commons schemas params grp from (ty1)
539+ -> Expression commons schemas params grp from (ty2)
540540unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
541541 renderSQL x <+> op <+> renderSQL y
542542
@@ -545,8 +545,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
545545unsafeUnaryOp
546546 :: ByteString
547547 -- ^ operator
548− -> Expression db params grp from (ty0)
549− -> Expression db params grp from (ty1)
548+ -> Expression commons schemas params grp from (ty0)
549+ -> Expression commons schemas params grp from (ty1)
550550unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
551551 op <+> renderSQL x
552552
@@ -555,8 +555,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
555555unsafeFunction
556556 :: ByteString
557557 -- ^ function
558− -> Expression db params grp from (xty)
559− -> Expression db params grp from (yty)
558+ -> Expression commons schemas params grp from (xty)
559+ -> Expression commons schemas params grp from (yty)
560560unsafeFunction fun x = UnsafeExpression $
561561 fun <> parenthesized (renderSQL x)
562562
@@ -565,13 +565,13 @@ unsafeVariadicFunction
565565 :: SListI elems
566566 => ByteString
567567 -- ^ function
568− -> NP (Expression db params grp from) elems
569− -> Expression db params grp from ret
568+ -> NP (Expression commons schemas params grp from) elems
569+ -> Expression commons schemas params grp from ret
570570unsafeVariadicFunction fun x = UnsafeExpression $
571571 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
572572
573573instance ty `In` PGNum
574− => Num (Expression db params grp from (nullity ty)) where
574+ => Num (Expression commons schemas params grp from (nullity ty)) where
575575 (+) = unsafeBinaryOp "+"
576576 (-) = unsafeBinaryOp "-"
577577 (*) = unsafeBinaryOp "*"
@@ -583,12 +583,12 @@ instance ty `In` PGNum
583583 . show
584584
585585instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
586− (Expression db params grp from (nullity ty)) where
586+ (Expression commons schemas params grp from (nullity ty)) where
587587 (/) = unsafeBinaryOp "/"
588588 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
589589
590590instance (ty `In` PGNum, ty `In` PGFloating) => Floating
591− (Expression db params grp from (nullity ty)) where
591+ (Expression commons schemas params grp from (nullity ty)) where
592592 pi = UnsafeExpression "pi()"
593593 exp = unsafeFunction "exp"
594594 log = unsafeFunction "ln"
@@ -611,18 +611,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
611611
612612-- | >>> :{
613613-- let
614−-- expression :: Expression db params grp from (nullity 'PGfloat4)
614+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
615615-- expression = atan2_ pi 2
616616-- in printSQL expression
617617-- :}
618618-- atan2(pi(), 2)
619619atan2_
620620 :: float `In` PGFloating
621− => Expression db params grp from (nullity float)
621+ => Expression commons schemas params grp from (nullity float)
622622 -- ^ numerator
623− -> Expression db params grp from (nullity float)
623+ -> Expression commons schemas params grp from (nullity float)
624624 -- ^ denominator
625− -> Expression db params grp from (nullity float)
625+ -> Expression commons schemas params grp from (nullity float)
626626atan2_ y x = UnsafeExpression $
627627 "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
628628
@@ -635,9 +635,9 @@ atan2_ y x = UnsafeExpression $
635635cast
636636 :: TypeExpression schemas ty1
637637 -- ^ type to cast as
638− -> Expression (commons :=> schemas) params grp from ty0
638+ -> Expression commons schemas params grp from ty0
639639 -- ^ value to convert
640− -> Expression (commons :=> schemas) params grp from ty1
640+ -> Expression commons schemas params grp from ty1
641641cast ty x = UnsafeExpression $ parenthesized $
642642 renderSQL x <+> "::" <+> renderSQL ty
643643
@@ -645,136 +645,136 @@ cast ty x = UnsafeExpression $ parenthesized $
645645--
646646-- >>> :{
647647-- let
648−-- expression :: Expression db params grp from (nullity 'PGint2)
648+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
649649-- expression = 5 `quot_` 2
650650-- in printSQL expression
651651-- :}
652652-- (5 / 2)
653653quot_
654654 :: int `In` PGIntegral
655− => Expression db params grp from (nullity int)
655+ => Expression commons schemas params grp from (nullity int)
656656 -- ^ numerator
657− -> Expression db params grp from (nullity int)
657+ -> Expression commons schemas params grp from (nullity int)
658658 -- ^ denominator
659− -> Expression db params grp from (nullity int)
659+ -> Expression commons schemas params grp from (nullity int)
660660quot_ = unsafeBinaryOp "/"
661661
662662-- | remainder upon integer division
663663--
664664-- >>> :{
665665-- let
666−-- expression :: Expression db params grp from (nullity 'PGint2)
666+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
667667-- expression = 5 `rem_` 2
668668-- in printSQL expression
669669-- :}
670670-- (5 % 2)
671671rem_
672672 :: int `In` PGIntegral
673− => Expression db params grp from (nullity int)
673+ => Expression commons schemas params grp from (nullity int)
674674 -- ^ numerator
675− -> Expression db params grp from (nullity int)
675+ -> Expression commons schemas params grp from (nullity int)
676676 -- ^ denominator
677− -> Expression db params grp from (nullity int)
677+ -> Expression commons schemas params grp from (nullity int)
678678rem_ = unsafeBinaryOp "%"
679679
680680-- | >>> :{
681681-- let
682−-- expression :: Expression db params grp from (nullity 'PGfloat4)
682+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
683683-- expression = trunc pi
684684-- in printSQL expression
685685-- :}
686686-- trunc(pi())
687687trunc
688688 :: frac `In` PGFloating
689− => Expression db params grp from (nullity frac)
689+ => Expression commons schemas params grp from (nullity frac)
690690 -- ^ fractional number
691− -> Expression db params grp from (nullity frac)
691+ -> Expression commons schemas params grp from (nullity frac)
692692trunc = unsafeFunction "trunc"
693693
694694-- | >>> :{
695695-- let
696−-- expression :: Expression db params grp from (nullity 'PGfloat4)
696+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
697697-- expression = round_ pi
698698-- in printSQL expression
699699-- :}
700700-- round(pi())
701701round_
702702 :: frac `In` PGFloating
703− => Expression db params grp from (nullity frac)
703+ => Expression commons schemas params grp from (nullity frac)
704704 -- ^ fractional number
705− -> Expression db params grp from (nullity frac)
705+ -> Expression commons schemas params grp from (nullity frac)
706706round_ = unsafeFunction "round"
707707
708708-- | >>> :{
709709-- let
710−-- expression :: Expression db params grp from (nullity 'PGfloat4)
710+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
711711-- expression = ceiling_ pi
712712-- in printSQL expression
713713-- :}
714714-- ceiling(pi())
715715ceiling_
716716 :: frac `In` PGFloating
717− => Expression db params grp from (nullity frac)
717+ => Expression commons schemas params grp from (nullity frac)
718718 -- ^ fractional number
719− -> Expression db params grp from (nullity frac)
719+ -> Expression commons schemas params grp from (nullity frac)
720720ceiling_ = unsafeFunction "ceiling"
721721
722722-- | A `Condition` is an `Expression`, which can evaluate
723723-- to `true`, `false` or `null_`. This is because SQL uses
724724-- a three valued logic.
725−type Condition db params grp from =
726− Expression db params grp from ('Null 'PGbool)
725+type Condition commons schemas params grp from =
726+ Expression commons schemas params grp from ('Null 'PGbool)
727727
728728-- | >>> printSQL true
729729-- TRUE
730−true :: Expression db params grp from (nullity 'PGbool)
730+true :: Expression commons schemas params grp from (nullity 'PGbool)
731731true = UnsafeExpression "TRUE"
732732
733733-- | >>> printSQL false
734734-- FALSE
735−false :: Expression db params grp from (nullity 'PGbool)
735+false :: Expression commons schemas params grp from (nullity 'PGbool)
736736false = UnsafeExpression "FALSE"
737737
738738-- | >>> printSQL $ not_ true
739739-- (NOT TRUE)
740740not_
741− :: Expression db params grp from (nullity 'PGbool)
742− -> Expression db params grp from (nullity 'PGbool)
741+ :: Expression commons schemas params grp from (nullity 'PGbool)
742+ -> Expression commons schemas params grp from (nullity 'PGbool)
743743not_ = unsafeUnaryOp "NOT"
744744
745745-- | >>> printSQL $ true .&& false
746746-- (TRUE AND FALSE)
747747(.&&)
748− :: Expression db params grp from (nullity 'PGbool)
749− -> Expression db params grp from (nullity 'PGbool)
750− -> Expression db params grp from (nullity 'PGbool)
748+ :: Expression commons schemas params grp from (nullity 'PGbool)
749+ -> Expression commons schemas params grp from (nullity 'PGbool)
750+ -> Expression commons schemas params grp from (nullity 'PGbool)
751751infixr 3 .&&
752752(.&&) = unsafeBinaryOp "AND"
753753
754754-- | >>> printSQL $ true .|| false
755755-- (TRUE OR FALSE)
756756(.||)
757− :: Expression db params grp from (nullity 'PGbool)
758− -> Expression db params grp from (nullity 'PGbool)
759− -> Expression db params grp from (nullity 'PGbool)
757+ :: Expression commons schemas params grp from (nullity 'PGbool)
758+ -> Expression commons schemas params grp from (nullity 'PGbool)
759+ -> Expression commons schemas params grp from (nullity 'PGbool)
760760infixr 2 .||
761761(.||) = unsafeBinaryOp "OR"
762762
763763-- | >>> :{
764764-- let
765−-- expression :: Expression db params grp from (nullity 'PGint2)
765+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
766766-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
767767-- in printSQL expression
768768-- :}
769769-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
770770caseWhenThenElse
771− :: [ ( Condition db params grp from
772− , Expression db params grp from ty
771+ :: [ ( Condition commons schemas params grp from
772+ , Expression commons schemas params grp from ty
773773 ) ]
774774 -- ^ whens and thens
775− -> Expression db params grp from ty
775+ -> Expression commons schemas params grp from ty
776776 -- ^ else
777− -> Expression db params grp from ty
777+ -> Expression commons schemas params grp from ty
778778caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
779779 [ "CASE"
780780 , mconcat
@@ -790,16 +790,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
790790
791791-- | >>> :{
792792-- let
793−-- expression :: Expression db params grp from (nullity 'PGint2)
793+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
794794-- expression = ifThenElse true 1 0
795795-- in printSQL expression
796796-- :}
797797-- CASE WHEN TRUE THEN 1 ELSE 0 END
798798ifThenElse
799− :: Condition db params grp from
800− -> Expression db params grp from ty -- ^ then
801− -> Expression db params grp from ty -- ^ else
802− -> Expression db params grp from ty
799+ :: Condition commons schemas params grp from
800+ -> Expression commons schemas params grp from ty -- ^ then
801+ -> Expression commons schemas params grp from ty -- ^ else
802+ -> Expression commons schemas params grp from ty
803803ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
804804
805805-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -808,85 +808,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
808808-- >>> printSQL $ true .== null_
809809-- (TRUE = NULL)
810810(.==)
811− :: Expression db params grp from (nullity0 ty) -- ^ lhs
812− -> Expression db params grp from (nullity1 ty) -- ^ rhs
813− -> Condition db params grp from
811+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
812+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
813+ -> Condition commons schemas params grp from
814814(.==) = unsafeBinaryOp "="
815815infix 4 .==
816816
817817-- | >>> printSQL $ true ./= null_
818818-- (TRUE <> NULL)
819819(./=)
820− :: Expression db params grp from (nullity0 ty) -- ^ lhs
821− -> Expression db params grp from (nullity1 ty) -- ^ rhs
822− -> Condition db params grp from
820+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
821+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
822+ -> Condition commons schemas params grp from
823823(./=) = unsafeBinaryOp "<>"
824824infix 4 ./=
825825
826826-- | >>> printSQL $ true .>= null_
827827-- (TRUE >= NULL)
828828(.>=)
829− :: Expression db params grp from (nullity0 ty) -- ^ lhs
830− -> Expression db params grp from (nullity1 ty) -- ^ rhs
831− -> Condition db params grp from
829+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
830+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
831+ -> Condition commons schemas params grp from
832832(.>=) = unsafeBinaryOp ">="
833833infix 4 .>=
834834
835835-- | >>> printSQL $ true .< null_
836836-- (TRUE < NULL)
837837(.<)
838− :: Expression db params grp from (nullity0 ty) -- ^ lhs
839− -> Expression db params grp from (nullity1 ty) -- ^ rhs
840− -> Condition db params grp from
838+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
839+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
840+ -> Condition commons schemas params grp from
841841(.<) = unsafeBinaryOp "<"
842842infix 4 .<
843843
844844-- | >>> printSQL $ true .<= null_
845845-- (TRUE <= NULL)
846846(.<=)
847− :: Expression db params grp from (nullity0 ty) -- ^ lhs
848− -> Expression db params grp from (nullity1 ty) -- ^ rhs
849− -> Condition db params grp from
847+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
848+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
849+ -> Condition commons schemas params grp from
850850(.<=) = unsafeBinaryOp "<="
851851infix 4 .<=
852852
853853-- | >>> printSQL $ true .> null_
854854-- (TRUE > NULL)
855855(.>)
856− :: Expression db params grp from (nullity0 ty) -- ^ lhs
857− -> Expression db params grp from (nullity1 ty) -- ^ rhs
858− -> Condition db params grp from
856+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
857+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
858+ -> Condition commons schemas params grp from
859859(.>) = unsafeBinaryOp ">"
860860infix 4 .>
861861
862862-- | >>> printSQL currentDate
863863-- CURRENT_DATE
864864currentDate
865− :: Expression db params grp from (nullity 'PGdate)
865+ :: Expression commons schemas params grp from (nullity 'PGdate)
866866currentDate = UnsafeExpression "CURRENT_DATE"
867867
868868-- | >>> printSQL currentTime
869869-- CURRENT_TIME
870870currentTime
871− :: Expression db params grp from (nullity 'PGtimetz)
871+ :: Expression commons schemas params grp from (nullity 'PGtimetz)
872872currentTime = UnsafeExpression "CURRENT_TIME"
873873
874874-- | >>> printSQL currentTimestamp
875875-- CURRENT_TIMESTAMP
876876currentTimestamp
877− :: Expression db params grp from (nullity 'PGtimestamptz)
877+ :: Expression commons schemas params grp from (nullity 'PGtimestamptz)
878878currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
879879
880880-- | >>> printSQL localTime
881881-- LOCALTIME
882882localTime
883− :: Expression db params grp from (nullity 'PGtime)
883+ :: Expression commons schemas params grp from (nullity 'PGtime)
884884localTime = UnsafeExpression "LOCALTIME"
885885
886886-- | >>> printSQL localTimestamp
887887-- LOCALTIMESTAMP
888888localTimestamp
889− :: Expression db params grp from (nullity 'PGtimestamp)
889+ :: Expression commons schemas params grp from (nullity 'PGtimestamp)
890890localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
891891
892892{-----------------------------------------
@@ -894,7 +894,7 @@ text
894894-----------------------------------------}
895895
896896instance IsString
897− (Expression db params grp from (nullity 'PGtext)) where
897+ (Expression commons schemas params grp from (nullity 'PGtext)) where
898898 fromString str = UnsafeExpression $
899899 "E\'" <> fromString (escape =<< str) <> "\'"
900900 where
@@ -910,36 +910,36 @@ instance IsString
910910 c -> [c]
911911
912912instance Semigroup
913− (Expression db params grp from (nullity 'PGtext)) where
913+ (Expression commons schemas params grp from (nullity 'PGtext)) where
914914 (<>) = unsafeBinaryOp "||"
915915
916916instance Monoid
917− (Expression db params grp from (nullity 'PGtext)) where
917+ (Expression commons schemas params grp from (nullity 'PGtext)) where
918918 mempty = fromString ""
919919 mappend = (<>)
920920
921921-- | >>> printSQL $ lower "ARRRGGG"
922922-- lower(E'ARRRGGG')
923923lower
924− :: Expression db params grp from (nullity 'PGtext)
924+ :: Expression commons schemas params grp from (nullity 'PGtext)
925925 -- ^ string to lower case
926− -> Expression db params grp from (nullity 'PGtext)
926+ -> Expression commons schemas params grp from (nullity 'PGtext)
927927lower = unsafeFunction "lower"
928928
929929-- | >>> printSQL $ upper "eeee"
930930-- upper(E'eeee')
931931upper
932− :: Expression db params grp from (nullity 'PGtext)
932+ :: Expression commons schemas params grp from (nullity 'PGtext)
933933 -- ^ string to upper case
934− -> Expression db params grp from (nullity 'PGtext)
934+ -> Expression commons schemas params grp from (nullity 'PGtext)
935935upper = unsafeFunction "upper"
936936
937937-- | >>> printSQL $ charLength "four"
938938-- char_length(E'four')
939939charLength
940− :: Expression db params grp from (nullity 'PGtext)
940+ :: Expression commons schemas params grp from (nullity 'PGtext)
941941 -- ^ string to measure
942− -> Expression db params grp from (nullity 'PGint4)
942+ -> Expression commons schemas params grp from (nullity 'PGint4)
943943charLength = unsafeFunction "char_length"
944944
945945-- | The `like` expression returns true if the @string@ matches
@@ -952,11 +952,11 @@ charLength = unsafeFunction "char_length"
952952-- >>> printSQL $ "abc" `like` "a%"
953953-- (E'abc' LIKE E'a%')
954954like
955− :: Expression db params grp from (nullity 'PGtext)
955+ :: Expression commons schemas params grp from (nullity 'PGtext)
956956 -- ^ string
957− -> Expression db params grp from (nullity 'PGtext)
957+ -> Expression commons schemas params grp from (nullity 'PGtext)
958958 -- ^ pattern
959− -> Expression db params grp from (nullity 'PGbool)
959+ -> Expression commons schemas params grp from (nullity 'PGbool)
960960like = unsafeBinaryOp "LIKE"
961961
962962-- | The key word ILIKE can be used instead of LIKE to make the
@@ -965,11 +965,11 @@ like = unsafeBinaryOp "LIKE"
965965-- >>> printSQL $ "abc" `ilike` "a%"
966966-- (E'abc' ILIKE E'a%')
967967ilike
968− :: Expression db params grp from (nullity 'PGtext)
968+ :: Expression commons schemas params grp from (nullity 'PGtext)
969969 -- ^ string
970− -> Expression db params grp from (nullity 'PGtext)
970+ -> Expression commons schemas params grp from (nullity 'PGtext)
971971 -- ^ pattern
972− -> Expression db params grp from (nullity 'PGbool)
972+ -> Expression commons schemas params grp from (nullity 'PGbool)
973973ilike = unsafeBinaryOp "ILIKE"
974974
975975{-----------------------------------------
@@ -984,36 +984,36 @@ Table 9.44: json and jsonb operators
984984-- | Get JSON value (object field or array element) at a key.
985985(.->)
986986 :: (json `In` PGJsonType, key `In` PGJsonKey)
987− => Expression db params grp from (nullity json)
988− -> Expression db params grp from (nullity key)
989− -> Expression db params grp from ('Null json)
987+ => Expression commons schemas params grp from (nullity json)
988+ -> Expression commons schemas params grp from (nullity key)
989+ -> Expression commons schemas params grp from ('Null json)
990990infixl 8 .->
991991(.->) = unsafeBinaryOp "->"
992992
993993-- | Get JSON value (object field or array element) at a key, as text.
994994(.->>)
995995 :: (json `In` PGJsonType, key `In` PGJsonKey)
996− => Expression db params grp from (nullity json)
997− -> Expression db params grp from (nullity key)
998− -> Expression db params grp from ('Null 'PGtext)
996+ => Expression commons schemas params grp from (nullity json)
997+ -> Expression commons schemas params grp from (nullity key)
998+ -> Expression commons schemas params grp from ('Null 'PGtext)
999999infixl 8 .->>
10001000(.->>) = unsafeBinaryOp "->>"
10011001
10021002-- | Get JSON value at a specified path.
10031003(.#>)
10041004 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1005− => Expression db params grp from (nullity json)
1006− -> Expression db params grp from (nullity path)
1007− -> Expression db params grp from ('Null json)
1005+ => Expression commons schemas params grp from (nullity json)
1006+ -> Expression commons schemas params grp from (nullity path)
1007+ -> Expression commons schemas params grp from ('Null json)
10081008infixl 8 .#>
10091009(.#>) = unsafeBinaryOp "#>"
10101010
10111011-- | Get JSON value at a specified path as text.
10121012(.#>>)
10131013 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1014− => Expression db params grp from (nullity json)
1015− -> Expression db params grp from (nullity path)
1016− -> Expression db params grp from ('Null 'PGtext)
1014+ => Expression commons schemas params grp from (nullity json)
1015+ -> Expression commons schemas params grp from (nullity path)
1016+ -> Expression commons schemas params grp from ('Null 'PGtext)
10171017infixl 8 .#>>
10181018(.#>>) = unsafeBinaryOp "#>>"
10191019
@@ -1022,48 +1022,48 @@ infixl 8 .#>>
10221022-- | Does the left JSON value contain the right JSON path/value entries at the
10231023-- top level?
10241024(.@>)
1025− :: Expression db params grp from (nullity 'PGjsonb)
1026− -> Expression db params grp from (nullity 'PGjsonb)
1027− -> Condition db params grp from
1025+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1026+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1027+ -> Condition commons schemas params grp from
10281028infixl 9 .@>
10291029(.@>) = unsafeBinaryOp "@>"
10301030
10311031-- | Are the left JSON path/value entries contained at the top level within the
10321032-- right JSON value?
10331033(.<@)
1034− :: Expression db params grp from (nullity 'PGjsonb)
1035− -> Expression db params grp from (nullity 'PGjsonb)
1036− -> Condition db params grp from
1034+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1035+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1036+ -> Condition commons schemas params grp from
10371037infixl 9 .<@
10381038(.<@) = unsafeBinaryOp "<@"
10391039
10401040-- | Does the string exist as a top-level key within the JSON value?
10411041(.?)
1042− :: Expression db params grp from (nullity 'PGjsonb)
1043− -> Expression db params grp from (nullity 'PGtext)
1044− -> Condition db params grp from
1042+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1043+ -> Expression commons schemas params grp from (nullity 'PGtext)
1044+ -> Condition commons schemas params grp from
10451045infixl 9 .?
10461046(.?) = unsafeBinaryOp "?"
10471047
10481048-- | Do any of these array strings exist as top-level keys?
10491049(.?|)
1050− :: Expression db params grp from (nullity 'PGjsonb)
1051− -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1052− -> Condition db params grp from
1050+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1051+ -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1052+ -> Condition commons schemas params grp from
10531053infixl 9 .?|
10541054(.?|) = unsafeBinaryOp "?|"
10551055
10561056-- | Do all of these array strings exist as top-level keys?
10571057(.?&)
1058− :: Expression db params grp from (nullity 'PGjsonb)
1059− -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1060− -> Condition db params grp from
1058+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1059+ -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1060+ -> Condition commons schemas params grp from
10611061infixl 9 .?&
10621062(.?&) = unsafeBinaryOp "?&"
10631063
10641064-- | Concatenate two jsonb values into a new jsonb value.
10651065instance
1066− Semigroup (Expression db from grouping param (nullity 'PGjsonb)) where
1066+ Semigroup (Expression commons schemas from grouping param (nullity 'PGjsonb)) where
10671067 (<>) = unsafeBinaryOp "||"
10681068
10691069-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1080,9 +1080,9 @@ instance
10801080-- count from the end). Throws an error if top level container is not an array.
10811081(.-.)
10821082 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1083− => Expression db params grp from (nullity 'PGjsonb)
1084− -> Expression db params grp from (nullity key)
1085− -> Expression db params grp from (nullity 'PGjsonb)
1083+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1084+ -> Expression commons schemas params grp from (nullity key)
1085+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
10861086infixl 6 .-.
10871087(.-.) = unsafeBinaryOp "-"
10881088
@@ -1090,9 +1090,9 @@ infixl 6 .-.
10901090-- integers count from the end)
10911091(#-.)
10921092 :: PGTextArray "(#-.)" arrayty
1093− => Expression db params grp from (nullity 'PGjsonb)
1094− -> Expression db params grp from (nullity arrayty)
1095− -> Expression db params grp from (nullity 'PGjsonb)
1093+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1094+ -> Expression commons schemas params grp from (nullity arrayty)
1095+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
10961096infixl 6 #-.
10971097(#-.) = unsafeBinaryOp "#-"
10981098
@@ -1103,14 +1103,14 @@ Table 9.45: JSON creation functions
11031103-- | Literal binary JSON
11041104jsonbLit
11051105 :: JSON.ToJSON x
1106− => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjsonb)
1106+ => x -> Expression commons schemas params grp from (nullity 'PGjsonb)
11071107jsonbLit = cast jsonb . UnsafeExpression
11081108 . singleQuotedUtf8 . toStrict . JSON.encode
11091109
11101110-- | Literal JSON
11111111jsonLit
11121112 :: JSON.ToJSON x
1113− => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjson)
1113+ => x -> Expression commons schemas params grp from (nullity 'PGjson)
11141114jsonLit = cast json . UnsafeExpression
11151115 . singleQuotedUtf8 . toStrict . JSON.encode
11161116
@@ -1121,8 +1121,8 @@ jsonLit = cast json . UnsafeExpression
11211121-- number, a Boolean, or a null value, the text representation will be used, in
11221122-- such a fashion that it is a valid json value.
11231123toJson
1124− :: Expression db params grp from (nullity ty)
1125− -> Expression db params grp from (nullity 'PGjson)
1124+ :: Expression commons schemas params grp from (nullity ty)
1125+ -> Expression commons schemas params grp from (nullity 'PGjson)
11261126toJson = unsafeFunction "to_json"
11271127
11281128-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1132,43 +1132,43 @@ toJson = unsafeFunction "to_json"
11321132-- number, a Boolean, or a null value, the text representation will be used, in
11331133-- such a fashion that it is a valid jsonb value.
11341134toJsonb
1135− :: Expression db params grp from (nullity ty)
1136− -> Expression db params grp from (nullity 'PGjsonb)
1135+ :: Expression commons schemas params grp from (nullity ty)
1136+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
11371137toJsonb = unsafeFunction "to_jsonb"
11381138
11391139-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
11401140-- becomes a JSON array of arrays.
11411141arrayToJson
11421142 :: PGArray "arrayToJson" arr
1143− => Expression db params grp from (nullity arr)
1144− -> Expression db params grp from (nullity 'PGjson)
1143+ => Expression commons schemas params grp from (nullity arr)
1144+ -> Expression commons schemas params grp from (nullity 'PGjson)
11451145arrayToJson = unsafeFunction "array_to_json"
11461146
11471147-- | Returns the row as a JSON object.
11481148rowToJson
1149− :: Expression db params grp from (nullity ('PGcomposite ty))
1150− -> Expression db params grp from (nullity 'PGjson)
1149+ :: Expression commons schemas params grp from (nullity ('PGcomposite ty))
1150+ -> Expression commons schemas params grp from (nullity 'PGjson)
11511151rowToJson = unsafeFunction "row_to_json"
11521152
11531153-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
11541154-- argument list.
11551155jsonBuildArray
11561156 :: SListI elems
1157− => NP (Expression db params grp from) elems
1158− -> Expression db params grp from (nullity 'PGjson)
1157+ => NP (Expression commons schemas params grp from) elems
1158+ -> Expression commons schemas params grp from (nullity 'PGjson)
11591159jsonBuildArray = unsafeVariadicFunction "json_build_array"
11601160
11611161-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
11621162-- variadic argument list.
11631163jsonbBuildArray
11641164 :: SListI elems
1165− => NP (Expression db params grp from) elems
1166− -> Expression db params grp from (nullity 'PGjsonb)
1165+ => NP (Expression commons schemas params grp from) elems
1166+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
11671167jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
11681168
11691169unsafeRowFunction
11701170 :: All Top elems
1171− => NP (Aliased (Expression db params grp from)) elems
1171+ => NP (Aliased (Expression commons schemas params grp from)) elems
11721172 -> [ByteString]
11731173unsafeRowFunction =
11741174 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1183,8 +1183,8 @@ unsafeRowFunction =
11831183-- and values.
11841184jsonBuildObject
11851185 :: All Top elems
1186− => NP (Aliased (Expression db params grp from)) elems
1187− -> Expression db params grp from (nullity 'PGjson)
1186+ => NP (Aliased (Expression commons schemas params grp from)) elems
1187+ -> Expression commons schemas params grp from (nullity 'PGjson)
11881188jsonBuildObject
11891189 = unsafeFunction "json_build_object"
11901190 . UnsafeExpression
@@ -1196,8 +1196,8 @@ jsonBuildObject
11961196-- between text and values.
11971197jsonbBuildObject
11981198 :: All Top elems
1199− => NP (Aliased (Expression db params grp from)) elems
1200− -> Expression db params grp from (nullity 'PGjsonb)
1199+ => NP (Aliased (Expression commons schemas params grp from)) elems
1200+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12011201jsonbBuildObject
12021202 = unsafeFunction "jsonb_build_object"
12031203 . UnsafeExpression
@@ -1210,8 +1210,8 @@ jsonbBuildObject
12101210-- array has exactly two elements, which are taken as a key/value pair.
12111211jsonObject
12121212 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1213− => Expression db params grp from (nullity arr)
1214− -> Expression db params grp from (nullity 'PGjson)
1213+ => Expression commons schemas params grp from (nullity arr)
1214+ -> Expression commons schemas params grp from (nullity 'PGjson)
12151215jsonObject = unsafeFunction "json_object"
12161216
12171217-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1220,8 +1220,8 @@ jsonObject = unsafeFunction "json_object"
12201220-- array has exactly two elements, which are taken as a key/value pair.
12211221jsonbObject
12221222 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1223− => Expression db params grp from (nullity arr)
1224− -> Expression db params grp from (nullity 'PGjsonb)
1223+ => Expression commons schemas params grp from (nullity arr)
1224+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12251225jsonbObject = unsafeFunction "jsonb_object"
12261226
12271227-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1229,9 +1229,9 @@ jsonbObject = unsafeFunction "jsonb_object"
12291229jsonZipObject
12301230 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
12311231 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1232− => Expression db params grp from (nullity keysArray)
1233− -> Expression db params grp from (nullity valuesArray)
1234− -> Expression db params grp from (nullity 'PGjson)
1232+ => Expression commons schemas params grp from (nullity keysArray)
1233+ -> Expression commons schemas params grp from (nullity valuesArray)
1234+ -> Expression commons schemas params grp from (nullity 'PGjson)
12351235jsonZipObject ks vs =
12361236 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
12371237
@@ -1241,9 +1241,9 @@ jsonZipObject ks vs =
12411241jsonbZipObject
12421242 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
12431243 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1244− => Expression db params grp from (nullity keysArray)
1245− -> Expression db params grp from (nullity valuesArray)
1246− -> Expression db params grp from (nullity 'PGjsonb)
1244+ => Expression commons schemas params grp from (nullity keysArray)
1245+ -> Expression commons schemas params grp from (nullity valuesArray)
1246+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12471247jsonbZipObject ks vs =
12481248 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
12491249
@@ -1253,23 +1253,23 @@ Table 9.46: JSON processing functions
12531253
12541254-- | Returns the number of elements in the outermost JSON array.
12551255jsonArrayLength
1256− :: Expression db params grp from (nullity 'PGjson)
1257− -> Expression db params grp from (nullity 'PGint4)
1256+ :: Expression commons schemas params grp from (nullity 'PGjson)
1257+ -> Expression commons schemas params grp from (nullity 'PGint4)
12581258jsonArrayLength = unsafeFunction "json_array_length"
12591259
12601260-- | Returns the number of elements in the outermost binary JSON array.
12611261jsonbArrayLength
1262− :: Expression db params grp from (nullity 'PGjsonb)
1263− -> Expression db params grp from (nullity 'PGint4)
1262+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1263+ -> Expression commons schemas params grp from (nullity 'PGint4)
12641264jsonbArrayLength = unsafeFunction "jsonb_array_length"
12651265
12661266-- | Returns JSON value pointed to by the given path (equivalent to #>
12671267-- operator).
12681268jsonExtractPath
12691269 :: SListI elems
1270− => Expression db params grp from (nullity 'PGjson)
1271− -> NP (Expression db params grp from) elems
1272− -> Expression db params grp from (nullity 'PGjsonb)
1270+ => Expression commons schemas params grp from (nullity 'PGjson)
1271+ -> NP (Expression commons schemas params grp from) elems
1272+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12731273jsonExtractPath x xs =
12741274 unsafeVariadicFunction "json_extract_path" (x :* xs)
12751275
@@ -1277,9 +1277,9 @@ jsonExtractPath x xs =
12771277-- operator).
12781278jsonbExtractPath
12791279 :: SListI elems
1280− => Expression db params grp from (nullity 'PGjsonb)
1281− -> NP (Expression db params grp from) elems
1282− -> Expression db params grp from (nullity 'PGjsonb)
1280+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1281+ -> NP (Expression commons schemas params grp from) elems
1282+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12831283jsonbExtractPath x xs =
12841284 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
12851285
@@ -1287,9 +1287,9 @@ jsonbExtractPath x xs =
12871287-- operator), as text.
12881288jsonExtractPathAsText
12891289 :: SListI elems
1290− => Expression db params grp from (nullity 'PGjson)
1291− -> NP (Expression db params grp from) elems
1292− -> Expression db params grp from (nullity 'PGjson)
1290+ => Expression commons schemas params grp from (nullity 'PGjson)
1291+ -> NP (Expression commons schemas params grp from) elems
1292+ -> Expression commons schemas params grp from (nullity 'PGjson)
12931293jsonExtractPathAsText x xs =
12941294 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
12951295
@@ -1297,38 +1297,38 @@ jsonExtractPathAsText x xs =
12971297-- operator), as text.
12981298jsonbExtractPathAsText
12991299 :: SListI elems
1300− => Expression db params grp from (nullity 'PGjsonb)
1301− -> NP (Expression db params grp from) elems
1302− -> Expression db params grp from (nullity 'PGjsonb)
1300+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1301+ -> NP (Expression commons schemas params grp from) elems
1302+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13031303jsonbExtractPathAsText x xs =
13041304 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
13051305
13061306-- | Returns the type of the outermost JSON value as a text string. Possible
13071307-- types are object, array, string, number, boolean, and null.
13081308jsonTypeof
1309− :: Expression db params grp from (nullity 'PGjson)
1310− -> Expression db params grp from (nullity 'PGtext)
1309+ :: Expression commons schemas params grp from (nullity 'PGjson)
1310+ -> Expression commons schemas params grp from (nullity 'PGtext)
13111311jsonTypeof = unsafeFunction "json_typeof"
13121312
13131313-- | Returns the type of the outermost binary JSON value as a text string.
13141314-- Possible types are object, array, string, number, boolean, and null.
13151315jsonbTypeof
1316− :: Expression db params grp from (nullity 'PGjsonb)
1317− -> Expression db params grp from (nullity 'PGtext)
1316+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1317+ -> Expression commons schemas params grp from (nullity 'PGtext)
13181318jsonbTypeof = unsafeFunction "jsonb_typeof"
13191319
13201320-- | Returns its argument with all object fields that have null values omitted.
13211321-- Other null values are untouched.
13221322jsonStripNulls
1323− :: Expression db params grp from (nullity 'PGjson)
1324− -> Expression db params grp from (nullity 'PGjson)
1323+ :: Expression commons schemas params grp from (nullity 'PGjson)
1324+ -> Expression commons schemas params grp from (nullity 'PGjson)
13251325jsonStripNulls = unsafeFunction "json_strip_nulls"
13261326
13271327-- | Returns its argument with all object fields that have null values omitted.
13281328-- Other null values are untouched.
13291329jsonbStripNulls
1330− :: Expression db params grp from (nullity 'PGjsonb)
1331− -> Expression db params grp from (nullity 'PGjsonb)
1330+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1331+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13321332jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13331333
13341334-- | @ jsonbSet target path new_value create_missing @
@@ -1340,11 +1340,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13401340-- arrays.
13411341jsonbSet
13421342 :: PGTextArray "jsonbSet" arr
1343− => Expression db params grp from (nullity 'PGjsonb)
1344− -> Expression db params grp from (nullity arr)
1345− -> Expression db params grp from (nullity 'PGjsonb)
1346− -> Maybe (Expression db params grp from (nullity 'PGbool))
1347− -> Expression db params grp from (nullity 'PGjsonb)
1343+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1344+ -> Expression commons schemas params grp from (nullity arr)
1345+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1346+ -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1347+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13481348jsonbSet tgt path val createMissing = case createMissing of
13491349 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
13501350 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1359,19 +1359,19 @@ jsonbSet tgt path val createMissing = case createMissing of
13591359-- in path count from the end of JSON arrays.
13601360jsonbInsert
13611361 :: PGTextArray "jsonbInsert" arr
1362− => Expression db params grp from (nullity 'PGjsonb)
1363− -> Expression db params grp from (nullity arr)
1364− -> Expression db params grp from (nullity 'PGjsonb)
1365− -> Maybe (Expression db params grp from (nullity 'PGbool))
1366− -> Expression db params grp from (nullity 'PGjsonb)
1362+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1363+ -> Expression commons schemas params grp from (nullity arr)
1364+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1365+ -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1366+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13671367jsonbInsert tgt path val insertAfter = case insertAfter of
13681368 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
13691369 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
13701370
13711371-- | Returns its argument as indented JSON text.
13721372jsonbPretty
1373− :: Expression db params grp from (nullity 'PGjsonb)
1374− -> Expression db params grp from (nullity 'PGtext)
1373+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1374+ -> Expression commons schemas params grp from (nullity 'PGtext)
13751375jsonbPretty = unsafeFunction "jsonb_pretty"
13761376
13771377{-----------------------------------------
@@ -1381,54 +1381,54 @@ aggregation
13811381-- | escape hatch to define aggregate functions
13821382unsafeAggregate
13831383 :: ByteString -- ^ aggregate function
1384− -> Expression db from 'Ungrouped params (xty)
1385− -> Expression db from ('Grouped bys) params (yty)
1384+ -> Expression commons schemas from 'Ungrouped params (xty)
1385+ -> Expression commons schemas from ('Grouped bys) params (yty)
13861386unsafeAggregate fun x = UnsafeExpression $ mconcat
13871387 [fun, "(", renderSQL x, ")"]
13881388
13891389-- | escape hatch to define aggregate functions over distinct values
13901390unsafeAggregateDistinct
13911391 :: ByteString -- ^ aggregate function
1392− -> Expression db from 'Ungrouped params (xty)
1393− -> Expression db from ('Grouped bys) params (yty)
1392+ -> Expression commons schemas from 'Ungrouped params (xty)
1393+ -> Expression commons schemas from ('Grouped bys) params (yty)
13941394unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
13951395 [fun, "(DISTINCT ", renderSQL x, ")"]
13961396
13971397-- | >>> :{
13981398-- let
1399−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1399+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
14001400-- expression = sum_ #col
14011401-- in printSQL expression
14021402-- :}
14031403-- sum("col")
14041404sum_
14051405 :: ty `In` PGNum
1406− => Expression db from 'Ungrouped params (nullity ty)
1406+ => Expression commons schemas from 'Ungrouped params (nullity ty)
14071407 -- ^ what to sum
1408− -> Expression db from ('Grouped bys) params (nullity ty)
1408+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
14091409sum_ = unsafeAggregate "sum"
14101410
14111411-- | >>> :{
14121412-- let
1413−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
1413+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
14141414-- expression = sumDistinct #col
14151415-- in printSQL expression
14161416-- :}
14171417-- sum(DISTINCT "col")
14181418sumDistinct
14191419 :: ty `In` PGNum
1420− => Expression db from 'Ungrouped params (nullity ty)
1420+ => Expression commons schemas from 'Ungrouped params (nullity ty)
14211421 -- ^ what to sum
1422− -> Expression db from ('Grouped bys) params (nullity ty)
1422+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
14231423sumDistinct = unsafeAggregateDistinct "sum"
14241424
14251425-- | A constraint for `PGType`s that you can take averages of and the resulting
14261426-- `PGType`.
14271427class PGAvg ty avg | ty -> avg where
14281428 avg, avgDistinct
1429− :: Expression db from 'Ungrouped params (nullity ty)
1429+ :: Expression commons schemas from 'Ungrouped params (nullity ty)
14301430 -- ^ what to average
1431− -> Expression db from ('Grouped bys) params (nullity avg)
1431+ -> Expression commons schemas from ('Grouped bys) params (nullity avg)
14321432 avg = unsafeAggregate "avg"
14331433 avgDistinct = unsafeAggregateDistinct "avg"
14341434instance PGAvg 'PGint2 'PGnumeric
@@ -1441,110 +1441,110 @@ instance PGAvg 'PGinterval 'PGinterval
14411441
14421442-- | >>> :{
14431443-- let
1444−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1444+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14451445-- expression = bitAnd #col
14461446-- in printSQL expression
14471447-- :}
14481448-- bit_and("col")
14491449bitAnd
14501450 :: int `In` PGIntegral
1451− => Expression db from 'Ungrouped params (nullity int)
1451+ => Expression commons schemas from 'Ungrouped params (nullity int)
14521452 -- ^ what to aggregate
1453− -> Expression db from ('Grouped bys) params (nullity int)
1453+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14541454bitAnd = unsafeAggregate "bit_and"
14551455
14561456-- | >>> :{
14571457-- let
1458−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1458+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14591459-- expression = bitOr #col
14601460-- in printSQL expression
14611461-- :}
14621462-- bit_or("col")
14631463bitOr
14641464 :: int `In` PGIntegral
1465− => Expression db from 'Ungrouped params (nullity int)
1465+ => Expression commons schemas from 'Ungrouped params (nullity int)
14661466 -- ^ what to aggregate
1467− -> Expression db from ('Grouped bys) params (nullity int)
1467+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14681468bitOr = unsafeAggregate "bit_or"
14691469
14701470-- | >>> :{
14711471-- let
1472−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1472+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14731473-- expression = bitAndDistinct #col
14741474-- in printSQL expression
14751475-- :}
14761476-- bit_and(DISTINCT "col")
14771477bitAndDistinct
14781478 :: int `In` PGIntegral
1479− => Expression db from 'Ungrouped params (nullity int)
1479+ => Expression commons schemas from 'Ungrouped params (nullity int)
14801480 -- ^ what to aggregate
1481− -> Expression db from ('Grouped bys) params (nullity int)
1481+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14821482bitAndDistinct = unsafeAggregateDistinct "bit_and"
14831483
14841484-- | >>> :{
14851485-- let
1486−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1486+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14871487-- expression = bitOrDistinct #col
14881488-- in printSQL expression
14891489-- :}
14901490-- bit_or(DISTINCT "col")
14911491bitOrDistinct
14921492 :: int `In` PGIntegral
1493− => Expression db from 'Ungrouped params (nullity int)
1493+ => Expression commons schemas from 'Ungrouped params (nullity int)
14941494 -- ^ what to aggregate
1495− -> Expression db from ('Grouped bys) params (nullity int)
1495+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14961496bitOrDistinct = unsafeAggregateDistinct "bit_or"
14971497
14981498-- | >>> :{
14991499-- let
1500−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1500+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15011501-- expression = boolAnd #col
15021502-- in printSQL expression
15031503-- :}
15041504-- bool_and("col")
15051505boolAnd
1506− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1506+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15071507 -- ^ what to aggregate
1508− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1508+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15091509boolAnd = unsafeAggregate "bool_and"
15101510
15111511-- | >>> :{
15121512-- let
1513−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1513+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15141514-- expression = boolOr #col
15151515-- in printSQL expression
15161516-- :}
15171517-- bool_or("col")
15181518boolOr
1519− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1519+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15201520 -- ^ what to aggregate
1521− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1521+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15221522boolOr = unsafeAggregate "bool_or"
15231523
15241524-- | >>> :{
15251525-- let
1526−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1526+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15271527-- expression = boolAndDistinct #col
15281528-- in printSQL expression
15291529-- :}
15301530-- bool_and(DISTINCT "col")
15311531boolAndDistinct
1532− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1532+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15331533 -- ^ what to aggregate
1534− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1534+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15351535boolAndDistinct = unsafeAggregateDistinct "bool_and"
15361536
15371537-- | >>> :{
15381538-- let
1539−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1539+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15401540-- expression = boolOrDistinct #col
15411541-- in printSQL expression
15421542-- :}
15431543-- bool_or(DISTINCT "col")
15441544boolOrDistinct
1545− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1545+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15461546 -- ^ what to aggregate
1547− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1547+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15481548boolOrDistinct = unsafeAggregateDistinct "bool_or"
15491549
15501550-- | A special aggregation that does not require an input
@@ -1552,70 +1552,70 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
15521552-- >>> printSQL countStar
15531553-- count(*)
15541554countStar
1555− :: Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1555+ :: Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
15561556countStar = UnsafeExpression $ "count(*)"
15571557
15581558-- | >>> :{
15591559-- let
1560−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1560+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
15611561-- expression = count #col
15621562-- in printSQL expression
15631563-- :}
15641564-- count("col")
15651565count
1566− :: Expression db from 'Ungrouped params ty
1566+ :: Expression commons schemas from 'Ungrouped params ty
15671567 -- ^ what to count
1568− -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1568+ -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
15691569count = unsafeAggregate "count"
15701570
15711571-- | >>> :{
15721572-- let
1573−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1573+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
15741574-- expression = countDistinct #col
15751575-- in printSQL expression
15761576-- :}
15771577-- count(DISTINCT "col")
15781578countDistinct
1579− :: Expression db from 'Ungrouped params ty
1579+ :: Expression commons schemas from 'Ungrouped params ty
15801580 -- ^ what to count
1581− -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1581+ -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
15821582countDistinct = unsafeAggregateDistinct "count"
15831583
15841584-- | synonym for `boolAnd`
15851585--
15861586-- >>> :{
15871587-- let
1588−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1588+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15891589-- expression = every #col
15901590-- in printSQL expression
15911591-- :}
15921592-- every("col")
15931593every
1594− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1594+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15951595 -- ^ what to aggregate
1596− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1596+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15971597every = unsafeAggregate "every"
15981598
15991599-- | synonym for `boolAndDistinct`
16001600--
16011601-- >>> :{
16021602-- let
1603−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1603+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
16041604-- expression = everyDistinct #col
16051605-- in printSQL expression
16061606-- :}
16071607-- every(DISTINCT "col")
16081608everyDistinct
1609− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1609+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
16101610 -- ^ what to aggregate
1611− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1611+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
16121612everyDistinct = unsafeAggregateDistinct "every"
16131613
16141614-- | minimum and maximum aggregation
16151615max_, min_, maxDistinct, minDistinct
1616− :: Expression db from 'Ungrouped params (nullity ty)
1616+ :: Expression commons schemas from 'Ungrouped params (nullity ty)
16171617 -- ^ what to aggregate
1618− -> Expression db from ('Grouped bys) params (nullity ty)
1618+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
16191619max_ = unsafeAggregate "max"
16201620min_ = unsafeAggregate "min"
16211621maxDistinct = unsafeAggregateDistinct "max"
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+98−93
@@ -21,6 +21,7 @@ Squeal data manipulation language.
2121 , RankNTypes
2222 , ScopedTypeVariables
2323 , TypeApplications
24+ , TypeFamilies
2425 , TypeInType
2526 , TypeOperators
2627 , UndecidableInstances
@@ -29,6 +30,7 @@ Squeal data manipulation language.
2930module Squeal.PostgreSQL.Manipulation
3031 ( -- * Manipulation
3132 Manipulation (..)
33+ , Manipulation_
3234 , queryStatement
3335 , QueryClause (..)
3436 , pattern Values_
@@ -54,6 +56,7 @@ module Squeal.PostgreSQL.Manipulation
5456
5557import Control.DeepSeq
5658import Data.ByteString hiding (foldr)
59+import Data.Kind (Type)
5760import GHC.TypeLits (KnownSymbol)
5861
5962import qualified Generics.SOP as SOP
@@ -75,7 +78,7 @@ simple insert:
7578>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
7679>>> :{
7780let
78− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
81+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
7982 manipulation =
8083 insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
8184in printSQL manipulation
@@ -88,7 +91,7 @@ parameterized insert:
8891>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
8992>>> :{
9093let
91− manipulation :: Manipulation (DBof (Public Schema)) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
94+ manipulation :: Manipulation '[] (Public Schema) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
9295 manipulation =
9396 insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
9497in printSQL manipulation
@@ -99,7 +102,7 @@ returning insert:
99102
100103>>> :{
101104let
102− manipulation :: Manipulation (DBof (Public Schema)) '[] '["fromOnly" ::: 'NotNull 'PGint4]
105+ manipulation :: Manipulation '[] (Public Schema) '[] '["fromOnly" ::: 'NotNull 'PGint4]
103106 manipulation =
104107 insertInto #tab (Values_ (2 `as` #col1 :* 3 `as` #col2))
105108 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
@@ -114,7 +117,7 @@ upsert:
114117>>> type CustomersSchema = '["customers" ::: 'Table (CustomersConstraints :=> CustomersColumns)]
115118>>> :{
116119let
117− manipulation :: Manipulation (DBof (Public CustomersSchema)) '[] '[]
120+ manipulation :: Manipulation '[] (Public CustomersSchema) '[] '[]
118121 manipulation =
119122 insertInto #customers
120123 (Values_ ("John Smith" `as` #name :* "john@smith.com" `as` #email))
@@ -129,7 +132,7 @@ query insert:
129132
130133>>> :{
131134let
132− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
135+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
133136 manipulation = insertInto_ #tab (Subquery (select Star (from (table #tab))))
134137in printSQL manipulation
135138:}
@@ -139,7 +142,7 @@ update:
139142
140143>>> :{
141144let
142− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
145+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
143146 manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
144147in printSQL manipulation
145148:}
@@ -149,7 +152,7 @@ delete:
149152
150153>>> :{
151154let
152− manipulation :: Manipulation (DBof (Public Schema)) '[]
155+ manipulation :: Manipulation '[] (Public Schema) '[]
153156 '[ "col1" ::: 'NotNull 'PGint4
154157 , "col2" ::: 'NotNull 'PGint4 ]
155158 manipulation = deleteFrom #tab NoUsing (#col1 .== #col2) (Returning Star)
@@ -168,7 +171,7 @@ type Schema3 =
168171
169172>>> :{
170173let
171− manipulation :: Manipulation (DBof (Public Schema3)) '[] '[]
174+ manipulation :: Manipulation '[] (Public Schema3) '[] '[]
172175 manipulation =
173176 deleteFrom_ #tab (Using (table #other_tab & also (table #third_tab)))
174177 ( (#tab ! #col2 .== #other_tab ! #col2)
@@ -183,7 +186,7 @@ with manipulation:
183186>>> type ProductsSchema = '["products" ::: 'Table ('[] :=> ProductsColumns), "products_deleted" ::: 'Table ('[] :=> ProductsColumns)]
184187>>> :{
185188let
186− manipulation :: Manipulation (DBof (Public ProductsSchema)) '[ 'NotNull 'PGdate] '[]
189+ manipulation :: Manipulation '[] (Public ProductsSchema) '[ 'NotNull 'PGdate] '[]
187190 manipulation = with
188191 (deleteFrom #products NoUsing (#date .< param @1) (Returning Star) `as` #del)
189192 (insertInto_ #products_deleted (Subquery (select Star (from (common #del)))))
@@ -193,12 +196,13 @@ WITH "del" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RETURNING *)
193196-}
194197
195198newtype Manipulation
196− (db :: DBType)
199+ (commons :: FromType)
200+ (schemas :: SchemasType)
197201 (params :: [NullityType])
198202 (columns :: RowType)
199203 = UnsafeManipulation { renderManipulation :: ByteString }
200204 deriving (GHC.Generic,Show,Eq,Ord,NFData)
201−instance RenderSQL (Manipulation db params columns) where
205+instance RenderSQL (Manipulation commons schemas params columns) where
202206 renderSQL = renderManipulation
203207instance With Manipulation where
204208 with Done manip = manip
@@ -206,10 +210,13 @@ instance With Manipulation where
206210 "WITH" <+> renderCommonTableExpressions renderSQL cte ctes
207211 <+> renderSQL manip
208212
213+type family Manipulation_ (schemas :: SchemasType) (params :: Type) (row :: Type) where
214+ Manipulation_ schemas params row = Manipulation '[] schemas (TuplePG params) (RowPG row)
215+
209216-- | Convert a `Query` into a `Manipulation`.
210217queryStatement
211− :: Query db params columns
212− -> Manipulation db params columns
218+ :: Query commons schemas params columns
219+ -> Manipulation commons schemas params columns
213220queryStatement q = UnsafeManipulation $ renderSQL q
214221
215222{-----------------------------------------
@@ -224,18 +231,17 @@ more than one row, but there is no way to insert less than one row.
224231Even if you know only some column values, a complete row must be created.
225232-}
226233insertInto
227− :: ( db ~ (commons :=> schemas)
228− , Has sch schemas schema
234+ :: ( Has sch schemas schema
229235 , Has tab schema ('Table table)
230236 , columns ~ TableToColumns table
231237 , row0 ~ TableToRow table
232238 , SOP.SListI columns
233239 , SOP.SListI row1 )
234240 => QualifiedAlias sch tab
235− -> QueryClause db params columns
236− -> ConflictClause tab db params table
237− -> ReturningClause db params '[tab ::: row0] row1
238− -> Manipulation db params row1
241+ -> QueryClause commons schemas params columns
242+ -> ConflictClause tab commons schemas params table
243+ -> ReturningClause commons schemas params '[tab ::: row0] row1
244+ -> Manipulation commons schemas params row1
239245insertInto tab qry conflict ret = UnsafeManipulation $
240246 "INSERT" <+> "INTO" <+> renderSQL tab
241247 <+> renderSQL qry
@@ -243,35 +249,34 @@ insertInto tab qry conflict ret = UnsafeManipulation $
243249 <> renderSQL ret
244250
245251insertInto_
246− :: ( db ~ (commons :=> schemas)
247− , Has sch schemas schema
252+ :: ( Has sch schemas schema
248253 , Has tab schema ('Table table)
249254 , columns ~ TableToColumns table
250255 , row ~ TableToRow table
251256 , SOP.SListI columns )
252257 => QualifiedAlias sch tab
253− -> QueryClause db params columns
254− -> Manipulation db params '[]
258+ -> QueryClause commons schemas params columns
259+ -> Manipulation commons schemas params '[]
255260insertInto_ tab qry =
256261 insertInto tab qry OnConflictDoRaise (Returning_ Nil)
257262
258−data QueryClause db params columns where
263+data QueryClause commons schemas params columns where
259264 Values
260265 :: SOP.SListI columns
261− => NP (ColumnExpression db params 'Ungrouped '[]) columns
262− -> [NP (ColumnExpression db params 'Ungrouped '[]) columns]
263− -> QueryClause db params columns
266+ => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
267+ -> [NP (ColumnExpression schemas params 'Ungrouped '[]) columns]
268+ -> QueryClause commons schemas params columns
264269 Select
265270 :: SOP.SListI columns
266− => NP (ColumnExpression db params grp from) columns
267− -> TableExpression db params grp from
268− -> QueryClause db params columns
271+ => NP (ColumnExpression schemas params grp from) columns
272+ -> TableExpression commons schemas params grp from
273+ -> QueryClause commons schemas params columns
269274 Subquery
270275 :: ColumnsToRow columns ~ row
271− => Query db params row
272− -> QueryClause db params columns
276+ => Query commons schemas params row
277+ -> QueryClause commons schemas params columns
273278
274−instance RenderSQL (QueryClause db params columns) where
279+instance RenderSQL (QueryClause commons schemas params columns) where
275280 renderSQL = \case
276281 Values row0 rows ->
277282 parenthesized (renderCommaSeparated renderSQLPart row0)
@@ -287,7 +292,7 @@ instance RenderSQL (QueryClause db params columns) where
287292 Subquery qry -> renderQuery qry
288293 where
289294 renderSQLPartMaybe, renderValuePartMaybe
290− :: ColumnExpression db params grp from column -> Maybe ByteString
295+ :: ColumnExpression schemas params grp from column -> Maybe ByteString
291296 renderSQLPartMaybe = \case
292297 DefaultAs _ -> Nothing
293298 Specific (_ `As` name) -> Just $ renderSQL name
@@ -295,7 +300,7 @@ instance RenderSQL (QueryClause db params columns) where
295300 DefaultAs _ -> Nothing
296301 Specific (value `As` _) -> Just $ renderExpression value
297302 renderSQLPart, renderValuePart
298− :: ColumnExpression db params grp from column -> ByteString
303+ :: ColumnExpression schemas params grp from column -> ByteString
299304 renderSQLPart = \case
300305 DefaultAs name -> renderSQL name
301306 Specific (_ `As` name) -> renderSQL name
@@ -305,49 +310,49 @@ instance RenderSQL (QueryClause db params columns) where
305310
306311pattern Values_
307312 :: SOP.SListI columns
308− => NP (ColumnExpression db params 'Ungrouped '[]) columns
309− -> QueryClause db params columns
313+ => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
314+ -> QueryClause commons schemas params columns
310315pattern Values_ vals = Values vals []
311316
312−data ColumnExpression db params grp from column where
317+data ColumnExpression schemas params grp from column where
313318 DefaultAs
314319 :: KnownSymbol col
315320 => Alias col
316− -> ColumnExpression db params grp from (col ::: 'Def :=> ty)
321+ -> ColumnExpression schemas params grp from (col ::: 'Def :=> ty)
317322 Specific
318− :: Aliased (Expression db params grp from) (col ::: ty)
319− -> ColumnExpression db params grp from (col ::: defness :=> ty)
323+ :: Aliased (Expression '[] schemas params grp from) (col ::: ty)
324+ -> ColumnExpression schemas params grp from (col ::: defness :=> ty)
320325
321326instance (KnownSymbol col, column ~ (col ::: defness :=> ty))
322327 => Aliasable col
323− (Expression db params grp from ty)
324− (ColumnExpression db params grp from column) where
328+ (Expression '[] schemas params grp from ty)
329+ (ColumnExpression schemas params grp from column) where
325330 expression `as` col = Specific (expression `As` col)
326331instance (KnownSymbol col, columns ~ '[col ::: defness :=> ty])
327332 => Aliasable col
328− (Expression db params grp from ty)
329− (NP (ColumnExpression db params grp from) columns) where
333+ (Expression '[] schemas params grp from ty)
334+ (NP (ColumnExpression schemas params grp from) columns) where
330335 expression `as` col = expression `as` col :* Nil
331336instance (KnownSymbol col, column ~ (col ::: 'Def :=> ty))
332− => DefaultAliasable col (ColumnExpression db params grp from column) where
337+ => DefaultAliasable col (ColumnExpression schemas params grp from column) where
333338 defaultAs = DefaultAs
334339instance (KnownSymbol col, columns ~ '[col ::: 'Def :=> ty])
335− => DefaultAliasable col (NP (ColumnExpression db params grp from) columns) where
340+ => DefaultAliasable col (NP (ColumnExpression schemas params grp from) columns) where
336341 defaultAs col = defaultAs col :* Nil
337342
338343instance (HasUnique tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
339− => IsLabel col (ColumnExpression db params 'Ungrouped from column) where
344+ => IsLabel col (ColumnExpression schemas params 'Ungrouped from column) where
340345 fromLabel = fromLabel @col `as` Alias
341346instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
342347 => IsLabel col
343− (NP (ColumnExpression db params 'Ungrouped from) columns) where
348+ (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
344349 fromLabel = fromLabel @col `as` Alias
345350
346351instance (Has tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
347− => IsQualified tab col (ColumnExpression db params 'Ungrouped from column) where
352+ => IsQualified tab col (ColumnExpression schemas params 'Ungrouped from column) where
348353 tab ! col = tab ! col `as` col
349354instance (Has tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
350− => IsQualified tab col (NP (ColumnExpression db params 'Ungrouped from) columns) where
355+ => IsQualified tab col (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
351356 tab ! col = tab ! col `as` col
352357
353358instance
@@ -356,7 +361,7 @@ instance
356361 , GroupedBy tab col bys
357362 , column ~ (col ::: defness :=> ty)
358363 ) => IsLabel col
359− (ColumnExpression db params ('Grouped bys) from column) where
364+ (ColumnExpression schemas params ('Grouped bys) from column) where
360365 fromLabel = fromLabel @col `as` Alias
361366instance
362367 ( HasUnique tab from row
@@ -364,7 +369,7 @@ instance
364369 , GroupedBy tab col bys
365370 , columns ~ '[col ::: defness :=> ty]
366371 ) => IsLabel col
367− (NP (ColumnExpression db params ('Grouped bys) from) columns) where
372+ (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
368373 fromLabel = fromLabel @col `as` Alias
369374
370375instance
@@ -373,7 +378,7 @@ instance
373378 , GroupedBy tab col bys
374379 , column ~ (col ::: defness :=> ty)
375380 ) => IsQualified tab col
376− (ColumnExpression db params ('Grouped bys) from column) where
381+ (ColumnExpression schemas params ('Grouped bys) from column) where
377382 tab ! col = tab ! col `as` col
378383instance
379384 ( Has tab from row
@@ -381,10 +386,10 @@ instance
381386 , GroupedBy tab col bys
382387 , columns ~ '[col ::: defness :=> ty]
383388 ) => IsQualified tab col
384− (NP (ColumnExpression db params ('Grouped bys) from) columns) where
389+ (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
385390 tab ! col = tab ! col :* Nil
386391
387−instance RenderSQL (ColumnExpression db params grp from column) where
392+instance RenderSQL (ColumnExpression schemas params grp from column) where
388393 renderSQL = \case
389394 DefaultAs col ->
390395 renderSQL col <+> "=" <+> "DEFAULT"
@@ -401,18 +406,18 @@ instance RenderSQL (ColumnExpression db params grp from column) where
401406-- the row will not be returned. `ReturningStar` will return all columns
402407-- in the row. Use @Returning Nil@ in the common case where no return
403408-- values are desired.
404−newtype ReturningClause db params from row =
405− Returning (Selection db params 'Ungrouped from row)
409+newtype ReturningClause commons schemas params from row =
410+ Returning (Selection commons schemas params 'Ungrouped from row)
406411
407−instance RenderSQL (ReturningClause db params from row) where
412+instance RenderSQL (ReturningClause commons schemas params from row) where
408413 renderSQL = \case
409414 Returning (List Nil) -> ""
410415 Returning selection -> " RETURNING" <+> renderSQL selection
411416
412417pattern Returning_
413418 :: SOP.SListI row
414− => NP (Aliased (Expression db params 'Ungrouped from)) row
415− -> ReturningClause db params from row
419+ => NP (Aliased (Expression commons schemas params 'Ungrouped from)) row
420+ -> ReturningClause commons schemas params from row
416421pattern Returning_ list = Returning (List list)
417422
418423-- | A `ConflictClause` specifies an action to perform upon a constraint
@@ -420,34 +425,34 @@ pattern Returning_ list = Returning (List list)
420425-- `OnConflictDoNothing` simply avoids inserting a row.
421426-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
422427-- proposed for insertion.
423−data ConflictClause tab db params table where
424− OnConflictDoRaise :: ConflictClause tab db params table
428+data ConflictClause tab commons schemas params table where
429+ OnConflictDoRaise :: ConflictClause tab commons schemas params table
425430 OnConflict
426431 :: ConflictTarget constraints
427− -> ConflictAction tab db params columns
428− -> ConflictClause tab db params (constraints :=> columns)
432+ -> ConflictAction tab commons schemas params columns
433+ -> ConflictClause tab commons schemas params (constraints :=> columns)
429434
430435-- | Render a `ConflictClause`.
431436instance SOP.SListI (TableToColumns table)
432− => RenderSQL (ConflictClause tab db params table) where
437+ => RenderSQL (ConflictClause tab commons schemas params table) where
433438 renderSQL = \case
434439 OnConflictDoRaise -> ""
435440 OnConflict target action -> " ON CONFLICT"
436441 <+> renderSQL target <+> renderSQL action
437442
438−data ConflictAction tab db params columns where
439− DoNothing :: ConflictAction tab db params columns
443+data ConflictAction tab commons schemas params columns where
444+ DoNothing :: ConflictAction tab commons schemas params columns
440445 DoUpdate
441446 :: ( row ~ ColumnsToRow columns
442447 , SOP.SListI columns
443448 , columns ~ (col0 ': cols)
444449 , SOP.All (HasIn columns) subcolumns
445450 , AllUnique subcolumns )
446− => NP (ColumnExpression db params 'Ungrouped '[tab ::: row, "excluded" ::: row]) subcolumns
447− -> [Condition db params 'Ungrouped '[tab ::: row, "excluded" ::: row]]
448− -> ConflictAction tab db params columns
451+ => NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]) subcolumns
452+ -> [Condition commons schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]]
453+ -> ConflictAction tab commons schemas params columns
449454
450−instance RenderSQL (ConflictAction tab db params columns) where
455+instance RenderSQL (ConflictAction tab commons schemas params columns) where
451456 renderSQL = \case
452457 DoNothing -> "DO NOTHING"
453458 DoUpdate updates whs'
@@ -487,12 +492,12 @@ update
487492 , SOP.All (HasIn columns) subcolumns
488493 , AllUnique subcolumns )
489494 => QualifiedAlias sch tab -- ^ table to update
490− -> NP (ColumnExpression db params 'Ungrouped '[tab ::: row0]) subcolumns
495+ -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row0]) subcolumns
491496 -- ^ modified values to replace old values
492− -> Condition db params 'Ungrouped '[tab ::: row0]
497+ -> Condition commons schemas params 'Ungrouped '[tab ::: row0]
493498 -- ^ condition under which to perform update on a row
494− -> ReturningClause db params '[tab ::: row0] row1 -- ^ results to return
495− -> Manipulation db params row1
499+ -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
500+ -> Manipulation commons schemas params row1
496501update tab columns wh returning = UnsafeManipulation $
497502 "UPDATE"
498503 <+> renderSQL tab
@@ -512,22 +517,22 @@ update_
512517 , SOP.All (HasIn columns) subcolumns
513518 , AllUnique subcolumns )
514519 => QualifiedAlias sch tab -- ^ table to update
515− -> NP (ColumnExpression db params 'Ungrouped '[tab ::: row]) subcolumns
520+ -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row]) subcolumns
516521 -- ^ modified values to replace old values
517− -> Condition db params 'Ungrouped '[tab ::: row]
522+ -> Condition commons schemas params 'Ungrouped '[tab ::: row]
518523 -- ^ condition under which to perform update on a row
519− -> Manipulation db params '[]
524+ -> Manipulation commons schemas params '[]
520525update_ tab columns wh = update tab columns wh (Returning_ Nil)
521526
522527{-----------------------------------------
523528DELETE statements
524529-----------------------------------------}
525530
526−data UsingClause db params from where
527− NoUsing :: UsingClause db params '[]
531+data UsingClause commons schemas params from where
532+ NoUsing :: UsingClause commons schemas params '[]
528533 Using
529− :: FromClause db params from
530− -> UsingClause db params from
534+ :: FromClause commons schemas params from
535+ -> UsingClause commons schemas params from
531536
532537-- | Delete rows from a table.
533538deleteFrom
@@ -538,11 +543,11 @@ deleteFrom
538543 , row0 ~ TableToRow table
539544 , columns ~ TableToColumns table )
540545 => QualifiedAlias sch tab -- ^ table to delete from
541− -> UsingClause db params from
542− -> Condition db params 'Ungrouped (tab ::: row0 ': from)
546+ -> UsingClause commons schemas params from
547+ -> Condition commons schemas params 'Ungrouped (tab ::: row0 ': from)
543548 -- ^ condition under which to delete a row
544− -> ReturningClause db params '[tab ::: row0] row1 -- ^ results to return
545− -> Manipulation db params row1
549+ -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
550+ -> Manipulation commons schemas params row1
546551deleteFrom tab using wh returning = UnsafeManipulation $
547552 "DELETE FROM"
548553 <+> renderSQL tab
@@ -560,10 +565,10 @@ deleteFrom_
560565 , row ~ TableToRow table
561566 , columns ~ TableToColumns table )
562567 => QualifiedAlias sch tab -- ^ table to delete from
563− -> UsingClause db params from
564− -> Condition db params 'Ungrouped (tab ::: row ': from)
568+ -> UsingClause commons schemas params from
569+ -> Condition commons schemas params 'Ungrouped (tab ::: row ': from)
565570 -- ^ condition under which to delete a row
566− -> Manipulation db params '[]
571+ -> Manipulation commons schemas params '[]
567572deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
568573
569574-- | This has the behaviour of a cartesian product, taking all
@@ -572,10 +577,10 @@ deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
572577-- a comma separated list of tables. Typical case is the `USING` clause
573578-- of a DELETE query.
574579also
575− :: FromClause schema params right
580+ :: FromClause commons schemas params right
576581 -- ^ right
577− -> FromClause schema params left
582+ -> FromClause commons schemas params left
578583 -- ^ left
579− -> FromClause schema params (Join left right)
584+ -> FromClause commons schemas params (Join left right)
580585also right left = UnsafeFromClause $
581586 renderSQL left <> "," <+> renderSQL right
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+3−3
@@ -275,21 +275,21 @@ createMigrations =
275275-- | Inserts a `Migration` into the `MigrationsTable`
276276insertMigration
277277 :: Has "migrations" schemas MigrationsSchema
278− => Manipulation ('[] :=> schemas) '[ 'NotNull 'PGtext] '[]
278+ => Manipulation '[] schemas '[ 'NotNull 'PGtext] '[]
279279insertMigration = insertInto_ (#migrations ! #schema_migrations) . Values_ $
280280 (param @1) `as` #name :* defaultAs #executed_at
281281
282282-- | Deletes a `Migration` from the `MigrationsTable`
283283deleteMigration
284284 :: Has "migrations" schemas MigrationsSchema
285− => Manipulation ('[] :=> schemas) '[ 'NotNull 'PGtext ] '[]
285+ => Manipulation '[] schemas '[ 'NotNull 'PGtext ] '[]
286286deleteMigration = deleteFrom_ (#migrations ! #schema_migrations) NoUsing (#name .== param @1)
287287
288288-- | Selects a `Migration` from the `MigrationsTable`, returning
289289-- the time at which it was executed.
290290selectMigration
291291 :: Has "migrations" schemas MigrationsSchema
292− => Query ('[] :=> schemas) '[ 'NotNull 'PGtext ]
292+ => Query '[] schemas '[ 'NotNull 'PGtext ]
293293 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
294294selectMigration = select_
295295 (#executed_at `as` #executed_at)
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+14−14
@@ -315,63 +315,63 @@ a default instance.
315315class Monad pq => MonadPQ schemas pq | pq -> schemas where
316316 manipulateParams
317317 :: ToParams x params
318− => Manipulation ('[] :=> schemas) params ys
318+ => Manipulation '[] schemas params ys
319319 -- ^ `insertRows`, `update` or `deleteFrom`
320320 -> x -> pq (K LibPQ.Result ys)
321321 default manipulateParams
322322 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
323323 => ToParams x params
324− => Manipulation ('[] :=> schemas) params ys
324+ => Manipulation '[] schemas params ys
325325 -- ^ `insertRows`, `update` or `deleteFrom`
326326 -> x -> pq (K LibPQ.Result ys)
327327 manipulateParams manipulation params = lift $
328328 manipulateParams manipulation params
329329
330− manipulate :: Manipulation ('[] :=> schemas) '[] ys -> pq (K LibPQ.Result ys)
330+ manipulate :: Manipulation '[] schemas '[] ys -> pq (K LibPQ.Result ys)
331331 manipulate statement = manipulateParams statement ()
332332
333333 runQueryParams
334334 :: ToParams x params
335− => Query ('[] :=> schemas) params ys
335+ => Query '[] schemas params ys
336336 -- ^ `select` and friends
337337 -> x -> pq (K LibPQ.Result ys)
338338 runQueryParams = manipulateParams . queryStatement
339339
340340 runQuery
341− :: Query ('[] :=> schemas) '[] ys
341+ :: Query '[] schemas '[] ys
342342 -- ^ `select` and friends
343343 -> pq (K LibPQ.Result ys)
344344 runQuery q = runQueryParams q ()
345345
346346 traversePrepared
347347 :: (ToParams x params, Traversable list)
348− => Manipulation ('[] :=> schemas) params ys
348+ => Manipulation '[] schemas params ys
349349 -- ^ `insertRows`, `update`, or `deleteFrom`, and friends
350350 -> list x -> pq (list (K LibPQ.Result ys))
351351 default traversePrepared
352352 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
353353 => (ToParams x params, Traversable list)
354− => Manipulation ('[] :=> schemas) params ys -> list x -> pq (list (K LibPQ.Result ys))
354+ => Manipulation '[] schemas params ys -> list x -> pq (list (K LibPQ.Result ys))
355355 traversePrepared manipulation params = lift $
356356 traversePrepared manipulation params
357357
358358 forPrepared
359359 :: (ToParams x params, Traversable list)
360360 => list x
361− -> Manipulation ('[] :=> schemas) params ys
361+ -> Manipulation '[] schemas params ys
362362 -- ^ `insertRows`, `update` or `deleteFrom`
363363 -> pq (list (K LibPQ.Result ys))
364364 forPrepared = flip traversePrepared
365365
366366 traversePrepared_
367367 :: (ToParams x params, Foldable list)
368− => Manipulation ('[] :=> schemas) params '[]
368+ => Manipulation '[] schemas params '[]
369369 -- ^ `insertRows`, `update` or `deleteFrom`
370370 -> list x -> pq ()
371371 default traversePrepared_
372372 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
373373 => (ToParams x params, Foldable list)
374− => Manipulation ('[] :=> schemas) params '[]
374+ => Manipulation '[] schemas params '[]
375375 -- ^ `insertRows`, `update` or `deleteFrom`
376376 -> list x -> pq ()
377377 traversePrepared_ manipulation params = lift $
@@ -380,7 +380,7 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where
380380 forPrepared_
381381 :: (ToParams x params, Foldable list)
382382 => list x
383− -> Manipulation ('[] :=> schemas) params '[]
383+ -> Manipulation '[] schemas params '[]
384384 -- ^ `insertRows`, `update` or `deleteFrom`
385385 -> pq ()
386386 forPrepared_ = flip traversePrepared_
@@ -395,7 +395,7 @@ instance (MonadBase IO io, schemas0 ~ schemas, schemas1 ~ schemas)
395395 => MonadPQ schemas (PQ schemas0 schemas1 io) where
396396
397397 manipulateParams
398− (UnsafeManipulation q :: Manipulation ('[] :=> schemas) ps ys) (params :: x) =
398+ (UnsafeManipulation q :: Manipulation '[] schemas ps ys) (params :: x) =
399399 PQ $ \ (K conn) -> do
400400 let
401401 toParam' encoding =
@@ -411,7 +411,7 @@ instance (MonadBase IO io, schemas0 ~ schemas, schemas1 ~ schemas)
411411 return $ K (K result)
412412
413413 traversePrepared
414− (UnsafeManipulation q :: Manipulation ('[] :=> schemas) xs ys) (list :: list x) =
414+ (UnsafeManipulation q :: Manipulation '[] schemas xs ys) (list :: list x) =
415415 PQ $ \ (K conn) -> liftBase $ do
416416 let temp = "temporary_statement"
417417 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
@@ -438,7 +438,7 @@ instance (MonadBase IO io, schemas0 ~ schemas, schemas1 ~ schemas)
438438 return (K results)
439439
440440 traversePrepared_
441− (UnsafeManipulation q :: Manipulation ('[] :=> schemas) xs '[]) (list :: list x) =
441+ (UnsafeManipulation q :: Manipulation '[] schemas xs '[]) (list :: list x) =
442442 PQ $ \ (K conn) -> liftBase $ do
443443 let temp = "temporary_statement"
444444 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+297−292
@@ -31,6 +31,7 @@ Squeal queries.
3131module Squeal.PostgreSQL.Query
3232 ( -- * Queries
3333 Query (..)
34+ , Query_
3435 -- ** Select
3536 , select
3637 , select_
@@ -124,6 +125,7 @@ module Squeal.PostgreSQL.Query
124125
125126import Control.DeepSeq
126127import Data.ByteString (ByteString)
128+import Data.Kind (Type)
127129import Data.String
128130import Data.Word
129131import Generics.SOP hiding (from)
@@ -145,7 +147,7 @@ simple query:
145147>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
146148>>> :{
147149let
148− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
150+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
149151 query = select Star (from (table #tab))
150152in printSQL query
151153:}
@@ -155,7 +157,7 @@ restricted query:
155157
156158>>> :{
157159let
158− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
160+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
159161 query =
160162 select_ ((#col1 + #col2) `as` #sum :* #col1)
161163 ( from (table #tab)
@@ -169,7 +171,7 @@ subquery:
169171
170172>>> :{
171173let
172− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
174+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
173175 query = select Star (from (subquery (select Star (from (table #tab)) `as` #sub)))
174176in printSQL query
175177:}
@@ -179,7 +181,7 @@ limits and offsets:
179181
180182>>> :{
181183let
182− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
184+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
183185 query = select Star (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
184186in printSQL query
185187:}
@@ -189,7 +191,7 @@ parameterized query:
189191
190192>>> :{
191193let
192− query :: Query (DBof (Public Schema)) '[ 'NotNull 'PGint4] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
194+ query :: Query '[] (Public Schema) '[ 'NotNull 'PGint4] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
193195 query = select Star (from (table #tab) & where_ (#col1 .> param @1))
194196in printSQL query
195197:}
@@ -199,7 +201,7 @@ aggregation query:
199201
200202>>> :{
201203let
202− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
204+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
203205 query =
204206 select_ (sum_ #col2 `as` #sum :* #col1)
205207 ( from (table (#tab `as` #table1))
@@ -213,7 +215,7 @@ sorted query:
213215
214216>>> :{
215217let
216− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
218+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
217219 query = select Star (from (table #tab) & orderBy [#col1 & Asc])
218220in printSQL query
219221:}
@@ -250,7 +252,7 @@ type OrdersSchema =
250252
251253>>> :{
252254let
253− query :: Query (DBof (Public OrdersSchema))
255+ query :: Query '[] (Public OrdersSchema)
254256 '[]
255257 '[ "order_price" ::: 'NotNull 'PGfloat4
256258 , "customer_name" ::: 'NotNull 'PGtext
@@ -273,7 +275,7 @@ self-join:
273275
274276>>> :{
275277let
276− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
278+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
277279 query = select (#t1 & DotStar) (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
278280in printSQL query
279281:}
@@ -283,7 +285,7 @@ value queries:
283285
284286>>> :{
285287let
286− query :: Query db '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
288+ query :: Query commons schemas '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
287289 query = values (1 `as` #foo :* true `as` #bar) [2 `as` #foo :* false `as` #bar]
288290in printSQL query
289291:}
@@ -293,7 +295,7 @@ set operations:
293295
294296>>> :{
295297let
296− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
298+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
297299 query = select Star (from (table #tab)) `unionAll` select Star (from (table #tab))
298300in printSQL query
299301:}
@@ -303,7 +305,7 @@ with queries:
303305
304306>>> :{
305307let
306− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
308+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
307309 query = with (
308310 select Star (from (table #tab)) `as` #cte1 :>>
309311 select Star (from (common #cte1)) `as` #cte2
@@ -313,19 +315,23 @@ in printSQL query
313315WITH "cte1" AS (SELECT * FROM "tab" AS "tab"), "cte2" AS (SELECT * FROM "cte1" AS "cte1") SELECT * FROM "cte2" AS "cte2"
314316-}
315317newtype Query
316− (db :: DBType)
318+ (commons :: FromType)
319+ (schemas :: SchemasType)
317320 (params :: [NullityType])
318− (columns :: RowType)
321+ (row :: RowType)
319322 = UnsafeQuery { renderQuery :: ByteString }
320323 deriving (GHC.Generic,Show,Eq,Ord,NFData)
321−instance RenderSQL (Query db params columns) where renderSQL = renderQuery
324+instance RenderSQL (Query commons schemas params row) where renderSQL = renderQuery
325+
326+type family Query_ (schemas :: SchemasType) (params :: Type) (row :: Type) where
327+ Query_ schemas params row = Query '[] schemas (TuplePG params) (RowPG row)
322328
323329-- | The results of two queries can be combined using the set operation
324330-- `union`. Duplicate rows are eliminated.
325331union
326− :: Query db params columns
327− -> Query db params columns
328− -> Query db params columns
332+ :: Query commons schemas params columns
333+ -> Query commons schemas params columns
334+ -> Query commons schemas params columns
329335q1 `union` q2 = UnsafeQuery $
330336 parenthesized (renderSQL q1)
331337 <+> "UNION"
@@ -334,9 +340,9 @@ q1 `union` q2 = UnsafeQuery $
334340-- | The results of two queries can be combined using the set operation
335341-- `unionAll`, the disjoint union. Duplicate rows are retained.
336342unionAll
337− :: Query db params columns
338− -> Query db params columns
339− -> Query db params columns
343+ :: Query commons schemas params columns
344+ -> Query commons schemas params columns
345+ -> Query commons schemas params columns
340346q1 `unionAll` q2 = UnsafeQuery $
341347 parenthesized (renderSQL q1)
342348 <+> "UNION" <+> "ALL"
@@ -345,9 +351,9 @@ q1 `unionAll` q2 = UnsafeQuery $
345351-- | The results of two queries can be combined using the set operation
346352-- `intersect`, the intersection. Duplicate rows are eliminated.
347353intersect
348− :: Query db params columns
349− -> Query db params columns
350− -> Query db params columns
354+ :: Query commons schemas params columns
355+ -> Query commons schemas params columns
356+ -> Query commons schemas params columns
351357q1 `intersect` q2 = UnsafeQuery $
352358 parenthesized (renderSQL q1)
353359 <+> "INTERSECT"
@@ -356,9 +362,9 @@ q1 `intersect` q2 = UnsafeQuery $
356362-- | The results of two queries can be combined using the set operation
357363-- `intersectAll`, the intersection. Duplicate rows are retained.
358364intersectAll
359− :: Query db params columns
360− -> Query db params columns
361− -> Query db params columns
365+ :: Query commons schemas params columns
366+ -> Query commons schemas params columns
367+ -> Query commons schemas params columns
362368q1 `intersectAll` q2 = UnsafeQuery $
363369 parenthesized (renderSQL q1)
364370 <+> "INTERSECT" <+> "ALL"
@@ -367,9 +373,9 @@ q1 `intersectAll` q2 = UnsafeQuery $
367373-- | The results of two queries can be combined using the set operation
368374-- `except`, the set difference. Duplicate rows are eliminated.
369375except
370− :: Query db params columns
371− -> Query db params columns
372− -> Query db params columns
376+ :: Query commons schemas params columns
377+ -> Query commons schemas params columns
378+ -> Query commons schemas params columns
373379q1 `except` q2 = UnsafeQuery $
374380 parenthesized (renderSQL q1)
375381 <+> "EXCEPT"
@@ -378,9 +384,9 @@ q1 `except` q2 = UnsafeQuery $
378384-- | The results of two queries can be combined using the set operation
379385-- `exceptAll`, the set difference. Duplicate rows are retained.
380386exceptAll
381− :: Query db params columns
382− -> Query db params columns
383− -> Query db params columns
387+ :: Query commons schemas params columns
388+ -> Query commons schemas params columns
389+ -> Query commons schemas params columns
384390q1 `exceptAll` q2 = UnsafeQuery $
385391 parenthesized (renderSQL q1)
386392 <+> "EXCEPT" <+> "ALL"
@@ -390,49 +396,49 @@ q1 `exceptAll` q2 = UnsafeQuery $
390396SELECT queries
391397-----------------------------------------}
392398
393−data Selection db params grp from row where
399+data Selection commons schemas params grp from row where
394400 List
395401 :: SListI row
396− => NP (Aliased (Expression db params grp from)) row
397− -> Selection db params grp from row
402+ => NP (Aliased (Expression commons schemas params grp from)) row
403+ -> Selection commons schemas params grp from row
398404 Star
399405 :: HasUnique tab from row
400− => Selection db params 'Ungrouped from row
406+ => Selection commons schemas params 'Ungrouped from row
401407 DotStar
402408 :: Has tab from row
403409 => Alias tab
404− -> Selection db params 'Ungrouped from row
410+ -> Selection commons schemas params 'Ungrouped from row
405411 Also
406− :: Selection db params grp from right
407− -> Selection db params grp from left
408− -> Selection db params grp from (Join left right)
412+ :: Selection commons schemas params grp from right
413+ -> Selection commons schemas params grp from left
414+ -> Selection commons schemas params grp from (Join left right)
409415instance (KnownSymbol col, row ~ '[col ::: ty])
410416 => Aliasable col
411− (Expression db params grp from ty)
412− (Selection db params grp from row) where
417+ (Expression commons schemas params grp from ty)
418+ (Selection commons schemas params grp from row) where
413419 expr `as` col = List (expr `as` col)
414420instance (Has tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
415− => IsQualified tab col (Selection db params 'Ungrouped from row1) where
421+ => IsQualified tab col (Selection commons schemas params 'Ungrouped from row1) where
416422 tab ! col = tab ! col `as` col
417423instance
418424 ( Has tab from row0
419425 , Has col row0 ty
420426 , row1 ~ '[col ::: ty]
421427 , GroupedBy tab col bys )
422− => IsQualified tab col (Selection db params ('Grouped bys) from row1) where
428+ => IsQualified tab col (Selection commons schemas params ('Grouped bys) from row1) where
423429 tab ! col = tab ! col `as` col
424430instance (HasUnique tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
425− => IsLabel col (Selection db params 'Ungrouped from row1) where
431+ => IsLabel col (Selection commons schemas params 'Ungrouped from row1) where
426432 fromLabel = fromLabel @col `as` Alias
427433instance
428434 ( HasUnique tab from row0
429435 , Has col row0 ty
430436 , row1 ~ '[col ::: ty]
431437 , GroupedBy tab col bys )
432− => IsLabel col (Selection db params ('Grouped bys) from row1) where
438+ => IsLabel col (Selection commons schemas params ('Grouped bys) from row1) where
433439 fromLabel = fromLabel @col `as` Alias
434440
435−instance RenderSQL (Selection db params grp from row) where
441+instance RenderSQL (Selection commons schemas params grp from row) where
436442 renderSQL = \case
437443 List list -> renderCommaSeparated (renderAliased renderSQL) list
438444 Star -> "*"
@@ -446,11 +452,11 @@ instance RenderSQL (Selection db params grp from row) where
446452-- the intermediate table are actually output.
447453select
448454 :: (SListI row, row ~ (x ': xs))
449− => Selection db params grp from row
455+ => Selection commons schemas params grp from row
450456 -- ^ select list
451− -> TableExpression db params grp from
457+ -> TableExpression commons schemas params grp from
452458 -- ^ intermediate virtual table
453− -> Query db params row
459+ -> Query commons schemas params row
454460select selection tabexpr = UnsafeQuery $
455461 "SELECT"
456462 <+> renderSQL selection
@@ -458,20 +464,20 @@ select selection tabexpr = UnsafeQuery $
458464
459465select_
460466 :: (SListI row, row ~ (x ': xs))
461− => NP (Aliased (Expression db params grp from)) row
462− -> TableExpression db params grp from
463− -> Query db params row
467+ => NP (Aliased (Expression commons schemas params grp from)) row
468+ -> TableExpression commons schemas params grp from
469+ -> Query commons schemas params row
464470select_ list = select (List list)
465471
466472-- | After the select list has been processed, the result table can
467473-- be subject to the elimination of duplicate rows using `selectDistinct`.
468474selectDistinct
469475 :: (SListI columns, columns ~ (col ': cols))
470− => Selection db params 'Ungrouped from columns
476+ => Selection commons schemas params 'Ungrouped from columns
471477 -- ^ select list
472− -> TableExpression db params 'Ungrouped from
478+ -> TableExpression commons schemas params 'Ungrouped from
473479 -- ^ intermediate virtual table
474− -> Query db params columns
480+ -> Query commons schemas params columns
475481selectDistinct selection tabexpr = UnsafeQuery $
476482 "SELECT DISTINCT"
477483 <+> renderSQL selection
@@ -479,11 +485,11 @@ selectDistinct selection tabexpr = UnsafeQuery $
479485
480486selectDistinct_
481487 :: (SListI columns, columns ~ (col ': cols))
482− => NP (Aliased (Expression db params 'Ungrouped from)) columns
488+ => NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns
483489 -- ^ select list
484− -> TableExpression db params 'Ungrouped from
490+ -> TableExpression commons schemas params 'Ungrouped from
485491 -- ^ intermediate virtual table
486− -> Query db params columns
492+ -> Query commons schemas params columns
487493selectDistinct_ list = select (List list)
488494
489495-- | `values` computes a row value or set of row values
@@ -492,16 +498,16 @@ selectDistinct_ list = select (List list)
492498-- but it can be used on its own.
493499--
494500-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
495−-- >>> let query = values (1 `as` #a :* "one" `as` #b) [] :: Query db '[] Row
501+-- >>> let query = values (1 `as` #a :* "one" `as` #b) [] :: Query commons schemas '[] Row
496502-- >>> printSQL query
497503-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
498504values
499505 :: SListI cols
500− => NP (Aliased (Expression db params 'Ungrouped '[] )) cols
501− -> [NP (Aliased (Expression db params 'Ungrouped '[] )) cols]
506+ => NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols
507+ -> [NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols]
502508 -- ^ When more than one row is specified, all the rows must
503509 -- must have the same number of elements
504− -> Query db params cols
510+ -> Query commons schemas params cols
505511values rw rws = UnsafeQuery $ "SELECT * FROM"
506512 <+> parenthesized (
507513 "VALUES"
@@ -512,7 +518,7 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
512518 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
513519 where
514520 renderAliasPart, renderValuePart
515− :: Aliased (Expression db params 'Ungrouped '[] ) ty -> ByteString
521+ :: Aliased (Expression commons schemas params 'Ungrouped '[] ) ty -> ByteString
516522 renderAliasPart (_ `As` name) = renderSQL name
517523 renderValuePart (value `As` _) = renderSQL value
518524
@@ -520,9 +526,9 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
520526-- specified by value expressions.
521527values_
522528 :: SListI cols
523− => NP (Aliased (Expression db params 'Ungrouped '[] )) cols
529+ => NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols
524530 -- ^ one row of values
525− -> Query db params cols
531+ -> Query commons schemas params cols
526532values_ rw = values rw []
527533
528534{-----------------------------------------
@@ -536,15 +542,16 @@ Table Expressions
536542-- to a table on disk, a so-called base table, but more complex expressions
537543-- can be used to modify or combine base tables in various ways.
538544data TableExpression
539− (db :: DBType)
545+ (commons :: FromType)
546+ (schemas :: SchemasType)
540547 (params :: [NullityType])
541548 (grp :: Grouping)
542549 (from :: FromType)
543550 = TableExpression
544− { fromClause :: FromClause db params from
551+ { fromClause :: FromClause commons schemas params from
545552 -- ^ A table reference that can be a table name, or a derived table such
546553 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
547− , whereClause :: [Condition db params 'Ungrouped from]
554+ , whereClause :: [Condition commons schemas params 'Ungrouped from]
548555 -- ^ optional search coditions, combined with `.&&`. After the processing
549556 -- of the `fromClause` is done, each row of the derived virtual table
550557 -- is checked against the search condition. If the result of the
@@ -560,13 +567,13 @@ data TableExpression
560567 -- set of rows having common values into one group row that represents all
561568 -- rows in the group. This is done to eliminate redundancy in the output
562569 -- and/or compute aggregates that apply to these groups.
563− , havingClause :: HavingClause db params grp from
570+ , havingClause :: HavingClause commons schemas params grp from
564571 -- ^ If a table has been grouped using `groupBy`, but only certain groups
565572 -- are of interest, the `havingClause` can be used, much like a
566573 -- `whereClause`, to eliminate groups from the result. Expressions in the
567574 -- `havingClause` can refer both to grouped expressions and to ungrouped
568575 -- expressions (which necessarily involve an aggregate function).
569− , orderByClause :: [SortExpression db params grp from]
576+ , orderByClause :: [SortExpression commons schemas params grp from]
570577 -- ^ The `orderByClause` is for optional sorting. When more than one
571578 -- `SortExpression` is specified, the later (right) values are used to sort
572579 -- rows that are equal according to the earlier (left) values.
@@ -583,7 +590,7 @@ data TableExpression
583590 }
584591
585592-- | Render a `TableExpression`
586−instance RenderSQL (TableExpression db params grp from) where
593+instance RenderSQL (TableExpression commons schemas params grp from) where
587594 renderSQL
588595 (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
589596 [ "FROM ", renderSQL frm'
@@ -616,16 +623,16 @@ instance RenderSQL (TableExpression db params grp from) where
616623-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
617624-- to match the left-to-right sequencing of their placement in SQL.
618625from
619− :: FromClause db params from -- ^ table reference
620− -> TableExpression db params 'Ungrouped from
626+ :: FromClause commons schemas params from -- ^ table reference
627+ -> TableExpression commons schemas params 'Ungrouped from
621628from rels = TableExpression rels [] NoGroups NoHaving [] [] []
622629
623630-- | A `where_` is an endomorphism of `TableExpression`s which adds a
624631-- search condition to the `whereClause`.
625632where_
626− :: Condition db params 'Ungrouped from -- ^ filtering condition
627− -> TableExpression db params grp from
628− -> TableExpression db params grp from
633+ :: Condition commons schemas params 'Ungrouped from -- ^ filtering condition
634+ -> TableExpression commons schemas params grp from
635+ -> TableExpression commons schemas params grp from
629636where_ wh rels = rels {whereClause = wh : whereClause rels}
630637
631638-- | A `groupBy` is a transformation of `TableExpression`s which switches
@@ -634,8 +641,8 @@ where_ wh rels = rels {whereClause = wh : whereClause rels}
634641groupBy
635642 :: SListI bys
636643 => NP (By from) bys -- ^ grouped columns
637− -> TableExpression db params 'Ungrouped from
638− -> TableExpression db params ('Grouped bys) from
644+ -> TableExpression commons schemas params 'Ungrouped from
645+ -> TableExpression commons schemas params ('Grouped bys) from
639646groupBy bys rels = TableExpression
640647 { fromClause = fromClause rels
641648 , whereClause = whereClause rels
@@ -649,34 +656,34 @@ groupBy bys rels = TableExpression
649656-- | A `having` is an endomorphism of `TableExpression`s which adds a
650657-- search condition to the `havingClause`.
651658having
652− :: Condition db params ('Grouped bys) from -- ^ having condition
653− -> TableExpression db params ('Grouped bys) from
654− -> TableExpression db params ('Grouped bys) from
659+ :: Condition commons schemas params ('Grouped bys) from -- ^ having condition
660+ -> TableExpression commons schemas params ('Grouped bys) from
661+ -> TableExpression commons schemas params ('Grouped bys) from
655662having hv rels = rels
656663 { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
657664
658665-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
659666-- ordering to the right of the `orderByClause`.
660667orderBy
661− :: [SortExpression db params grp from] -- ^ sort expressions
662− -> TableExpression db params grp from
663− -> TableExpression db params grp from
668+ :: [SortExpression commons schemas params grp from] -- ^ sort expressions
669+ -> TableExpression commons schemas params grp from
670+ -> TableExpression commons schemas params grp from
664671orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
665672
666673-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
667674-- `limitClause`.
668675limit
669676 :: Word64 -- ^ limit parameter
670− -> TableExpression db params grp from
671− -> TableExpression db params grp from
677+ -> TableExpression commons schemas params grp from
678+ -> TableExpression commons schemas params grp from
672679limit lim rels = rels {limitClause = lim : limitClause rels}
673680
674681-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
675682-- `offsetClause`.
676683offset
677684 :: Word64 -- ^ offset parameter
678− -> TableExpression db params grp from
679− -> TableExpression db params grp from
685+ -> TableExpression commons schemas params grp from
686+ -> TableExpression commons schemas params grp from
680687offset off rels = rels {offsetClause = off : offsetClause rels}
681688
682689{-----------------------------------------
@@ -685,56 +692,56 @@ JSON stuff
685692
686693unsafeSetOfFunction
687694 :: ByteString
688− -> Expression db params 'Ungrouped '[] ty
689− -> Query db params row
695+ -> Expression commons schemas params 'Ungrouped '[] ty
696+ -> Query commons schemas params row
690697unsafeSetOfFunction fun expr = UnsafeQuery $
691698 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
692699
693700-- | Expands the outermost JSON object into a set of key/value pairs.
694701jsonEach
695− :: Expression db params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
696− -> Query db params
702+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
703+ -> Query commons schemas params
697704 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
698705jsonEach = unsafeSetOfFunction "json_each"
699706
700707-- | Expands the outermost binary JSON object into a set of key/value pairs.
701708jsonbEach
702− :: Expression db params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
703− -> Query db params
709+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
710+ -> Query commons schemas params
704711 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
705712jsonbEach = unsafeSetOfFunction "jsonb_each"
706713
707714-- | Expands the outermost JSON object into a set of key/value pairs.
708715jsonEachAsText
709− :: Expression db params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
710− -> Query db params
716+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
717+ -> Query commons schemas params
711718 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
712719jsonEachAsText = unsafeSetOfFunction "json_each_text"
713720
714721-- | Expands the outermost binary JSON object into a set of key/value pairs.
715722jsonbEachAsText
716− :: Expression db params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
717− -> Query db params
723+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
724+ -> Query commons schemas params
718725 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
719726jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
720727
721728-- | Returns set of keys in the outermost JSON object.
722729jsonObjectKeys
723− :: Expression db params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
724− -> Query db params '["json_object_keys" ::: 'NotNull 'PGtext]
730+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
731+ -> Query commons schemas params '["json_object_keys" ::: 'NotNull 'PGtext]
725732jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
726733
727734-- | Returns set of keys in the outermost JSON object.
728735jsonbObjectKeys
729− :: Expression db params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
730− -> Query db params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
736+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
737+ -> Query commons schemas params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
731738jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
732739
733740unsafePopulateFunction
734741 :: ByteString
735742 -> TypeExpression schemas (nullity ('PGcomposite row))
736− -> Expression (commons :=> schemas) params 'Ungrouped '[] ty
737− -> Query (commons :=> schemas) params row
743+ -> Expression commons schemas params 'Ungrouped '[] ty
744+ -> Query commons schemas params row
738745unsafePopulateFunction fun ty expr = UnsafeQuery $
739746 "SELECT * FROM " <> fun <> "("
740747 <> "null::" <> renderSQL ty <> ", "
@@ -744,24 +751,24 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
744751-- type defined by the given table.
745752jsonPopulateRecord
746753 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
747− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
748− -> Query (commons :=> schemas) params row
754+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
755+ -> Query commons schemas params row
749756jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
750757
751758-- | Expands the binary JSON expression to a row whose columns match the record
752759-- type defined by the given table.
753760jsonbPopulateRecord
754761 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
755− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
756− -> Query (commons :=> schemas) params row
762+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
763+ -> Query commons schemas params row
757764jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
758765
759766-- | Expands the outermost array of objects in the given JSON expression to a
760767-- set of rows whose columns match the record type defined by the given table.
761768jsonPopulateRecordSet
762769 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
763− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
764− -> Query (commons :=> schemas) params row
770+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
771+ -> Query commons schemas params row
765772jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
766773
767774-- | Expands the outermost array of objects in the given binary JSON expression
@@ -769,55 +776,55 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
769776-- table.
770777jsonbPopulateRecordSet
771778 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
772− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
773− -> Query (commons :=> schemas) params row
779+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
780+ -> Query commons schemas params row
774781jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
775782
776783unsafeRecordFunction
777784 :: (SListI record, json `In` PGJsonType)
778785 => ByteString
779− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity json)
786+ -> Expression commons schemas params 'Ungrouped '[] (nullity json)
780787 -> NP (Aliased (TypeExpression schemas)) record
781− -> Query (commons :=> schemas) params record
788+ -> Query commons schemas params record
782789unsafeRecordFunction fun expr types = UnsafeQuery $
783790 "SELECT * FROM " <> fun <> "("
784791 <> renderSQL expr <> ")"
785792 <+> "AS" <+> "x" <> parenthesized (renderCommaSeparated renderTy types)
786793 where
787− renderTy :: Aliased (TypeExpression db) ty -> ByteString
794+ renderTy :: Aliased (TypeExpression schemas) ty -> ByteString
788795 renderTy (ty `As` alias) =
789796 renderSQL alias <+> renderSQL ty
790797
791798-- | Builds an arbitrary record from a JSON object.
792799jsonToRecord
793800 :: SListI record
794− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
801+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
795802 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
796− -> Query (commons :=> schemas) params record
803+ -> Query commons schemas params record
797804jsonToRecord = unsafeRecordFunction "json_to_record"
798805
799806-- | Builds an arbitrary record from a binary JSON object.
800807jsonbToRecord
801808 :: SListI record
802− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
809+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
803810 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
804− -> Query (commons :=> schemas) params record
811+ -> Query commons schemas params record
805812jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
806813
807814-- | Builds an arbitrary set of records from a JSON array of objects.
808815jsonToRecordSet
809816 :: SListI record
810− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
817+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
811818 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
812− -> Query (commons :=> schemas) params record
819+ -> Query commons schemas params record
813820jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
814821
815822-- | Builds an arbitrary set of records from a binary JSON array of objects.
816823jsonbToRecordSet
817824 :: SListI record
818− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
825+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
819826 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
820− -> Query (commons :=> schemas) params record
827+ -> Query commons schemas params record
821828jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
822829
823830{-----------------------------------------
@@ -828,38 +835,38 @@ FROM clauses
828835A `FromClause` can be a table name, or a derived table such
829836as a subquery, a @JOIN@ construct, or complex combinations of these.
830837-}
831−newtype FromClause db params from
838+newtype FromClause commons schemas params from
832839 = UnsafeFromClause { renderFromClause :: ByteString }
833840 deriving (GHC.Generic,Show,Eq,Ord,NFData)
834−instance RenderSQL (FromClause db params from) where
841+instance RenderSQL (FromClause commons schemas params from) where
835842 renderSQL = renderFromClause
836843
837844-- | A real `table` is a table from the database.
838845table
839846 :: (Has sch schemas schema, Has tab schema ('Table table))
840847 => Aliased (QualifiedAlias sch) (alias ::: tab)
841− -> FromClause (commons :=> schemas) params '[alias ::: TableToRow table]
848+ -> FromClause commons schemas params '[alias ::: TableToRow table]
842849table (tab `As` alias) = UnsafeFromClause $
843850 renderSQL tab <+> "AS" <+> renderSQL alias
844851
845852-- | `subquery` derives a table from a `Query`.
846853subquery
847− :: Aliased (Query db params) query
848− -> FromClause db params '[query]
854+ :: Aliased (Query commons schemas params) query
855+ -> FromClause commons schemas params '[query]
849856subquery = UnsafeFromClause . renderAliased (parenthesized . renderQuery)
850857
851858-- | `view` derives a table from a `View`.
852859view
853860 :: (Has sch schemas schema, Has vw schema ('View view))
854861 => Aliased (QualifiedAlias sch) (alias ::: vw)
855− -> FromClause (commons :=> schemas) params '[alias ::: view]
862+ -> FromClause commons schemas params '[alias ::: view]
856863view (vw `As` alias) = UnsafeFromClause $
857864 renderSQL vw <+> "AS" <+> renderSQL alias
858865
859866common
860867 :: Has cte commons common
861868 => Aliased Alias (alias ::: cte)
862− -> FromClause (commons :=> schemas) params '[alias ::: common]
869+ -> FromClause commons schemas params '[alias ::: common]
863870common (cte `As` alias) = UnsafeFromClause $
864871 renderSQL cte <+> "AS" <+> renderSQL alias
865872
@@ -870,11 +877,11 @@ common (cte `As` alias) = UnsafeFromClause $
870877 have @n * m@ rows.
871878-}
872879crossJoin
873− :: FromClause db params right
880+ :: FromClause commons schemas params right
874881 -- ^ right
875− -> FromClause db params left
882+ -> FromClause commons schemas params left
876883 -- ^ left
877− -> FromClause db params (Join left right)
884+ -> FromClause commons schemas params (Join left right)
878885crossJoin right left = UnsafeFromClause $
879886 renderSQL left <+> "CROSS JOIN" <+> renderSQL right
880887
@@ -882,13 +889,13 @@ crossJoin right left = UnsafeFromClause $
882889the @on@ condition.
883890-}
884891innerJoin
885− :: FromClause db params right
892+ :: FromClause commons schemas params right
886893 -- ^ right
887− -> Condition db params 'Ungrouped (Join left right)
894+ -> Condition commons schemas params 'Ungrouped (Join left right)
888895 -- ^ @on@ condition
889− -> FromClause db params left
896+ -> FromClause commons schemas params left
890897 -- ^ left
891− -> FromClause db params (Join left right)
898+ -> FromClause commons schemas params (Join left right)
892899innerJoin right on left = UnsafeFromClause $
893900 renderSQL left <+> "INNER JOIN" <+> renderSQL right
894901 <+> "ON" <+> renderSQL on
@@ -899,13 +906,13 @@ innerJoin right on left = UnsafeFromClause $
899906 Thus, the joined table always has at least one row for each row in @left@.
900907-}
901908leftOuterJoin
902− :: FromClause db params right
909+ :: FromClause commons schemas params right
903910 -- ^ right
904− -> Condition db params 'Ungrouped (Join left right)
911+ -> Condition commons schemas params 'Ungrouped (Join left right)
905912 -- ^ @on@ condition
906− -> FromClause db params left
913+ -> FromClause commons schemas params left
907914 -- ^ left
908− -> FromClause db params (Join left (NullifyFrom right))
915+ -> FromClause commons schemas params (Join left (NullifyFrom right))
909916leftOuterJoin right on left = UnsafeFromClause $
910917 renderSQL left <+> "LEFT OUTER JOIN" <+> renderSQL right
911918 <+> "ON" <+> renderSQL on
@@ -917,13 +924,13 @@ leftOuterJoin right on left = UnsafeFromClause $
917924 have a row for each row in @right@.
918925-}
919926rightOuterJoin
920− :: FromClause db params right
927+ :: FromClause commons schemas params right
921928 -- ^ right
922− -> Condition db params 'Ungrouped (Join left right)
929+ -> Condition commons schemas params 'Ungrouped (Join left right)
923930 -- ^ @on@ condition
924− -> FromClause db params left
931+ -> FromClause commons schemas params left
925932 -- ^ left
926− -> FromClause db params (Join (NullifyFrom left) right)
933+ -> FromClause commons schemas params (Join (NullifyFrom left) right)
927934rightOuterJoin right on left = UnsafeFromClause $
928935 renderSQL left <+> "RIGHT OUTER JOIN" <+> renderSQL right
929936 <+> "ON" <+> renderSQL on
@@ -936,13 +943,13 @@ rightOuterJoin right on left = UnsafeFromClause $
936943 is added.
937944-}
938945fullOuterJoin
939− :: FromClause db params right
946+ :: FromClause commons schemas params right
940947 -- ^ right
941− -> Condition db params 'Ungrouped (Join left right)
948+ -> Condition commons schemas params 'Ungrouped (Join left right)
942949 -- ^ @on@ condition
943− -> FromClause db params left
950+ -> FromClause commons schemas params left
944951 -- ^ left
945− -> FromClause db params
952+ -> FromClause commons schemas params
946953 (Join (NullifyFrom left) (NullifyFrom right))
947954fullOuterJoin right on left = UnsafeFromClause $
948955 renderSQL left <+> "FULL OUTER JOIN" <+> renderSQL right
@@ -1011,17 +1018,17 @@ instance RenderSQL (GroupByClause grp from) where
10111018-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
10121019-- `TableExpression` must use `Having` whose conditions are combined with
10131020-- `.&&`.
1014−data HavingClause db params grp from where
1015− NoHaving :: HavingClause db params 'Ungrouped from
1021+data HavingClause commons schemas params grp from where
1022+ NoHaving :: HavingClause commons schemas params 'Ungrouped from
10161023 Having
1017− :: [Condition db params ('Grouped bys) from]
1018− -> HavingClause db params ('Grouped bys) from
1019−deriving instance Show (HavingClause db params grp from)
1020−deriving instance Eq (HavingClause db params grp from)
1021−deriving instance Ord (HavingClause db params grp from)
1024+ :: [Condition commons schemas params ('Grouped bys) from]
1025+ -> HavingClause commons schemas params ('Grouped bys) from
1026+deriving instance Show (HavingClause commons schemas params grp from)
1027+deriving instance Eq (HavingClause commons schemas params grp from)
1028+deriving instance Ord (HavingClause commons schemas params grp from)
10221029
10231030-- | Render a `HavingClause`.
1024−instance RenderSQL (HavingClause db params grp from) where
1031+instance RenderSQL (HavingClause commons schemas params grp from) where
10251032 renderSQL = \case
10261033 NoHaving -> ""
10271034 Having [] -> ""
@@ -1040,29 +1047,29 @@ Sorting
10401047-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
10411048-- determine whether nulls appear before or after non-null values in the sort
10421049-- ordering of a `Null` result column.
1043−data SortExpression db params grp from where
1050+data SortExpression commons schemas params grp from where
10441051 Asc
1045− :: Expression db params grp from ('NotNull ty)
1046− -> SortExpression db params grp from
1052+ :: Expression commons schemas params grp from ('NotNull ty)
1053+ -> SortExpression commons schemas params grp from
10471054 Desc
1048− :: Expression db params grp from ('NotNull ty)
1049− -> SortExpression db params grp from
1055+ :: Expression commons schemas params grp from ('NotNull ty)
1056+ -> SortExpression commons schemas params grp from
10501057 AscNullsFirst
1051− :: Expression db params grp from ('Null ty)
1052− -> SortExpression db params grp from
1058+ :: Expression commons schemas params grp from ('Null ty)
1059+ -> SortExpression commons schemas params grp from
10531060 AscNullsLast
1054− :: Expression db params grp from ('Null ty)
1055− -> SortExpression db params grp from
1061+ :: Expression commons schemas params grp from ('Null ty)
1062+ -> SortExpression commons schemas params grp from
10561063 DescNullsFirst
1057− :: Expression db params grp from ('Null ty)
1058− -> SortExpression db params grp from
1064+ :: Expression commons schemas params grp from ('Null ty)
1065+ -> SortExpression commons schemas params grp from
10591066 DescNullsLast
1060− :: Expression db params grp from ('Null ty)
1061− -> SortExpression db params grp from
1062−deriving instance Show (SortExpression db params grp from)
1067+ :: Expression commons schemas params grp from ('Null ty)
1068+ -> SortExpression commons schemas params grp from
1069+deriving instance Show (SortExpression commons schemas params grp from)
10631070
10641071-- | Render a `SortExpression`.
1065−instance RenderSQL (SortExpression db params grp from) where
1072+instance RenderSQL (SortExpression commons schemas params grp from) where
10661073 renderSQL = \case
10671074 Asc expression -> renderSQL expression <+> "ASC"
10681075 Desc expression -> renderSQL expression <+> "DESC"
@@ -1075,18 +1082,18 @@ instance RenderSQL (SortExpression db params grp from) where
10751082
10761083unsafeSubqueryExpression
10771084 :: ByteString
1078− -> Expression db params grp from ty
1079− -> Query db params '[alias ::: ty]
1080− -> Expression db params grp from (nullity 'PGbool)
1085+ -> Expression commons schemas params grp from ty
1086+ -> Query commons schemas params '[alias ::: ty]
1087+ -> Expression commons schemas params grp from (nullity 'PGbool)
10811088unsafeSubqueryExpression op x q = UnsafeExpression $
10821089 renderSQL x <+> op <+> parenthesized (renderSQL q)
10831090
10841091unsafeRowSubqueryExpression
10851092 :: SListI row
10861093 => ByteString
1087− -> NP (Aliased (Expression db params grp from)) row
1088− -> Query db params row
1089− -> Expression db params grp from (nullity 'PGbool)
1094+ -> NP (Aliased (Expression commons schemas params grp from)) row
1095+ -> Query commons schemas params row
1096+ -> Expression commons schemas params grp from (nullity 'PGbool)
10901097unsafeRowSubqueryExpression op xs q = UnsafeExpression $
10911098 renderSQL (row xs) <+> op <+> parenthesized (renderSQL q)
10921099
@@ -1099,9 +1106,9 @@ unsafeRowSubqueryExpression op xs q = UnsafeExpression $
10991106-- >>> printSQL $ true `in_` values_ (true `as` #foo)
11001107-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11011108in_
1102− :: Expression db params grp from ty -- ^ expression
1103− -> Query db params '[alias ::: ty] -- ^ subquery
1104− -> Expression db params grp from (nullity 'PGbool)
1109+ :: Expression commons schemas params grp from ty -- ^ expression
1110+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1111+ -> Expression commons schemas params grp from (nullity 'PGbool)
11051112in_ = unsafeSubqueryExpression "IN"
11061113
11071114{- | The left-hand side of this form of `rowIn` is a row constructor.
@@ -1114,272 +1121,270 @@ is `true` if any equal subquery row is found.
11141121The result is `false` if no equal row is found
11151122(including the case where the subquery returns no rows).
11161123
1117−>>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1124+>>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11181125>>> printSQL $ myRow `rowIn` values_ myRow
11191126ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11201127-}
11211128rowIn
11221129 :: SListI row
1123− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1124− -> Query db params row -- ^ subquery
1125− -> Expression db params grp from (nullity 'PGbool)
1130+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1131+ -> Query commons schemas params row -- ^ subquery
1132+ -> Expression commons schemas params grp from (nullity 'PGbool)
11261133rowIn = unsafeRowSubqueryExpression "IN"
11271134
11281135-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
11291136-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11301137eqAll
1131− :: Expression db params grp from ty -- ^ expression
1132− -> Query db params '[alias ::: ty] -- ^ subquery
1133− -> Expression db params grp from (nullity 'PGbool)
1138+ :: Expression commons schemas params grp from ty -- ^ expression
1139+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1140+ -> Expression commons schemas params grp from (nullity 'PGbool)
11341141eqAll = unsafeSubqueryExpression "= ALL"
11351142
1136−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1143+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11371144-- >>> printSQL $ myRow `rowEqAll` values_ myRow
11381145-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11391146rowEqAll
11401147 :: SListI row
1141− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1142− -> Query db params row -- ^ subquery
1143− -> Expression db params grp from (nullity 'PGbool)
1148+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1149+ -> Query commons schemas params row -- ^ subquery
1150+ -> Expression commons schemas params grp from (nullity 'PGbool)
11441151rowEqAll = unsafeRowSubqueryExpression "= ALL"
11451152
11461153-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
11471154-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11481155eqAny
1149− :: Expression db params grp from ty -- ^ expression
1150− -> Query db params '[alias ::: ty] -- ^ subquery
1151− -> Expression db params grp from (nullity 'PGbool)
1156+ :: Expression commons schemas params grp from ty -- ^ expression
1157+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1158+ -> Expression commons schemas params grp from (nullity 'PGbool)
11521159eqAny = unsafeSubqueryExpression "= ANY"
11531160
1154−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1161+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11551162-- >>> printSQL $ myRow `rowEqAny` values_ myRow
11561163-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11571164rowEqAny
11581165 :: SListI row
1159− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1160− -> Query db params row -- ^ subquery
1161− -> Expression db params grp from (nullity 'PGbool)
1166+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1167+ -> Query commons schemas params row -- ^ subquery
1168+ -> Expression commons schemas params grp from (nullity 'PGbool)
11621169rowEqAny = unsafeRowSubqueryExpression "= ANY"
11631170
11641171-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
11651172-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11661173neqAll
1167− :: Expression db params grp from ty -- ^ expression
1168− -> Query db params '[alias ::: ty] -- ^ subquery
1169− -> Expression db params grp from (nullity 'PGbool)
1174+ :: Expression commons schemas params grp from ty -- ^ expression
1175+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1176+ -> Expression commons schemas params grp from (nullity 'PGbool)
11701177neqAll = unsafeSubqueryExpression "<> ALL"
11711178
1172−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1179+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11731180-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
11741181-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11751182rowNeqAll
11761183 :: SListI row
1177− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1178− -> Query db params row -- ^ subquery
1179− -> Expression db params grp from (nullity 'PGbool)
1184+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1185+ -> Query commons schemas params row -- ^ subquery
1186+ -> Expression commons schemas params grp from (nullity 'PGbool)
11801187rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
11811188
11821189-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
11831190-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
11841191neqAny
1185− :: Expression db params grp from ty -- ^ expression
1186− -> Query db params '[alias ::: ty] -- ^ subquery
1187− -> Expression db params grp from (nullity 'PGbool)
1192+ :: Expression commons schemas params grp from ty -- ^ expression
1193+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1194+ -> Expression commons schemas params grp from (nullity 'PGbool)
11881195neqAny = unsafeSubqueryExpression "<> ANY"
11891196
1190−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1197+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
11911198-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
11921199-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
11931200rowNeqAny
11941201 :: SListI row
1195− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1196− -> Query db params row -- ^ subquery
1197− -> Expression db params grp from (nullity 'PGbool)
1202+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1203+ -> Query commons schemas params row -- ^ subquery
1204+ -> Expression commons schemas params grp from (nullity 'PGbool)
11981205rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
11991206
12001207-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
12011208-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12021209allLt
1203− :: Expression db params grp from ty -- ^ expression
1204− -> Query db params '[alias ::: ty] -- ^ subquery
1205− -> Expression db params grp from (nullity 'PGbool)
1210+ :: Expression commons schemas params grp from ty -- ^ expression
1211+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1212+ -> Expression commons schemas params grp from (nullity 'PGbool)
12061213allLt = unsafeSubqueryExpression "ALL <"
12071214
1208−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1215+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12091216-- >>> printSQL $ myRow `rowLtAll` values_ myRow
12101217-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12111218rowLtAll
12121219 :: SListI row
1213− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1214− -> Query db params row -- ^ subquery
1215− -> Expression db params grp from (nullity 'PGbool)
1220+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1221+ -> Query commons schemas params row -- ^ subquery
1222+ -> Expression commons schemas params grp from (nullity 'PGbool)
12161223rowLtAll = unsafeRowSubqueryExpression "ALL <"
12171224
12181225-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
12191226-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12201227ltAny
1221− :: Expression db params grp from ty -- ^ expression
1222− -> Query db params '[alias ::: ty] -- ^ subquery
1223− -> Expression db params grp from (nullity 'PGbool)
1228+ :: Expression commons schemas params grp from ty -- ^ expression
1229+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1230+ -> Expression commons schemas params grp from (nullity 'PGbool)
12241231ltAny = unsafeSubqueryExpression "ANY <"
12251232
1226−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1233+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12271234-- >>> printSQL $ myRow `rowLtAll` values_ myRow
12281235-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12291236rowLtAny
12301237 :: SListI row
1231− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1232− -> Query db params row -- ^ subquery
1233− -> Expression db params grp from (nullity 'PGbool)
1238+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1239+ -> Query commons schemas params row -- ^ subquery
1240+ -> Expression commons schemas params grp from (nullity 'PGbool)
12341241rowLtAny = unsafeRowSubqueryExpression "ANY <"
12351242
12361243-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
12371244-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12381245lteAll
1239− :: Expression db params grp from ty -- ^ expression
1240− -> Query db params '[alias ::: ty] -- ^ subquery
1241− -> Expression db params grp from (nullity 'PGbool)
1246+ :: Expression commons schemas params grp from ty -- ^ expression
1247+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1248+ -> Expression commons schemas params grp from (nullity 'PGbool)
12421249lteAll = unsafeSubqueryExpression "<= ALL"
12431250
1244−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1251+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12451252-- >>> printSQL $ myRow `rowLteAll` values_ myRow
12461253-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12471254rowLteAll
12481255 :: SListI row
1249− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1250− -> Query db params row -- ^ subquery
1251− -> Expression db params grp from (nullity 'PGbool)
1256+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1257+ -> Query commons schemas params row -- ^ subquery
1258+ -> Expression commons schemas params grp from (nullity 'PGbool)
12521259rowLteAll = unsafeRowSubqueryExpression "<= ALL"
12531260
12541261-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
12551262-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12561263lteAny
1257− :: Expression db params grp from ty -- ^ expression
1258− -> Query db params '[alias ::: ty] -- ^ subquery
1259− -> Expression db params grp from (nullity 'PGbool)
1264+ :: Expression commons schemas params grp from ty -- ^ expression
1265+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1266+ -> Expression commons schemas params grp from (nullity 'PGbool)
12601267lteAny = unsafeSubqueryExpression "<= ANY"
12611268
1262−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1269+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12631270-- >>> printSQL $ myRow `rowLteAny` values_ myRow
12641271-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12651272rowLteAny
12661273 :: SListI row
1267− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1268− -> Query db params row -- ^ subquery
1269− -> Expression db params grp from (nullity 'PGbool)
1274+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1275+ -> Query commons schemas params row -- ^ subquery
1276+ -> Expression commons schemas params grp from (nullity 'PGbool)
12701277rowLteAny = unsafeRowSubqueryExpression "<= ANY"
12711278
12721279-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
12731280-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12741281gtAll
1275− :: Expression db params grp from ty -- ^ expression
1276− -> Query db params '[alias ::: ty] -- ^ subquery
1277− -> Expression db params grp from (nullity 'PGbool)
1282+ :: Expression commons schemas params grp from ty -- ^ expression
1283+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1284+ -> Expression commons schemas params grp from (nullity 'PGbool)
12781285gtAll = unsafeSubqueryExpression "> ALL"
12791286
1280−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1287+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12811288-- >>> printSQL $ myRow `rowGtAll` values_ myRow
12821289-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
12831290rowGtAll
12841291 :: SListI row
1285− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1286− -> Query db params row -- ^ subquery
1287− -> Expression db params grp from (nullity 'PGbool)
1292+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1293+ -> Query commons schemas params row -- ^ subquery
1294+ -> Expression commons schemas params grp from (nullity 'PGbool)
12881295rowGtAll = unsafeRowSubqueryExpression "> ALL"
12891296
12901297-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
12911298-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
12921299gtAny
1293− :: Expression db params grp from ty -- ^ expression
1294− -> Query db params '[alias ::: ty] -- ^ subquery
1295− -> Expression db params grp from (nullity 'PGbool)
1300+ :: Expression commons schemas params grp from ty -- ^ expression
1301+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1302+ -> Expression commons schemas params grp from (nullity 'PGbool)
12961303gtAny = unsafeSubqueryExpression "> ANY"
12971304
1298−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1305+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
12991306-- >>> printSQL $ myRow `rowGtAny` values_ myRow
13001307-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
13011308rowGtAny
13021309 :: SListI row
1303− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1304− -> Query db params row -- ^ subquery
1305− -> Expression db params grp from (nullity 'PGbool)
1310+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1311+ -> Query commons schemas params row -- ^ subquery
1312+ -> Expression commons schemas params grp from (nullity 'PGbool)
13061313rowGtAny = unsafeRowSubqueryExpression "> ANY"
13071314
13081315-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
13091316-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
13101317gteAll
1311− :: Expression db params grp from ty -- ^ expression
1312− -> Query db params '[alias ::: ty] -- ^ subquery
1313− -> Expression db params grp from (nullity 'PGbool)
1318+ :: Expression commons schemas params grp from ty -- ^ expression
1319+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1320+ -> Expression commons schemas params grp from (nullity 'PGbool)
13141321gteAll = unsafeSubqueryExpression ">= ALL"
13151322
1316−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1323+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
13171324-- >>> printSQL $ myRow `rowGteAll` values_ myRow
13181325-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
13191326rowGteAll
13201327 :: SListI row
1321− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1322− -> Query db params row -- ^ subquery
1323− -> Expression db params grp from (nullity 'PGbool)
1328+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1329+ -> Query commons schemas params row -- ^ subquery
1330+ -> Expression commons schemas params grp from (nullity 'PGbool)
13241331rowGteAll = unsafeRowSubqueryExpression ">= ALL"
13251332
13261333-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
13271334-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
13281335gteAny
1329− :: Expression db params grp from ty -- ^ expression
1330− -> Query db params '[alias ::: ty] -- ^ subquery
1331− -> Expression db params grp from (nullity 'PGbool)
1336+ :: Expression commons schemas params grp from ty -- ^ expression
1337+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1338+ -> Expression commons schemas params grp from (nullity 'PGbool)
13321339gteAny = unsafeSubqueryExpression ">= ANY"
13331340
1334−-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression db params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
1341+-- | >>> let myRow = 1 `as` #foo :* false `as` #bar :: NP (Aliased (Expression commons schemas params grp from)) '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
13351342-- >>> printSQL $ myRow `rowGteAny` values_ myRow
13361343-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
13371344rowGteAny
13381345 :: SListI row
1339− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1340− -> Query db params row -- ^ subquery
1341− -> Expression db params grp from (nullity 'PGbool)
1346+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1347+ -> Query commons schemas params row -- ^ subquery
1348+ -> Expression commons schemas params grp from (nullity 'PGbool)
13421349rowGteAny = unsafeRowSubqueryExpression ">= ANY"
13431350
13441351-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
13451352data CommonTableExpression statement
1353+ (schemas :: SchemasType)
13461354 (params :: [NullityType])
1347− (db0 :: DBType)
1348− (db1 :: DBType) where
1355+ (commons0 :: FromType)
1356+ (commons1 :: FromType) where
13491357 CommonTableExpression
1350− :: Aliased (statement (commons :=> schemas) params) (cte ::: common)
1351− -> CommonTableExpression statement params
1352− (commons :=> schemas) ((cte ::: common ': commons) :=> schemas)
1358+ :: Aliased (statement commons schemas params) (cte ::: common)
1359+ -> CommonTableExpression statement schemas params commons (cte ::: common ': commons)
13531360instance
13541361 ( KnownSymbol cte
1355− , db0 ~ (commons :=> schemas)
1356− , db1 ~ ((cte ::: common ': commons) :=> schemas)
1362+ , commons1 ~ (cte ::: common ': commons)
13571363 ) => Aliasable cte
1358− (statement db0 params common)
1359− (CommonTableExpression statement params db0 db1) where
1364+ (statement commons schemas params common)
1365+ (CommonTableExpression statement schemas params commons commons1) where
13601366 statement `as` cte = CommonTableExpression (statement `as` cte)
13611367instance
13621368 ( KnownSymbol cte
1363− , db0 ~ (commons :=> schemas)
1364− , db1 ~ ((cte ::: common ': commons) :=> schemas)
1369+ , commons1 ~ (cte ::: common ': commons)
13651370 ) => Aliasable cte
1366− (statement db0 params common)
1367− (AlignedList (CommonTableExpression statement params) db0 db1) where
1371+ (statement commons schemas params common)
1372+ (AlignedList (CommonTableExpression statement schemas params) commons commons1) where
13681373 statement `as` cte = single (statement `as` cte)
13691374
13701375-- | render a `CommonTableExpression`.
13711376renderCommonTableExpression
1372− :: (forall db ps row. statement db ps row -> ByteString) -- ^ render statement
1373− -> CommonTableExpression statement params db0 db1 -> ByteString
1377+ :: (forall cs ss ps row. statement cs ss ps row -> ByteString) -- ^ render statement
1378+ -> CommonTableExpression statement schemas params commons0 commons1 -> ByteString
13741379renderCommonTableExpression renderStatement
13751380 (CommonTableExpression (statement `As` alias)) =
13761381 renderSQL alias <+> "AS" <+> parenthesized (renderStatement statement)
13771382
13781383-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
13791384renderCommonTableExpressions
1380− :: (forall db ps row. statement db ps row -> ByteString) -- ^ render statement
1381− -> CommonTableExpression statement params db0 db1
1382− -> AlignedList (CommonTableExpression statement params) db1 db2
1385+ :: (forall cs ss ps row. statement cs ss ps row -> ByteString) -- ^ render statement
1386+ -> CommonTableExpression statement schemas params commons0 commons1
1387+ -> AlignedList (CommonTableExpression statement schemas params) commons1 commons2
13831388 -> ByteString
13841389renderCommonTableExpressions renderStatement cte ctes =
13851390 renderCommonTableExpression renderStatement cte <> case ctes of
@@ -1392,11 +1397,11 @@ renderCommonTableExpressions renderStatement cte ctes =
13921397-- defining temporary tables that exist just for one query.
13931398class With statement where
13941399 with
1395− :: AlignedList (CommonTableExpression statement params) db0 db1
1400+ :: AlignedList (CommonTableExpression statement schemas params) commons0 commons1
13961401 -- ^ common table expressions
1397− -> statement db1 params row
1402+ -> statement commons1 schemas params row
13981403 -- ^ larger query
1399− -> statement db0 params row
1404+ -> statement commons0 schemas params row
14001405instance With Query where
14011406 with Done query = query
14021407 with (cte :>> ctes) query = UnsafeQuery $
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−6
@@ -56,8 +56,6 @@ module Squeal.PostgreSQL.Schema
5656 , SchemaType
5757 , SchemasType
5858 , Public
59− , DBType
60− , DBof
6159 -- * Constraints
6260 , (:=>)
6361 , ColumnConstraint (..)
@@ -702,10 +700,6 @@ type SchemasType = [(Symbol,SchemaType)]
702700type family Public (schema :: SchemaType) :: SchemasType
703701 where Public schema = '["public" ::: schema]
704702
705−type DBType = (FromType,SchemasType)
706−
707−type family DBof :: SchemasType -> DBType where DBof = '(,) '[]
708−
709703-- | `IsPGlabel` looks very much like the `IsLabel` class. Whereas
710704-- the overloaded label, `fromLabel` is used for column references,
711705-- `label`s are used for enum terms. A `label` is called with
squeal-postgresql/test/Specs/ExceptionHandling.hs+1−3
@@ -48,8 +48,6 @@ type Schema =
4848
4949type Schemas = Public Schema
5050
51−type DB = DBof Schemas
52−
5351data User =
5452 User { userName :: Text
5553 , userEmail :: Maybe Text
@@ -58,7 +56,7 @@ data User =
5856instance SOP.Generic User
5957instance SOP.HasDatatypeInfo User
6058
61−insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
59+insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
6260 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
6361insertUser = insertInto #users
6462 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))