on dev help sign in
remove DBType

and add `Query_` and `Manipulation_` type families

commit0131dc72f22ffcd9131b8c71f7e14b0e60ede2aa authorEitan Chatav <eitan.chatav@gmail.com> dateThu 10 Jan 2019, 10:15 (8 years ago) parent2762bb4
8 files changed+702−697
squeal-postgresql/exe/Example.hs+3−5 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+4−4 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+305−304 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+87−80 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+286−281 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−6
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/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+305−304
@@ -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
@@ -249,7 +250,7 @@ class KnownNat n => HasParameter
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
@@ -424,20 +425,20 @@ matchNull y f x = ifThenElse (isNull x) y
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
@@ -491,41 +492,41 @@ field
491492 , Has field row ty)
492493 => QualifiedAlias sch tydef -- ^ row type
493494 -> Alias field -- ^ field name
494− -> Expression (commons :=> schemas) params grp from ('NotNull ('PGcomposite row))
495− -> Expression (commons :=> schemas) params grp from ty
495+ -> Expression commons schemas params grp from ('NotNull ('PGcomposite row))
496+ -> Expression commons schemas params grp from ty
496497field td fld expr = UnsafeExpression $
497498 parenthesized (renderSQL expr <> "::" <> renderSQL td)
498499 <> "." <> renderSQL fld
499500
500501instance Semigroup
501− (Expression db params grp from (nullity ('PGvararray ty))) where
502+ (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
502503 (<>) = unsafeBinaryOp "||"
503504
504505instance Monoid
505− (Expression db params grp from (nullity ('PGvararray ty))) where
506+ (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
506507 mempty = array []
507508 mappend = (<>)
508509
509−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression (commons :=> schemas) '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
510+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression commons schemas '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
510511-- >>> printSQL expr
511512-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
512513greatest
513− :: Expression db params grp from (nullty)
514+ :: Expression commons schemas params grp from (nullty)
514515 -- ^ needs at least 1 argument
515− -> [Expression db params grp from (nullty)]
516+ -> [Expression commons schemas params grp from (nullty)]
516517 -- ^ or more
517− -> Expression db params grp from (nullty)
518+ -> Expression commons schemas params grp from (nullty)
518519greatest x xs = UnsafeExpression $ "GREATEST("
519520 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
520521
521522-- | >>> printSQL $ least currentTimestamp [null_]
522523-- LEAST(CURRENT_TIMESTAMP, NULL)
523524least
524− :: Expression db params grp from (nullty)
525+ :: Expression commons schemas params grp from (nullty)
525526 -- ^ needs at least 1 argument
526− -> [Expression db params grp from (nullty)]
527+ -> [Expression commons schemas params grp from (nullty)]
527528 -- ^ or more
528− -> Expression db params grp from (nullty)
529+ -> Expression commons schemas params grp from (nullty)
529530least x xs = UnsafeExpression $ "LEAST("
530531 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
531532
@@ -534,9 +535,9 @@ least x xs = UnsafeExpression $ "LEAST("
534535unsafeBinaryOp
535536 :: ByteString
536537 -- ^ operator
537− -> Expression db params grp from (ty0)
538− -> Expression db params grp from (ty1)
539− -> Expression db params grp from (ty2)
538+ -> Expression commons schemas params grp from (ty0)
539+ -> Expression commons schemas params grp from (ty1)
540+ -> Expression commons schemas params grp from (ty2)
540541unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
541542 renderSQL x <+> op <+> renderSQL y
542543
@@ -545,8 +546,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
545546unsafeUnaryOp
546547 :: ByteString
547548 -- ^ operator
548− -> Expression db params grp from (ty0)
549− -> Expression db params grp from (ty1)
549+ -> Expression commons schemas params grp from (ty0)
550+ -> Expression commons schemas params grp from (ty1)
550551unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
551552 op <+> renderSQL x
552553
@@ -555,8 +556,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
555556unsafeFunction
556557 :: ByteString
557558 -- ^ function
558− -> Expression db params grp from (xty)
559− -> Expression db params grp from (yty)
559+ -> Expression commons schemas params grp from (xty)
560+ -> Expression commons schemas params grp from (yty)
560561unsafeFunction fun x = UnsafeExpression $
561562 fun <> parenthesized (renderSQL x)
562563
@@ -565,13 +566,13 @@ unsafeVariadicFunction
565566 :: SListI elems
566567 => ByteString
567568 -- ^ function
568− -> NP (Expression db params grp from) elems
569− -> Expression db params grp from ret
569+ -> NP (Expression commons schemas params grp from) elems
570+ -> Expression commons schemas params grp from ret
570571unsafeVariadicFunction fun x = UnsafeExpression $
571572 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
572573
573574instance ty `In` PGNum
574− => Num (Expression db params grp from (nullity ty)) where
575+ => Num (Expression commons schemas params grp from (nullity ty)) where
575576 (+) = unsafeBinaryOp "+"
576577 (-) = unsafeBinaryOp "-"
577578 (*) = unsafeBinaryOp "*"
@@ -583,12 +584,12 @@ instance ty `In` PGNum
583584 . show
584585
585586instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
586− (Expression db params grp from (nullity ty)) where
587+ (Expression commons schemas params grp from (nullity ty)) where
587588 (/) = unsafeBinaryOp "/"
588589 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
589590
590591instance (ty `In` PGNum, ty `In` PGFloating) => Floating
591− (Expression db params grp from (nullity ty)) where
592+ (Expression commons schemas params grp from (nullity ty)) where
592593 pi = UnsafeExpression "pi()"
593594 exp = unsafeFunction "exp"
594595 log = unsafeFunction "ln"
@@ -611,18 +612,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
611612
612613-- | >>> :{
613614-- let
614−-- expression :: Expression db params grp from (nullity 'PGfloat4)
615+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
615616-- expression = atan2_ pi 2
616617-- in printSQL expression
617618-- :}
618619-- atan2(pi(), 2)
619620atan2_
620621 :: float `In` PGFloating
621− => Expression db params grp from (nullity float)
622+ => Expression commons schemas params grp from (nullity float)
622623 -- ^ numerator
623− -> Expression db params grp from (nullity float)
624+ -> Expression commons schemas params grp from (nullity float)
624625 -- ^ denominator
625− -> Expression db params grp from (nullity float)
626+ -> Expression commons schemas params grp from (nullity float)
626627atan2_ y x = UnsafeExpression $
627628 "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
628629
@@ -635,9 +636,9 @@ atan2_ y x = UnsafeExpression $
635636cast
636637 :: TypeExpression schemas ty1
637638 -- ^ type to cast as
638− -> Expression (commons :=> schemas) params grp from ty0
639+ -> Expression commons schemas params grp from ty0
639640 -- ^ value to convert
640− -> Expression (commons :=> schemas) params grp from ty1
641+ -> Expression commons schemas params grp from ty1
641642cast ty x = UnsafeExpression $ parenthesized $
642643 renderSQL x <+> "::" <+> renderSQL ty
643644
@@ -645,136 +646,136 @@ cast ty x = UnsafeExpression $ parenthesized $
645646--
646647-- >>> :{
647648-- let
648−-- expression :: Expression db params grp from (nullity 'PGint2)
649+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
649650-- expression = 5 `quot_` 2
650651-- in printSQL expression
651652-- :}
652653-- (5 / 2)
653654quot_
654655 :: int `In` PGIntegral
655− => Expression db params grp from (nullity int)
656+ => Expression commons schemas params grp from (nullity int)
656657 -- ^ numerator
657− -> Expression db params grp from (nullity int)
658+ -> Expression commons schemas params grp from (nullity int)
658659 -- ^ denominator
659− -> Expression db params grp from (nullity int)
660+ -> Expression commons schemas params grp from (nullity int)
660661quot_ = unsafeBinaryOp "/"
661662
662663-- | remainder upon integer division
663664--
664665-- >>> :{
665666-- let
666−-- expression :: Expression db params grp from (nullity 'PGint2)
667+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
667668-- expression = 5 `rem_` 2
668669-- in printSQL expression
669670-- :}
670671-- (5 % 2)
671672rem_
672673 :: int `In` PGIntegral
673− => Expression db params grp from (nullity int)
674+ => Expression commons schemas params grp from (nullity int)
674675 -- ^ numerator
675− -> Expression db params grp from (nullity int)
676+ -> Expression commons schemas params grp from (nullity int)
676677 -- ^ denominator
677− -> Expression db params grp from (nullity int)
678+ -> Expression commons schemas params grp from (nullity int)
678679rem_ = unsafeBinaryOp "%"
679680
680681-- | >>> :{
681682-- let
682−-- expression :: Expression db params grp from (nullity 'PGfloat4)
683+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
683684-- expression = trunc pi
684685-- in printSQL expression
685686-- :}
686687-- trunc(pi())
687688trunc
688689 :: frac `In` PGFloating
689− => Expression db params grp from (nullity frac)
690+ => Expression commons schemas params grp from (nullity frac)
690691 -- ^ fractional number
691− -> Expression db params grp from (nullity frac)
692+ -> Expression commons schemas params grp from (nullity frac)
692693trunc = unsafeFunction "trunc"
693694
694695-- | >>> :{
695696-- let
696−-- expression :: Expression db params grp from (nullity 'PGfloat4)
697+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
697698-- expression = round_ pi
698699-- in printSQL expression
699700-- :}
700701-- round(pi())
701702round_
702703 :: frac `In` PGFloating
703− => Expression db params grp from (nullity frac)
704+ => Expression commons schemas params grp from (nullity frac)
704705 -- ^ fractional number
705− -> Expression db params grp from (nullity frac)
706+ -> Expression commons schemas params grp from (nullity frac)
706707round_ = unsafeFunction "round"
707708
708709-- | >>> :{
709710-- let
710−-- expression :: Expression db params grp from (nullity 'PGfloat4)
711+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
711712-- expression = ceiling_ pi
712713-- in printSQL expression
713714-- :}
714715-- ceiling(pi())
715716ceiling_
716717 :: frac `In` PGFloating
717− => Expression db params grp from (nullity frac)
718+ => Expression commons schemas params grp from (nullity frac)
718719 -- ^ fractional number
719− -> Expression db params grp from (nullity frac)
720+ -> Expression commons schemas params grp from (nullity frac)
720721ceiling_ = unsafeFunction "ceiling"
721722
722723-- | A `Condition` is an `Expression`, which can evaluate
723724-- to `true`, `false` or `null_`. This is because SQL uses
724725-- a three valued logic.
725−type Condition db params grp from =
726− Expression db params grp from ('Null 'PGbool)
726+type Condition commons schemas params grp from =
727+ Expression commons schemas params grp from ('Null 'PGbool)
727728
728729-- | >>> printSQL true
729730-- TRUE
730−true :: Expression db params grp from (nullity 'PGbool)
731+true :: Expression commons schemas params grp from (nullity 'PGbool)
731732true = UnsafeExpression "TRUE"
732733
733734-- | >>> printSQL false
734735-- FALSE
735−false :: Expression db params grp from (nullity 'PGbool)
736+false :: Expression commons schemas params grp from (nullity 'PGbool)
736737false = UnsafeExpression "FALSE"
737738
738739-- | >>> printSQL $ not_ true
739740-- (NOT TRUE)
740741not_
741− :: Expression db params grp from (nullity 'PGbool)
742− -> Expression db params grp from (nullity 'PGbool)
742+ :: Expression commons schemas params grp from (nullity 'PGbool)
743+ -> Expression commons schemas params grp from (nullity 'PGbool)
743744not_ = unsafeUnaryOp "NOT"
744745
745746-- | >>> printSQL $ true .&& false
746747-- (TRUE AND FALSE)
747748(.&&)
748− :: Expression db params grp from (nullity 'PGbool)
749− -> Expression db params grp from (nullity 'PGbool)
750− -> Expression db params grp from (nullity 'PGbool)
749+ :: Expression commons schemas params grp from (nullity 'PGbool)
750+ -> Expression commons schemas params grp from (nullity 'PGbool)
751+ -> Expression commons schemas params grp from (nullity 'PGbool)
751752infixr 3 .&&
752753(.&&) = unsafeBinaryOp "AND"
753754
754755-- | >>> printSQL $ true .|| false
755756-- (TRUE OR FALSE)
756757(.||)
757− :: Expression db params grp from (nullity 'PGbool)
758− -> Expression db params grp from (nullity 'PGbool)
759− -> Expression db params grp from (nullity 'PGbool)
758+ :: Expression commons schemas params grp from (nullity 'PGbool)
759+ -> Expression commons schemas params grp from (nullity 'PGbool)
760+ -> Expression commons schemas params grp from (nullity 'PGbool)
760761infixr 2 .||
761762(.||) = unsafeBinaryOp "OR"
762763
763764-- | >>> :{
764765-- let
765−-- expression :: Expression db params grp from (nullity 'PGint2)
766+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
766767-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
767768-- in printSQL expression
768769-- :}
769770-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
770771caseWhenThenElse
771− :: [ ( Condition db params grp from
772− , Expression db params grp from ty
772+ :: [ ( Condition commons schemas params grp from
773+ , Expression commons schemas params grp from ty
773774 ) ]
774775 -- ^ whens and thens
775− -> Expression db params grp from ty
776+ -> Expression commons schemas params grp from ty
776777 -- ^ else
777− -> Expression db params grp from ty
778+ -> Expression commons schemas params grp from ty
778779caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
779780 [ "CASE"
780781 , mconcat
@@ -790,16 +791,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
790791
791792-- | >>> :{
792793-- let
793−-- expression :: Expression db params grp from (nullity 'PGint2)
794+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
794795-- expression = ifThenElse true 1 0
795796-- in printSQL expression
796797-- :}
797798-- CASE WHEN TRUE THEN 1 ELSE 0 END
798799ifThenElse
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
800+ :: Condition commons schemas params grp from
801+ -> Expression commons schemas params grp from ty -- ^ then
802+ -> Expression commons schemas params grp from ty -- ^ else
803+ -> Expression commons schemas params grp from ty
803804ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
804805
805806-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -808,85 +809,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
808809-- >>> printSQL $ true .== null_
809810-- (TRUE = NULL)
810811(.==)
811− :: Expression db params grp from (nullity0 ty) -- ^ lhs
812− -> Expression db params grp from (nullity1 ty) -- ^ rhs
813− -> Condition db params grp from
812+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
813+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
814+ -> Condition commons schemas params grp from
814815(.==) = unsafeBinaryOp "="
815816infix 4 .==
816817
817818-- | >>> printSQL $ true ./= null_
818819-- (TRUE <> NULL)
819820(./=)
820− :: Expression db params grp from (nullity0 ty) -- ^ lhs
821− -> Expression db params grp from (nullity1 ty) -- ^ rhs
822− -> Condition db params grp from
821+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
822+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
823+ -> Condition commons schemas params grp from
823824(./=) = unsafeBinaryOp "<>"
824825infix 4 ./=
825826
826827-- | >>> printSQL $ true .>= null_
827828-- (TRUE >= NULL)
828829(.>=)
829− :: Expression db params grp from (nullity0 ty) -- ^ lhs
830− -> Expression db params grp from (nullity1 ty) -- ^ rhs
831− -> Condition db params grp from
830+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
831+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
832+ -> Condition commons schemas params grp from
832833(.>=) = unsafeBinaryOp ">="
833834infix 4 .>=
834835
835836-- | >>> printSQL $ true .< null_
836837-- (TRUE < NULL)
837838(.<)
838− :: Expression db params grp from (nullity0 ty) -- ^ lhs
839− -> Expression db params grp from (nullity1 ty) -- ^ rhs
840− -> Condition db params grp from
839+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
840+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
841+ -> Condition commons schemas params grp from
841842(.<) = unsafeBinaryOp "<"
842843infix 4 .<
843844
844845-- | >>> printSQL $ true .<= null_
845846-- (TRUE <= NULL)
846847(.<=)
847− :: Expression db params grp from (nullity0 ty) -- ^ lhs
848− -> Expression db params grp from (nullity1 ty) -- ^ rhs
849− -> Condition db params grp from
848+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
849+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
850+ -> Condition commons schemas params grp from
850851(.<=) = unsafeBinaryOp "<="
851852infix 4 .<=
852853
853854-- | >>> printSQL $ true .> null_
854855-- (TRUE > NULL)
855856(.>)
856− :: Expression db params grp from (nullity0 ty) -- ^ lhs
857− -> Expression db params grp from (nullity1 ty) -- ^ rhs
858− -> Condition db params grp from
857+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
858+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
859+ -> Condition commons schemas params grp from
859860(.>) = unsafeBinaryOp ">"
860861infix 4 .>
861862
862863-- | >>> printSQL currentDate
863864-- CURRENT_DATE
864865currentDate
865− :: Expression db params grp from (nullity 'PGdate)
866+ :: Expression commons schemas params grp from (nullity 'PGdate)
866867currentDate = UnsafeExpression "CURRENT_DATE"
867868
868869-- | >>> printSQL currentTime
869870-- CURRENT_TIME
870871currentTime
871− :: Expression db params grp from (nullity 'PGtimetz)
872+ :: Expression commons schemas params grp from (nullity 'PGtimetz)
872873currentTime = UnsafeExpression "CURRENT_TIME"
873874
874875-- | >>> printSQL currentTimestamp
875876-- CURRENT_TIMESTAMP
876877currentTimestamp
877− :: Expression db params grp from (nullity 'PGtimestamptz)
878+ :: Expression commons schemas params grp from (nullity 'PGtimestamptz)
878879currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
879880
880881-- | >>> printSQL localTime
881882-- LOCALTIME
882883localTime
883− :: Expression db params grp from (nullity 'PGtime)
884+ :: Expression commons schemas params grp from (nullity 'PGtime)
884885localTime = UnsafeExpression "LOCALTIME"
885886
886887-- | >>> printSQL localTimestamp
887888-- LOCALTIMESTAMP
888889localTimestamp
889− :: Expression db params grp from (nullity 'PGtimestamp)
890+ :: Expression commons schemas params grp from (nullity 'PGtimestamp)
890891localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
891892
892893{-----------------------------------------
@@ -894,7 +895,7 @@ text
894895-----------------------------------------}
895896
896897instance IsString
897− (Expression db params grp from (nullity 'PGtext)) where
898+ (Expression commons schemas params grp from (nullity 'PGtext)) where
898899 fromString str = UnsafeExpression $
899900 "E\'" <> fromString (escape =<< str) <> "\'"
900901 where
@@ -910,36 +911,36 @@ instance IsString
910911 c -> [c]
911912
912913instance Semigroup
913− (Expression db params grp from (nullity 'PGtext)) where
914+ (Expression commons schemas params grp from (nullity 'PGtext)) where
914915 (<>) = unsafeBinaryOp "||"
915916
916917instance Monoid
917− (Expression db params grp from (nullity 'PGtext)) where
918+ (Expression commons schemas params grp from (nullity 'PGtext)) where
918919 mempty = fromString ""
919920 mappend = (<>)
920921
921922-- | >>> printSQL $ lower "ARRRGGG"
922923-- lower(E'ARRRGGG')
923924lower
924− :: Expression db params grp from (nullity 'PGtext)
925+ :: Expression commons schemas params grp from (nullity 'PGtext)
925926 -- ^ string to lower case
926− -> Expression db params grp from (nullity 'PGtext)
927+ -> Expression commons schemas params grp from (nullity 'PGtext)
927928lower = unsafeFunction "lower"
928929
929930-- | >>> printSQL $ upper "eeee"
930931-- upper(E'eeee')
931932upper
932− :: Expression db params grp from (nullity 'PGtext)
933+ :: Expression commons schemas params grp from (nullity 'PGtext)
933934 -- ^ string to upper case
934− -> Expression db params grp from (nullity 'PGtext)
935+ -> Expression commons schemas params grp from (nullity 'PGtext)
935936upper = unsafeFunction "upper"
936937
937938-- | >>> printSQL $ charLength "four"
938939-- char_length(E'four')
939940charLength
940− :: Expression db params grp from (nullity 'PGtext)
941+ :: Expression commons schemas params grp from (nullity 'PGtext)
941942 -- ^ string to measure
942− -> Expression db params grp from (nullity 'PGint4)
943+ -> Expression commons schemas params grp from (nullity 'PGint4)
943944charLength = unsafeFunction "char_length"
944945
945946-- | The `like` expression returns true if the @string@ matches
@@ -952,11 +953,11 @@ charLength = unsafeFunction "char_length"
952953-- >>> printSQL $ "abc" `like` "a%"
953954-- (E'abc' LIKE E'a%')
954955like
955− :: Expression db params grp from (nullity 'PGtext)
956+ :: Expression commons schemas params grp from (nullity 'PGtext)
956957 -- ^ string
957− -> Expression db params grp from (nullity 'PGtext)
958+ -> Expression commons schemas params grp from (nullity 'PGtext)
958959 -- ^ pattern
959− -> Expression db params grp from (nullity 'PGbool)
960+ -> Expression commons schemas params grp from (nullity 'PGbool)
960961like = unsafeBinaryOp "LIKE"
961962
962963-- | The key word ILIKE can be used instead of LIKE to make the
@@ -965,11 +966,11 @@ like = unsafeBinaryOp "LIKE"
965966-- >>> printSQL $ "abc" `ilike` "a%"
966967-- (E'abc' ILIKE E'a%')
967968ilike
968− :: Expression db params grp from (nullity 'PGtext)
969+ :: Expression commons schemas params grp from (nullity 'PGtext)
969970 -- ^ string
970− -> Expression db params grp from (nullity 'PGtext)
971+ -> Expression commons schemas params grp from (nullity 'PGtext)
971972 -- ^ pattern
972− -> Expression db params grp from (nullity 'PGbool)
973+ -> Expression commons schemas params grp from (nullity 'PGbool)
973974ilike = unsafeBinaryOp "ILIKE"
974975
975976{-----------------------------------------
@@ -984,36 +985,36 @@ Table 9.44: json and jsonb operators
984985-- | Get JSON value (object field or array element) at a key.
985986(.->)
986987 :: (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)
988+ => Expression commons schemas params grp from (nullity json)
989+ -> Expression commons schemas params grp from (nullity key)
990+ -> Expression commons schemas params grp from ('Null json)
990991infixl 8 .->
991992(.->) = unsafeBinaryOp "->"
992993
993994-- | Get JSON value (object field or array element) at a key, as text.
994995(.->>)
995996 :: (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)
997+ => Expression commons schemas params grp from (nullity json)
998+ -> Expression commons schemas params grp from (nullity key)
999+ -> Expression commons schemas params grp from ('Null 'PGtext)
9991000infixl 8 .->>
10001001(.->>) = unsafeBinaryOp "->>"
10011002
10021003-- | Get JSON value at a specified path.
10031004(.#>)
10041005 :: (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)
1006+ => Expression commons schemas params grp from (nullity json)
1007+ -> Expression commons schemas params grp from (nullity path)
1008+ -> Expression commons schemas params grp from ('Null json)
10081009infixl 8 .#>
10091010(.#>) = unsafeBinaryOp "#>"
10101011
10111012-- | Get JSON value at a specified path as text.
10121013(.#>>)
10131014 :: (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)
1015+ => Expression commons schemas params grp from (nullity json)
1016+ -> Expression commons schemas params grp from (nullity path)
1017+ -> Expression commons schemas params grp from ('Null 'PGtext)
10171018infixl 8 .#>>
10181019(.#>>) = unsafeBinaryOp "#>>"
10191020
@@ -1022,48 +1023,48 @@ infixl 8 .#>>
10221023-- | Does the left JSON value contain the right JSON path/value entries at the
10231024-- top level?
10241025(.@>)
1025− :: Expression db params grp from (nullity 'PGjsonb)
1026− -> Expression db params grp from (nullity 'PGjsonb)
1027− -> Condition db params grp from
1026+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1027+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1028+ -> Condition commons schemas params grp from
10281029infixl 9 .@>
10291030(.@>) = unsafeBinaryOp "@>"
10301031
10311032-- | Are the left JSON path/value entries contained at the top level within the
10321033-- right JSON value?
10331034(.<@)
1034− :: Expression db params grp from (nullity 'PGjsonb)
1035− -> Expression db params grp from (nullity 'PGjsonb)
1036− -> Condition db params grp from
1035+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1036+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1037+ -> Condition commons schemas params grp from
10371038infixl 9 .<@
10381039(.<@) = unsafeBinaryOp "<@"
10391040
10401041-- | Does the string exist as a top-level key within the JSON value?
10411042(.?)
1042− :: Expression db params grp from (nullity 'PGjsonb)
1043− -> Expression db params grp from (nullity 'PGtext)
1044− -> Condition db params grp from
1043+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1044+ -> Expression commons schemas params grp from (nullity 'PGtext)
1045+ -> Condition commons schemas params grp from
10451046infixl 9 .?
10461047(.?) = unsafeBinaryOp "?"
10471048
10481049-- | Do any of these array strings exist as top-level keys?
10491050(.?|)
1050− :: Expression db params grp from (nullity 'PGjsonb)
1051− -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1052− -> Condition db params grp from
1051+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1052+ -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1053+ -> Condition commons schemas params grp from
10531054infixl 9 .?|
10541055(.?|) = unsafeBinaryOp "?|"
10551056
10561057-- | Do all of these array strings exist as top-level keys?
10571058(.?&)
1058− :: Expression db params grp from (nullity 'PGjsonb)
1059− -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1060− -> Condition db params grp from
1059+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1060+ -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1061+ -> Condition commons schemas params grp from
10611062infixl 9 .?&
10621063(.?&) = unsafeBinaryOp "?&"
10631064
10641065-- | Concatenate two jsonb values into a new jsonb value.
10651066instance
1066− Semigroup (Expression db from grouping param (nullity 'PGjsonb)) where
1067+ Semigroup (Expression commons schemas from grouping param (nullity 'PGjsonb)) where
10671068 (<>) = unsafeBinaryOp "||"
10681069
10691070-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1080,9 +1081,9 @@ instance
10801081-- count from the end). Throws an error if top level container is not an array.
10811082(.-.)
10821083 :: (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)
1084+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1085+ -> Expression commons schemas params grp from (nullity key)
1086+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
10861087infixl 6 .-.
10871088(.-.) = unsafeBinaryOp "-"
10881089
@@ -1090,9 +1091,9 @@ infixl 6 .-.
10901091-- integers count from the end)
10911092(#-.)
10921093 :: 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)
1094+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1095+ -> Expression commons schemas params grp from (nullity arrayty)
1096+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
10961097infixl 6 #-.
10971098(#-.) = unsafeBinaryOp "#-"
10981099
@@ -1103,14 +1104,14 @@ Table 9.45: JSON creation functions
11031104-- | Literal binary JSON
11041105jsonbLit
11051106 :: JSON.ToJSON x
1106− => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjsonb)
1107+ => x -> Expression commons schemas params grp from (nullity 'PGjsonb)
11071108jsonbLit = cast jsonb . UnsafeExpression
11081109 . singleQuotedUtf8 . toStrict . JSON.encode
11091110
11101111-- | Literal JSON
11111112jsonLit
11121113 :: JSON.ToJSON x
1113− => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjson)
1114+ => x -> Expression commons schemas params grp from (nullity 'PGjson)
11141115jsonLit = cast json . UnsafeExpression
11151116 . singleQuotedUtf8 . toStrict . JSON.encode
11161117
@@ -1121,8 +1122,8 @@ jsonLit = cast json . UnsafeExpression
11211122-- number, a Boolean, or a null value, the text representation will be used, in
11221123-- such a fashion that it is a valid json value.
11231124toJson
1124− :: Expression db params grp from (nullity ty)
1125− -> Expression db params grp from (nullity 'PGjson)
1125+ :: Expression commons schemas params grp from (nullity ty)
1126+ -> Expression commons schemas params grp from (nullity 'PGjson)
11261127toJson = unsafeFunction "to_json"
11271128
11281129-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1132,43 +1133,43 @@ toJson = unsafeFunction "to_json"
11321133-- number, a Boolean, or a null value, the text representation will be used, in
11331134-- such a fashion that it is a valid jsonb value.
11341135toJsonb
1135− :: Expression db params grp from (nullity ty)
1136− -> Expression db params grp from (nullity 'PGjsonb)
1136+ :: Expression commons schemas params grp from (nullity ty)
1137+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
11371138toJsonb = unsafeFunction "to_jsonb"
11381139
11391140-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
11401141-- becomes a JSON array of arrays.
11411142arrayToJson
11421143 :: PGArray "arrayToJson" arr
1143− => Expression db params grp from (nullity arr)
1144− -> Expression db params grp from (nullity 'PGjson)
1144+ => Expression commons schemas params grp from (nullity arr)
1145+ -> Expression commons schemas params grp from (nullity 'PGjson)
11451146arrayToJson = unsafeFunction "array_to_json"
11461147
11471148-- | Returns the row as a JSON object.
11481149rowToJson
1149− :: Expression db params grp from (nullity ('PGcomposite ty))
1150− -> Expression db params grp from (nullity 'PGjson)
1150+ :: Expression commons schemas params grp from (nullity ('PGcomposite ty))
1151+ -> Expression commons schemas params grp from (nullity 'PGjson)
11511152rowToJson = unsafeFunction "row_to_json"
11521153
11531154-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
11541155-- argument list.
11551156jsonBuildArray
11561157 :: SListI elems
1157− => NP (Expression db params grp from) elems
1158− -> Expression db params grp from (nullity 'PGjson)
1158+ => NP (Expression commons schemas params grp from) elems
1159+ -> Expression commons schemas params grp from (nullity 'PGjson)
11591160jsonBuildArray = unsafeVariadicFunction "json_build_array"
11601161
11611162-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
11621163-- variadic argument list.
11631164jsonbBuildArray
11641165 :: SListI elems
1165− => NP (Expression db params grp from) elems
1166− -> Expression db params grp from (nullity 'PGjsonb)
1166+ => NP (Expression commons schemas params grp from) elems
1167+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
11671168jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
11681169
11691170unsafeRowFunction
11701171 :: All Top elems
1171− => NP (Aliased (Expression db params grp from)) elems
1172+ => NP (Aliased (Expression commons schemas params grp from)) elems
11721173 -> [ByteString]
11731174unsafeRowFunction =
11741175 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1183,8 +1184,8 @@ unsafeRowFunction =
11831184-- and values.
11841185jsonBuildObject
11851186 :: All Top elems
1186− => NP (Aliased (Expression db params grp from)) elems
1187− -> Expression db params grp from (nullity 'PGjson)
1187+ => NP (Aliased (Expression commons schemas params grp from)) elems
1188+ -> Expression commons schemas params grp from (nullity 'PGjson)
11881189jsonBuildObject
11891190 = unsafeFunction "json_build_object"
11901191 . UnsafeExpression
@@ -1196,8 +1197,8 @@ jsonBuildObject
11961197-- between text and values.
11971198jsonbBuildObject
11981199 :: All Top elems
1199− => NP (Aliased (Expression db params grp from)) elems
1200− -> Expression db params grp from (nullity 'PGjsonb)
1200+ => NP (Aliased (Expression commons schemas params grp from)) elems
1201+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12011202jsonbBuildObject
12021203 = unsafeFunction "jsonb_build_object"
12031204 . UnsafeExpression
@@ -1210,8 +1211,8 @@ jsonbBuildObject
12101211-- array has exactly two elements, which are taken as a key/value pair.
12111212jsonObject
12121213 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1213− => Expression db params grp from (nullity arr)
1214− -> Expression db params grp from (nullity 'PGjson)
1214+ => Expression commons schemas params grp from (nullity arr)
1215+ -> Expression commons schemas params grp from (nullity 'PGjson)
12151216jsonObject = unsafeFunction "json_object"
12161217
12171218-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1220,8 +1221,8 @@ jsonObject = unsafeFunction "json_object"
12201221-- array has exactly two elements, which are taken as a key/value pair.
12211222jsonbObject
12221223 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1223− => Expression db params grp from (nullity arr)
1224− -> Expression db params grp from (nullity 'PGjsonb)
1224+ => Expression commons schemas params grp from (nullity arr)
1225+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12251226jsonbObject = unsafeFunction "jsonb_object"
12261227
12271228-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1229,9 +1230,9 @@ jsonbObject = unsafeFunction "jsonb_object"
12291230jsonZipObject
12301231 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
12311232 , 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)
1233+ => Expression commons schemas params grp from (nullity keysArray)
1234+ -> Expression commons schemas params grp from (nullity valuesArray)
1235+ -> Expression commons schemas params grp from (nullity 'PGjson)
12351236jsonZipObject ks vs =
12361237 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
12371238
@@ -1241,9 +1242,9 @@ jsonZipObject ks vs =
12411242jsonbZipObject
12421243 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
12431244 , 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)
1245+ => Expression commons schemas params grp from (nullity keysArray)
1246+ -> Expression commons schemas params grp from (nullity valuesArray)
1247+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12471248jsonbZipObject ks vs =
12481249 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
12491250
@@ -1253,23 +1254,23 @@ Table 9.46: JSON processing functions
12531254
12541255-- | Returns the number of elements in the outermost JSON array.
12551256jsonArrayLength
1256− :: Expression db params grp from (nullity 'PGjson)
1257− -> Expression db params grp from (nullity 'PGint4)
1257+ :: Expression commons schemas params grp from (nullity 'PGjson)
1258+ -> Expression commons schemas params grp from (nullity 'PGint4)
12581259jsonArrayLength = unsafeFunction "json_array_length"
12591260
12601261-- | Returns the number of elements in the outermost binary JSON array.
12611262jsonbArrayLength
1262− :: Expression db params grp from (nullity 'PGjsonb)
1263− -> Expression db params grp from (nullity 'PGint4)
1263+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1264+ -> Expression commons schemas params grp from (nullity 'PGint4)
12641265jsonbArrayLength = unsafeFunction "jsonb_array_length"
12651266
12661267-- | Returns JSON value pointed to by the given path (equivalent to #>
12671268-- operator).
12681269jsonExtractPath
12691270 :: 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)
1271+ => Expression commons schemas params grp from (nullity 'PGjson)
1272+ -> NP (Expression commons schemas params grp from) elems
1273+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12731274jsonExtractPath x xs =
12741275 unsafeVariadicFunction "json_extract_path" (x :* xs)
12751276
@@ -1277,9 +1278,9 @@ jsonExtractPath x xs =
12771278-- operator).
12781279jsonbExtractPath
12791280 :: 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)
1281+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1282+ -> NP (Expression commons schemas params grp from) elems
1283+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
12831284jsonbExtractPath x xs =
12841285 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
12851286
@@ -1287,9 +1288,9 @@ jsonbExtractPath x xs =
12871288-- operator), as text.
12881289jsonExtractPathAsText
12891290 :: 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)
1291+ => Expression commons schemas params grp from (nullity 'PGjson)
1292+ -> NP (Expression commons schemas params grp from) elems
1293+ -> Expression commons schemas params grp from (nullity 'PGjson)
12931294jsonExtractPathAsText x xs =
12941295 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
12951296
@@ -1297,38 +1298,38 @@ jsonExtractPathAsText x xs =
12971298-- operator), as text.
12981299jsonbExtractPathAsText
12991300 :: 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)
1301+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1302+ -> NP (Expression commons schemas params grp from) elems
1303+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13031304jsonbExtractPathAsText x xs =
13041305 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
13051306
13061307-- | Returns the type of the outermost JSON value as a text string. Possible
13071308-- types are object, array, string, number, boolean, and null.
13081309jsonTypeof
1309− :: Expression db params grp from (nullity 'PGjson)
1310− -> Expression db params grp from (nullity 'PGtext)
1310+ :: Expression commons schemas params grp from (nullity 'PGjson)
1311+ -> Expression commons schemas params grp from (nullity 'PGtext)
13111312jsonTypeof = unsafeFunction "json_typeof"
13121313
13131314-- | Returns the type of the outermost binary JSON value as a text string.
13141315-- Possible types are object, array, string, number, boolean, and null.
13151316jsonbTypeof
1316− :: Expression db params grp from (nullity 'PGjsonb)
1317− -> Expression db params grp from (nullity 'PGtext)
1317+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1318+ -> Expression commons schemas params grp from (nullity 'PGtext)
13181319jsonbTypeof = unsafeFunction "jsonb_typeof"
13191320
13201321-- | Returns its argument with all object fields that have null values omitted.
13211322-- Other null values are untouched.
13221323jsonStripNulls
1323− :: Expression db params grp from (nullity 'PGjson)
1324− -> Expression db params grp from (nullity 'PGjson)
1324+ :: Expression commons schemas params grp from (nullity 'PGjson)
1325+ -> Expression commons schemas params grp from (nullity 'PGjson)
13251326jsonStripNulls = unsafeFunction "json_strip_nulls"
13261327
13271328-- | Returns its argument with all object fields that have null values omitted.
13281329-- Other null values are untouched.
13291330jsonbStripNulls
1330− :: Expression db params grp from (nullity 'PGjsonb)
1331− -> Expression db params grp from (nullity 'PGjsonb)
1331+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1332+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13321333jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13331334
13341335-- | @ jsonbSet target path new_value create_missing @
@@ -1340,11 +1341,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
13401341-- arrays.
13411342jsonbSet
13421343 :: 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)
1344+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1345+ -> Expression commons schemas params grp from (nullity arr)
1346+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1347+ -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1348+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13481349jsonbSet tgt path val createMissing = case createMissing of
13491350 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
13501351 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1359,19 +1360,19 @@ jsonbSet tgt path val createMissing = case createMissing of
13591360-- in path count from the end of JSON arrays.
13601361jsonbInsert
13611362 :: 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)
1363+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1364+ -> Expression commons schemas params grp from (nullity arr)
1365+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1366+ -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1367+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
13671368jsonbInsert tgt path val insertAfter = case insertAfter of
13681369 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
13691370 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
13701371
13711372-- | Returns its argument as indented JSON text.
13721373jsonbPretty
1373− :: Expression db params grp from (nullity 'PGjsonb)
1374− -> Expression db params grp from (nullity 'PGtext)
1374+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1375+ -> Expression commons schemas params grp from (nullity 'PGtext)
13751376jsonbPretty = unsafeFunction "jsonb_pretty"
13761377
13771378{-----------------------------------------
@@ -1381,54 +1382,54 @@ aggregation
13811382-- | escape hatch to define aggregate functions
13821383unsafeAggregate
13831384 :: ByteString -- ^ aggregate function
1384− -> Expression db from 'Ungrouped params (xty)
1385− -> Expression db from ('Grouped bys) params (yty)
1385+ -> Expression commons schemas from 'Ungrouped params (xty)
1386+ -> Expression commons schemas from ('Grouped bys) params (yty)
13861387unsafeAggregate fun x = UnsafeExpression $ mconcat
13871388 [fun, "(", renderSQL x, ")"]
13881389
13891390-- | escape hatch to define aggregate functions over distinct values
13901391unsafeAggregateDistinct
13911392 :: ByteString -- ^ aggregate function
1392− -> Expression db from 'Ungrouped params (xty)
1393− -> Expression db from ('Grouped bys) params (yty)
1393+ -> Expression commons schemas from 'Ungrouped params (xty)
1394+ -> Expression commons schemas from ('Grouped bys) params (yty)
13941395unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
13951396 [fun, "(DISTINCT ", renderSQL x, ")"]
13961397
13971398-- | >>> :{
13981399-- let
1399−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1400+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
14001401-- expression = sum_ #col
14011402-- in printSQL expression
14021403-- :}
14031404-- sum("col")
14041405sum_
14051406 :: ty `In` PGNum
1406− => Expression db from 'Ungrouped params (nullity ty)
1407+ => Expression commons schemas from 'Ungrouped params (nullity ty)
14071408 -- ^ what to sum
1408− -> Expression db from ('Grouped bys) params (nullity ty)
1409+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
14091410sum_ = unsafeAggregate "sum"
14101411
14111412-- | >>> :{
14121413-- let
1413−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
1414+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
14141415-- expression = sumDistinct #col
14151416-- in printSQL expression
14161417-- :}
14171418-- sum(DISTINCT "col")
14181419sumDistinct
14191420 :: ty `In` PGNum
1420− => Expression db from 'Ungrouped params (nullity ty)
1421+ => Expression commons schemas from 'Ungrouped params (nullity ty)
14211422 -- ^ what to sum
1422− -> Expression db from ('Grouped bys) params (nullity ty)
1423+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
14231424sumDistinct = unsafeAggregateDistinct "sum"
14241425
14251426-- | A constraint for `PGType`s that you can take averages of and the resulting
14261427-- `PGType`.
14271428class PGAvg ty avg | ty -> avg where
14281429 avg, avgDistinct
1429− :: Expression db from 'Ungrouped params (nullity ty)
1430+ :: Expression commons schemas from 'Ungrouped params (nullity ty)
14301431 -- ^ what to average
1431− -> Expression db from ('Grouped bys) params (nullity avg)
1432+ -> Expression commons schemas from ('Grouped bys) params (nullity avg)
14321433 avg = unsafeAggregate "avg"
14331434 avgDistinct = unsafeAggregateDistinct "avg"
14341435instance PGAvg 'PGint2 'PGnumeric
@@ -1441,110 +1442,110 @@ instance PGAvg 'PGinterval 'PGinterval
14411442
14421443-- | >>> :{
14431444-- let
1444−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1445+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14451446-- expression = bitAnd #col
14461447-- in printSQL expression
14471448-- :}
14481449-- bit_and("col")
14491450bitAnd
14501451 :: int `In` PGIntegral
1451− => Expression db from 'Ungrouped params (nullity int)
1452+ => Expression commons schemas from 'Ungrouped params (nullity int)
14521453 -- ^ what to aggregate
1453− -> Expression db from ('Grouped bys) params (nullity int)
1454+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14541455bitAnd = unsafeAggregate "bit_and"
14551456
14561457-- | >>> :{
14571458-- let
1458−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1459+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14591460-- expression = bitOr #col
14601461-- in printSQL expression
14611462-- :}
14621463-- bit_or("col")
14631464bitOr
14641465 :: int `In` PGIntegral
1465− => Expression db from 'Ungrouped params (nullity int)
1466+ => Expression commons schemas from 'Ungrouped params (nullity int)
14661467 -- ^ what to aggregate
1467− -> Expression db from ('Grouped bys) params (nullity int)
1468+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14681469bitOr = unsafeAggregate "bit_or"
14691470
14701471-- | >>> :{
14711472-- let
1472−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1473+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14731474-- expression = bitAndDistinct #col
14741475-- in printSQL expression
14751476-- :}
14761477-- bit_and(DISTINCT "col")
14771478bitAndDistinct
14781479 :: int `In` PGIntegral
1479− => Expression db from 'Ungrouped params (nullity int)
1480+ => Expression commons schemas from 'Ungrouped params (nullity int)
14801481 -- ^ what to aggregate
1481− -> Expression db from ('Grouped bys) params (nullity int)
1482+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14821483bitAndDistinct = unsafeAggregateDistinct "bit_and"
14831484
14841485-- | >>> :{
14851486-- let
1486−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1487+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
14871488-- expression = bitOrDistinct #col
14881489-- in printSQL expression
14891490-- :}
14901491-- bit_or(DISTINCT "col")
14911492bitOrDistinct
14921493 :: int `In` PGIntegral
1493− => Expression db from 'Ungrouped params (nullity int)
1494+ => Expression commons schemas from 'Ungrouped params (nullity int)
14941495 -- ^ what to aggregate
1495− -> Expression db from ('Grouped bys) params (nullity int)
1496+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
14961497bitOrDistinct = unsafeAggregateDistinct "bit_or"
14971498
14981499-- | >>> :{
14991500-- let
1500−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1501+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15011502-- expression = boolAnd #col
15021503-- in printSQL expression
15031504-- :}
15041505-- bool_and("col")
15051506boolAnd
1506− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1507+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15071508 -- ^ what to aggregate
1508− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1509+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15091510boolAnd = unsafeAggregate "bool_and"
15101511
15111512-- | >>> :{
15121513-- let
1513−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1514+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15141515-- expression = boolOr #col
15151516-- in printSQL expression
15161517-- :}
15171518-- bool_or("col")
15181519boolOr
1519− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1520+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15201521 -- ^ what to aggregate
1521− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1522+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15221523boolOr = unsafeAggregate "bool_or"
15231524
15241525-- | >>> :{
15251526-- let
1526−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1527+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15271528-- expression = boolAndDistinct #col
15281529-- in printSQL expression
15291530-- :}
15301531-- bool_and(DISTINCT "col")
15311532boolAndDistinct
1532− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1533+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15331534 -- ^ what to aggregate
1534− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1535+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15351536boolAndDistinct = unsafeAggregateDistinct "bool_and"
15361537
15371538-- | >>> :{
15381539-- let
1539−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1540+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15401541-- expression = boolOrDistinct #col
15411542-- in printSQL expression
15421543-- :}
15431544-- bool_or(DISTINCT "col")
15441545boolOrDistinct
1545− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1546+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15461547 -- ^ what to aggregate
1547− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1548+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15481549boolOrDistinct = unsafeAggregateDistinct "bool_or"
15491550
15501551-- | A special aggregation that does not require an input
@@ -1552,70 +1553,70 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
15521553-- >>> printSQL countStar
15531554-- count(*)
15541555countStar
1555− :: Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1556+ :: Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
15561557countStar = UnsafeExpression $ "count(*)"
15571558
15581559-- | >>> :{
15591560-- let
1560−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1561+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
15611562-- expression = count #col
15621563-- in printSQL expression
15631564-- :}
15641565-- count("col")
15651566count
1566− :: Expression db from 'Ungrouped params ty
1567+ :: Expression commons schemas from 'Ungrouped params ty
15671568 -- ^ what to count
1568− -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1569+ -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
15691570count = unsafeAggregate "count"
15701571
15711572-- | >>> :{
15721573-- let
1573−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1574+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
15741575-- expression = countDistinct #col
15751576-- in printSQL expression
15761577-- :}
15771578-- count(DISTINCT "col")
15781579countDistinct
1579− :: Expression db from 'Ungrouped params ty
1580+ :: Expression commons schemas from 'Ungrouped params ty
15801581 -- ^ what to count
1581− -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1582+ -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
15821583countDistinct = unsafeAggregateDistinct "count"
15831584
15841585-- | synonym for `boolAnd`
15851586--
15861587-- >>> :{
15871588-- let
1588−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1589+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
15891590-- expression = every #col
15901591-- in printSQL expression
15911592-- :}
15921593-- every("col")
15931594every
1594− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1595+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
15951596 -- ^ what to aggregate
1596− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1597+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
15971598every = unsafeAggregate "every"
15981599
15991600-- | synonym for `boolAndDistinct`
16001601--
16011602-- >>> :{
16021603-- let
1603−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1604+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
16041605-- expression = everyDistinct #col
16051606-- in printSQL expression
16061607-- :}
16071608-- every(DISTINCT "col")
16081609everyDistinct
1609− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1610+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
16101611 -- ^ what to aggregate
1611− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1612+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
16121613everyDistinct = unsafeAggregateDistinct "every"
16131614
16141615-- | minimum and maximum aggregation
16151616max_, min_, maxDistinct, minDistinct
1616− :: Expression db from 'Ungrouped params (nullity ty)
1617+ :: Expression commons schemas from 'Ungrouped params (nullity ty)
16171618 -- ^ what to aggregate
1618− -> Expression db from ('Grouped bys) params (nullity ty)
1619+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
16191620max_ = unsafeAggregate "max"
16201621min_ = unsafeAggregate "min"
16211622maxDistinct = unsafeAggregateDistinct "max"
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+87−80
@@ -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
@@ -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{-----------------------------------------
@@ -232,10 +239,10 @@ insertInto
232239 , SOP.SListI columns
233240 , SOP.SListI row1 )
234241 => 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
242+ -> QueryClause commons schemas params columns
243+ -> ConflictClause tab commons schemas params table
244+ -> ReturningClause commons schemas params '[tab ::: row0] row1
245+ -> Manipulation commons schemas params row1
239246insertInto tab qry conflict ret = UnsafeManipulation $
240247 "INSERT" <+> "INTO" <+> renderSQL tab
241248 <+> renderSQL qry
@@ -250,28 +257,28 @@ insertInto_
250257 , row ~ TableToRow table
251258 , SOP.SListI columns )
252259 => QualifiedAlias sch tab
253− -> QueryClause db params columns
254− -> Manipulation db params '[]
260+ -> QueryClause commons schemas params columns
261+ -> Manipulation commons schemas params '[]
255262insertInto_ tab qry =
256263 insertInto tab qry OnConflictDoRaise (Returning_ Nil)
257264
258−data QueryClause db params columns where
265+data QueryClause commons schemas params columns where
259266 Values
260267 :: SOP.SListI columns
261− => NP (ColumnExpression db params 'Ungrouped '[]) columns
262− -> [NP (ColumnExpression db params 'Ungrouped '[]) columns]
263− -> QueryClause db params columns
268+ => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
269+ -> [NP (ColumnExpression schemas params 'Ungrouped '[]) columns]
270+ -> QueryClause commons schemas params columns
264271 Select
265272 :: SOP.SListI columns
266− => NP (ColumnExpression db params grp from) columns
267− -> TableExpression db params grp from
268− -> QueryClause db params columns
273+ => NP (ColumnExpression schemas params grp from) columns
274+ -> TableExpression commons schemas params grp from
275+ -> QueryClause commons schemas params columns
269276 Subquery
270277 :: ColumnsToRow columns ~ row
271− => Query db params row
272− -> QueryClause db params columns
278+ => Query commons schemas params row
279+ -> QueryClause commmons schemas params columns
273280
274−instance RenderSQL (QueryClause db params columns) where
281+instance RenderSQL (QueryClause commons schemas params columns) where
275282 renderSQL = \case
276283 Values row0 rows ->
277284 parenthesized (renderCommaSeparated renderSQLPart row0)
@@ -287,7 +294,7 @@ instance RenderSQL (QueryClause db params columns) where
287294 Subquery qry -> renderQuery qry
288295 where
289296 renderSQLPartMaybe, renderValuePartMaybe
290− :: ColumnExpression db params grp from column -> Maybe ByteString
297+ :: ColumnExpression schemas params grp from column -> Maybe ByteString
291298 renderSQLPartMaybe = \case
292299 DefaultAs _ -> Nothing
293300 Specific (_ `As` name) -> Just $ renderSQL name
@@ -295,7 +302,7 @@ instance RenderSQL (QueryClause db params columns) where
295302 DefaultAs _ -> Nothing
296303 Specific (value `As` _) -> Just $ renderExpression value
297304 renderSQLPart, renderValuePart
298− :: ColumnExpression db params grp from column -> ByteString
305+ :: ColumnExpression schemas params grp from column -> ByteString
299306 renderSQLPart = \case
300307 DefaultAs name -> renderSQL name
301308 Specific (_ `As` name) -> renderSQL name
@@ -305,49 +312,49 @@ instance RenderSQL (QueryClause db params columns) where
305312
306313pattern Values_
307314 :: SOP.SListI columns
308− => NP (ColumnExpression db params 'Ungrouped '[]) columns
309− -> QueryClause db params columns
315+ => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
316+ -> QueryClause commons schemas params columns
310317pattern Values_ vals = Values vals []
311318
312−data ColumnExpression db params grp from column where
319+data ColumnExpression schemas params grp from column where
313320 DefaultAs
314321 :: KnownSymbol col
315322 => Alias col
316− -> ColumnExpression db params grp from (col ::: 'Def :=> ty)
323+ -> ColumnExpression schemas params grp from (col ::: 'Def :=> ty)
317324 Specific
318− :: Aliased (Expression db params grp from) (col ::: ty)
319− -> ColumnExpression db params grp from (col ::: defness :=> ty)
325+ :: Aliased (Expression '[] schemas params grp from) (col ::: ty)
326+ -> ColumnExpression schemas params grp from (col ::: defness :=> ty)
320327
321328instance (KnownSymbol col, column ~ (col ::: defness :=> ty))
322329 => Aliasable col
323− (Expression db params grp from ty)
324− (ColumnExpression db params grp from column) where
330+ (Expression '[] schemas params grp from ty)
331+ (ColumnExpression schemas params grp from column) where
325332 expression `as` col = Specific (expression `As` col)
326333instance (KnownSymbol col, columns ~ '[col ::: defness :=> ty])
327334 => Aliasable col
328− (Expression db params grp from ty)
329− (NP (ColumnExpression db params grp from) columns) where
335+ (Expression '[] schemas params grp from ty)
336+ (NP (ColumnExpression schemas params grp from) columns) where
330337 expression `as` col = expression `as` col :* Nil
331338instance (KnownSymbol col, column ~ (col ::: 'Def :=> ty))
332− => DefaultAliasable col (ColumnExpression db params grp from column) where
339+ => DefaultAliasable col (ColumnExpression schemas params grp from column) where
333340 defaultAs = DefaultAs
334341instance (KnownSymbol col, columns ~ '[col ::: 'Def :=> ty])
335− => DefaultAliasable col (NP (ColumnExpression db params grp from) columns) where
342+ => DefaultAliasable col (NP (ColumnExpression schemas params grp from) columns) where
336343 defaultAs col = defaultAs col :* Nil
337344
338345instance (HasUnique tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
339− => IsLabel col (ColumnExpression db params 'Ungrouped from column) where
346+ => IsLabel col (ColumnExpression schemas params 'Ungrouped from column) where
340347 fromLabel = fromLabel @col `as` Alias
341348instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
342349 => IsLabel col
343− (NP (ColumnExpression db params 'Ungrouped from) columns) where
350+ (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
344351 fromLabel = fromLabel @col `as` Alias
345352
346353instance (Has tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
347− => IsQualified tab col (ColumnExpression db params 'Ungrouped from column) where
354+ => IsQualified tab col (ColumnExpression schemas params 'Ungrouped from column) where
348355 tab ! col = tab ! col `as` col
349356instance (Has tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
350− => IsQualified tab col (NP (ColumnExpression db params 'Ungrouped from) columns) where
357+ => IsQualified tab col (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
351358 tab ! col = tab ! col `as` col
352359
353360instance
@@ -356,7 +363,7 @@ instance
356363 , GroupedBy tab col bys
357364 , column ~ (col ::: defness :=> ty)
358365 ) => IsLabel col
359− (ColumnExpression db params ('Grouped bys) from column) where
366+ (ColumnExpression schemas params ('Grouped bys) from column) where
360367 fromLabel = fromLabel @col `as` Alias
361368instance
362369 ( HasUnique tab from row
@@ -364,7 +371,7 @@ instance
364371 , GroupedBy tab col bys
365372 , columns ~ '[col ::: defness :=> ty]
366373 ) => IsLabel col
367− (NP (ColumnExpression db params ('Grouped bys) from) columns) where
374+ (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
368375 fromLabel = fromLabel @col `as` Alias
369376
370377instance
@@ -373,7 +380,7 @@ instance
373380 , GroupedBy tab col bys
374381 , column ~ (col ::: defness :=> ty)
375382 ) => IsQualified tab col
376− (ColumnExpression db params ('Grouped bys) from column) where
383+ (ColumnExpression schemas params ('Grouped bys) from column) where
377384 tab ! col = tab ! col `as` col
378385instance
379386 ( Has tab from row
@@ -381,10 +388,10 @@ instance
381388 , GroupedBy tab col bys
382389 , columns ~ '[col ::: defness :=> ty]
383390 ) => IsQualified tab col
384− (NP (ColumnExpression db params ('Grouped bys) from) columns) where
391+ (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
385392 tab ! col = tab ! col :* Nil
386393
387−instance RenderSQL (ColumnExpression db params grp from column) where
394+instance RenderSQL (ColumnExpression schemas params grp from column) where
388395 renderSQL = \case
389396 DefaultAs col ->
390397 renderSQL col <+> "=" <+> "DEFAULT"
@@ -401,18 +408,18 @@ instance RenderSQL (ColumnExpression db params grp from column) where
401408-- the row will not be returned. `ReturningStar` will return all columns
402409-- in the row. Use @Returning Nil@ in the common case where no return
403410-- values are desired.
404−newtype ReturningClause db params from row =
405− Returning (Selection db params 'Ungrouped from row)
411+newtype ReturningClause commons schemas params from row =
412+ Returning (Selection commons schemas params 'Ungrouped from row)
406413
407−instance RenderSQL (ReturningClause db params from row) where
414+instance RenderSQL (ReturningClause commons schemas params from row) where
408415 renderSQL = \case
409416 Returning (List Nil) -> ""
410417 Returning selection -> " RETURNING" <+> renderSQL selection
411418
412419pattern Returning_
413420 :: SOP.SListI row
414− => NP (Aliased (Expression db params 'Ungrouped from)) row
415− -> ReturningClause db params from row
421+ => NP (Aliased (Expression commons schemas params 'Ungrouped from)) row
422+ -> ReturningClause commons schemas params from row
416423pattern Returning_ list = Returning (List list)
417424
418425-- | A `ConflictClause` specifies an action to perform upon a constraint
@@ -420,34 +427,34 @@ pattern Returning_ list = Returning (List list)
420427-- `OnConflictDoNothing` simply avoids inserting a row.
421428-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
422429-- proposed for insertion.
423−data ConflictClause tab db params table where
424− OnConflictDoRaise :: ConflictClause tab db params table
430+data ConflictClause tab commons schemas params table where
431+ OnConflictDoRaise :: ConflictClause tab commons schemas params table
425432 OnConflict
426433 :: ConflictTarget constraints
427− -> ConflictAction tab db params columns
428− -> ConflictClause tab db params (constraints :=> columns)
434+ -> ConflictAction tab commons schemas params columns
435+ -> ConflictClause tab commons schemas params (constraints :=> columns)
429436
430437-- | Render a `ConflictClause`.
431438instance SOP.SListI (TableToColumns table)
432− => RenderSQL (ConflictClause tab db params table) where
439+ => RenderSQL (ConflictClause tab commons schemas params table) where
433440 renderSQL = \case
434441 OnConflictDoRaise -> ""
435442 OnConflict target action -> " ON CONFLICT"
436443 <+> renderSQL target <+> renderSQL action
437444
438−data ConflictAction tab db params columns where
439− DoNothing :: ConflictAction tab db params columns
445+data ConflictAction tab commons schemas params columns where
446+ DoNothing :: ConflictAction tab commons schemas params columns
440447 DoUpdate
441448 :: ( row ~ ColumnsToRow columns
442449 , SOP.SListI columns
443450 , columns ~ (col0 ': cols)
444451 , SOP.All (HasIn columns) subcolumns
445452 , 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
453+ => NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]) subcolumns
454+ -> [Condition commons schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]]
455+ -> ConflictAction tab commons schemas params columns
449456
450−instance RenderSQL (ConflictAction tab db params columns) where
457+instance RenderSQL (ConflictAction tab commons schemas params columns) where
451458 renderSQL = \case
452459 DoNothing -> "DO NOTHING"
453460 DoUpdate updates whs'
@@ -487,12 +494,12 @@ update
487494 , SOP.All (HasIn columns) subcolumns
488495 , AllUnique subcolumns )
489496 => QualifiedAlias sch tab -- ^ table to update
490− -> NP (ColumnExpression db params 'Ungrouped '[tab ::: row0]) subcolumns
497+ -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row0]) subcolumns
491498 -- ^ modified values to replace old values
492− -> Condition db params 'Ungrouped '[tab ::: row0]
499+ -> Condition commons schemas params 'Ungrouped '[tab ::: row0]
493500 -- ^ condition under which to perform update on a row
494− -> ReturningClause db params '[tab ::: row0] row1 -- ^ results to return
495− -> Manipulation db params row1
501+ -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
502+ -> Manipulation commons schemas params row1
496503update tab columns wh returning = UnsafeManipulation $
497504 "UPDATE"
498505 <+> renderSQL tab
@@ -512,22 +519,22 @@ update_
512519 , SOP.All (HasIn columns) subcolumns
513520 , AllUnique subcolumns )
514521 => QualifiedAlias sch tab -- ^ table to update
515− -> NP (ColumnExpression db params 'Ungrouped '[tab ::: row]) subcolumns
522+ -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row]) subcolumns
516523 -- ^ modified values to replace old values
517− -> Condition db params 'Ungrouped '[tab ::: row]
524+ -> Condition commons schemas params 'Ungrouped '[tab ::: row]
518525 -- ^ condition under which to perform update on a row
519− -> Manipulation db params '[]
526+ -> Manipulation commons schemas params '[]
520527update_ tab columns wh = update tab columns wh (Returning_ Nil)
521528
522529{-----------------------------------------
523530DELETE statements
524531-----------------------------------------}
525532
526−data UsingClause db params from where
527− NoUsing :: UsingClause db params '[]
533+data UsingClause commons schemas params from where
534+ NoUsing :: UsingClause commons schemas params '[]
528535 Using
529− :: FromClause db params from
530− -> UsingClause db params from
536+ :: FromClause commons schemas params from
537+ -> UsingClause commons schemas params from
531538
532539-- | Delete rows from a table.
533540deleteFrom
@@ -538,11 +545,11 @@ deleteFrom
538545 , row0 ~ TableToRow table
539546 , columns ~ TableToColumns table )
540547 => QualifiedAlias sch tab -- ^ table to delete from
541− -> UsingClause db params from
542− -> Condition db params 'Ungrouped (tab ::: row0 ': from)
548+ -> UsingClause commons schemas params from
549+ -> Condition commons schemas params 'Ungrouped (tab ::: row0 ': from)
543550 -- ^ condition under which to delete a row
544− -> ReturningClause db params '[tab ::: row0] row1 -- ^ results to return
545− -> Manipulation db params row1
551+ -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
552+ -> Manipulation commons schemas params row1
546553deleteFrom tab using wh returning = UnsafeManipulation $
547554 "DELETE FROM"
548555 <+> renderSQL tab
@@ -560,10 +567,10 @@ deleteFrom_
560567 , row ~ TableToRow table
561568 , columns ~ TableToColumns table )
562569 => QualifiedAlias sch tab -- ^ table to delete from
563− -> UsingClause db params from
564− -> Condition db params 'Ungrouped (tab ::: row ': from)
570+ -> UsingClause commons schemas params from
571+ -> Condition commons schemas params 'Ungrouped (tab ::: row ': from)
565572 -- ^ condition under which to delete a row
566− -> Manipulation db params '[]
573+ -> Manipulation commons schemas params '[]
567574deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
568575
569576-- | This has the behaviour of a cartesian product, taking all
@@ -572,10 +579,10 @@ deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
572579-- a comma separated list of tables. Typical case is the `USING` clause
573580-- of a DELETE query.
574581also
575− :: FromClause schema params right
582+ :: FromClause commons schemas params right
576583 -- ^ right
577− -> FromClause schema params left
584+ -> FromClause commons schemas params left
578585 -- ^ left
579− -> FromClause schema params (Join left right)
586+ -> FromClause commons schemas params (Join left right)
580587also right left = UnsafeFromClause $
581588 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+286−281
@@ -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)
@@ -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:}
@@ -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