on dev help sign in
Merge pull request #88 from morphismtech/dev-underscore
fb99bd2Eitan Chatav
squeal-postgresql/exe/Example.hs+3−5
@@ -43,8 +43,6 @@ type Schema =
43
43
44type Schemas = Public Schema
44type Schemas = Public Schema
45
45
46−type DB = DBof Schemas
47−
48setup :: Definition (Public '[]) Schemas
46setup :: Definition (Public '[]) Schemas
49setup =
47setup =
50 createTable #users
48 createTable #users
@@ -64,17 +62,17 @@ setup =
64teardown :: Definition Schemas (Public '[])
62teardown :: Definition Schemas (Public '[])
65teardown = dropTable #emails >>> dropTable #users
63teardown = dropTable #emails >>> dropTable #users
66
64
67−insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
65+insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
68 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
66 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
69insertUser = insertInto #users
67insertUser = insertInto #users
70 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))
68 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))
71 (OnConflict (OnConstraint #pk_users) DoNothing) (Returning_ (#id `as` #fromOnly))
69 (OnConflict (OnConstraint #pk_users) DoNothing) (Returning_ (#id `as` #fromOnly))
72
70
73−insertEmail :: Manipulation DB '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
71+insertEmail :: Manipulation '[] Schemas '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
74insertEmail = insertInto_ #emails
72insertEmail = insertInto_ #emails
75 (Values_ (defaultAs #id :* param @1 `as` #user_id :* param @2 `as` #email))
73 (Values_ (defaultAs #id :* param @1 `as` #user_id :* param @2 `as` #email))
76
74
77−getUsers :: Query DB '[]
75+getUsers :: Query '[] Schemas '[]
78 '[ "userName" ::: 'NotNull 'PGtext
76 '[ "userName" ::: 'NotNull 'PGtext
79 , "userEmail" ::: 'Null 'PGtext
77 , "userEmail" ::: 'Null 'PGtext
80 , "userVec" ::: 'NotNull ('PGvararray ('Null 'PGint2))]
78 , "userVec" ::: 'NotNull ('PGvararray ('Null 'PGint2))]
squeal-postgresql/src/Squeal/PostgreSQL.hs+12−16
@@ -47,7 +47,6 @@ type Schema =
47 '[ "users" ::: 'Table (UsersConstraints :=> UsersColumns)
47 '[ "users" ::: 'Table (UsersConstraints :=> UsersColumns)
48 , "emails" ::: 'Table (EmailsConstraints :=> EmailsColumns) ]
48 , "emails" ::: 'Table (EmailsConstraints :=> EmailsColumns) ]
49type Schemas = Public Schema
49type Schemas = Public Schema
50−type DB = DBof Schemas
51:}
50:}
52
51
53Notice the use of type operators.
52Notice the use of type operators.
@@ -116,9 +115,18 @@ need to retrieve the user id that the insert generates and insert it into
116the emails table. Take a careful look at the type and definition of both
115the emails table. Take a careful look at the type and definition of both
117of our inserts.
116of our inserts.
118
117
118+We'll need a Haskell type for users. We give the type `Generics.SOP.Generic` and
119+`Generics.SOP.HasDatatypeInfo` instances so that we can decode the rows
120+we receive when we run @getUsers@. Notice that the record fields of the
121+@User@ type match the column names of @getUsers@.
122+
123+>>> data User = User { userName :: Text, userEmail :: Maybe Text } deriving (Show, GHC.Generic)
124+>>> instance SOP.Generic User
125+>>> instance SOP.HasDatatypeInfo User
126+
119>>> :{
127>>> :{
120let
128let
121− insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'Null 'PGtext ] '[]
129+ insertUser :: Manipulation_ Schemas User ()
122 insertUser = with (u `as` #u) e
130 insertUser = with (u `as` #u) e
123 where
131 where
124 u = insertInto #users
132 u = insertInto #users
@@ -138,9 +146,7 @@ need to use an inner join to get the right result. A `Query` is like a
138
146
139>>> :{
147>>> :{
140let
148let
141− getUsers :: Query DB '[]
149+ getUsers :: Query_ Schemas () User
142− '[ "userName" ::: 'NotNull 'PGtext
143− , "userEmail" ::: 'Null 'PGtext ]
144 getUsers = select_
150 getUsers = select_
145 (#u ! #name `as` #userName :* #e ! #email `as` #userEmail)
151 (#u ! #name `as` #userName :* #e ! #email `as` #userEmail)
146 ( from (table (#users `as` #u)
152 ( from (table (#users `as` #u)
@@ -151,17 +157,7 @@ let
151>>> printSQL getUsers
157>>> printSQL getUsers
152SELECT "u"."name" AS "userName", "e"."email" AS "userEmail" FROM "users" AS "u" INNER JOIN "emails" AS "e" ON ("u"."id" = "e"."user_id")
158SELECT "u"."name" AS "userName", "e"."email" AS "userEmail" FROM "users" AS "u" INNER JOIN "emails" AS "e" ON ("u"."id" = "e"."user_id")
153
159
154−Now that we've defined the SQL side of things, we'll need a Haskell type
155−for users. We give the type `Generics.SOP.Generic` and
156−`Generics.SOP.HasDatatypeInfo` instances so that we can decode the rows
157−we receive when we run @getUsers@. Notice that the record fields of the
158−@User@ type match the column names of @getUsers@.
159−
160−>>> data User = User { userName :: Text, userEmail :: Maybe Text } deriving (Show, GHC.Generic)
161−>>> instance SOP.Generic User
162−>>> instance SOP.HasDatatypeInfo User
163−
164−Let's also create some users to add to the database.
160+Let's create some users to add to the database.
165
161
166>>> :{
162>>> :{
167let
163let
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3
@@ -27,7 +27,7 @@ round trip query.
27>>> instance HasDatatypeInfo Row
27>>> instance HasDatatypeInfo Row
28>>> :{
28>>> :{
29let
29let
30− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
30+ roundTrip :: Query_ (Public '[]) Row Row
31 roundTrip = values_ $
31 roundTrip = values_ $
32 parameter @1 int2 `as` #col1 :*
32 parameter @1 int2 `as` #col1 :*
33 parameter @2 text `as` #col2 :*
33 parameter @2 text `as` #col2 :*
@@ -68,7 +68,7 @@ Once again, we define a simple round trip query.
68
68
69>>> :{
69>>> :{
70let
70let
71− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
71+ roundTrip :: Query_ (Public '[]) Row Row
72 roundTrip = values_ $
72 roundTrip = values_ $
73 parameter @1 (int2 & vararray) `as` #col1 :*
73 parameter @1 (int2 & vararray) `as` #col1 :*
74 parameter @2 (int2 & fixarray @2) `as` #col2 :*
74 parameter @2 (int2 & fixarray @2) `as` #col2 :*
@@ -146,7 +146,7 @@ Once again, define a round trip query.
146
146
147>>> :{
147>>> :{
148let
148let
149− roundTrip :: Query (DBof (Public Schema)) (TuplePG Row) (RowPG Row)
149+ roundTrip :: Query_ (Public Schema) Row Row
150 roundTrip = values_ $
150 roundTrip = values_ $
151 parameter @1 (typedef #schwarma) `as` #schwarma :*
151 parameter @1 (typedef #schwarma) `as` #schwarma :*
152 parameter @2 (typedef #person) `as` #person1 :*
152 parameter @2 (typedef #person) `as` #person1 :*
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+4−4
@@ -297,7 +297,7 @@ check
297 , HasAll aliases (TableToRow table) subcolumns )
297 , HasAll aliases (TableToRow table) subcolumns )
298 => NP Alias aliases
298 => NP Alias aliases
299 -- ^ specify the subcolumns which are getting checked
299 -- ^ specify the subcolumns which are getting checked
300− -> (forall t. Condition ('[] :=> schemas) '[] 'Ungrouped '[t ::: subcolumns])
300+ -> (forall t. Condition '[] schemas '[] 'Ungrouped '[t ::: subcolumns])
301 -- ^ a closed `Condition` on those subcolumns
301 -- ^ a closed `Condition` on those subcolumns
302 -> TableConstraintExpression sch tab schemas ('Check aliases)
302 -> TableConstraintExpression sch tab schemas ('Check aliases)
303check _cols condition = UnsafeTableConstraintExpression $
303check _cols condition = UnsafeTableConstraintExpression $
@@ -758,7 +758,7 @@ newtype AlterColumn (schemas :: SchemasType) (ty0 :: ColumnType) (ty1 :: ColumnT
758-- :}
758-- :}
759-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
759-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
760setDefault
760setDefault
761− :: Expression ('[] :=> schemas) '[] 'Ungrouped '[] ty -- ^ default value to set
761+ :: Expression '[] schemas '[] 'Ungrouped '[] ty -- ^ default value to set
762 -> AlterColumn schemas (constraint :=> ty) ('Def :=> ty)
762 -> AlterColumn schemas (constraint :=> ty) ('Def :=> ty)
763setDefault expression = UnsafeAlterColumn $
763setDefault expression = UnsafeAlterColumn $
764 "SET DEFAULT" <+> renderExpression expression
764 "SET DEFAULT" <+> renderExpression expression
@@ -843,7 +843,7 @@ CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
843createView
843createView
844 :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
844 :: (KnownSymbol sch, KnownSymbol vw, Has sch schemas schema)
845 => QualifiedAlias sch vw -- ^ the name of the view to add
845 => QualifiedAlias sch vw -- ^ the name of the view to add
846− -> Query ('[] :=> schemas) '[] view -- ^ query
846+ -> Query '[] schemas '[] view -- ^ query
847 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
847 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
848createView alias query = UnsafeDefinition $
848createView alias query = UnsafeDefinition $
849 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
849 "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
@@ -1009,7 +1009,7 @@ notNullable ty = UnsafeColumnTypeExpression $ renderSQL ty <+> "NOT NULL"
1009
1009
1010-- | used in `createTable` commands as a column constraint to give a default
1010-- | used in `createTable` commands as a column constraint to give a default
1011default_
1011default_
1012− :: Expression ('[] :=> schemas) '[] 'Ungrouped '[] ty
1012+ :: Expression '[] schemas '[] 'Ungrouped '[] ty
1013 -> ColumnTypeExpression schemas ('NoDef :=> ty)
1013 -> ColumnTypeExpression schemas ('NoDef :=> ty)
1014 -> ColumnTypeExpression schemas ('Def :=> ty)
1014 -> ColumnTypeExpression schemas ('Def :=> ty)
1015default_ x ty = UnsafeColumnTypeExpression $
1015default_ x ty = UnsafeColumnTypeExpression $
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+308−308
@@ -218,7 +218,8 @@ values from primitive expression using arithmetic, logical,
218and other operations.
218and other operations.
219-}
219-}
220newtype Expression
220newtype Expression
221− (db :: DBType)
221+ (commons :: FromType)
222+ (schemas :: SchemasType)
222 (params :: [NullityType])
223 (params :: [NullityType])
223 (grp :: Grouping)
224 (grp :: Grouping)
224 (from :: FromType)
225 (from :: FromType)
@@ -226,7 +227,7 @@ newtype Expression
226 = UnsafeExpression { renderExpression :: ByteString }
227 = UnsafeExpression { renderExpression :: ByteString }
227 deriving (GHC.Generic,Show,Eq,Ord,NFData)
228 deriving (GHC.Generic,Show,Eq,Ord,NFData)
228
229
229−instance RenderSQL (Expression db params grp from ty) where
230+instance RenderSQL (Expression commons schemas params grp from ty) where
230 renderSQL = renderExpression
231 renderSQL = renderExpression
231
232
232{- | A `HasParameter` constraint is used to indicate a value that is
233{- | A `HasParameter` constraint is used to indicate a value that is
@@ -244,12 +245,12 @@ class KnownNat n => HasParameter
244 | n params -> ty where
245 | n params -> ty where
245 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
246 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
246 --
247 --
247− -- >>> let expr = parameter @1 int4 :: Expression (DBof schemas) '[ 'Null 'PGint4] grp from ('Null 'PGint4)
248+ -- >>> let expr = parameter @1 int4 :: Expression '[] schemas '[ 'Null 'PGint4] grp from ('Null 'PGint4)
248 -- >>> printSQL expr
249 -- >>> printSQL expr
249 -- ($1 :: int4)
250 -- ($1 :: int4)
250 parameter
251 parameter
251 :: TypeExpression schemas ty
252 :: TypeExpression schemas ty
252− -> Expression (commons :=> schemas) params grp from ty
253+ -> Expression commons schemas params grp from ty
253 parameter ty = UnsafeExpression $ parenthesized $
254 parameter ty = UnsafeExpression $ parenthesized $
254 "$" <> renderNat @n <+> "::"
255 "$" <> renderNat @n <+> "::"
255 <+> renderSQL ty
256 <+> renderSQL ty
@@ -260,38 +261,38 @@ instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
260-- | `param` takes a `Nat` using type application and for basic types,
261-- | `param` takes a `Nat` using type application and for basic types,
261-- infers a `TypeExpression`.
262-- infers a `TypeExpression`.
262--
263--
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)
264-- >>> printSQL expr
265-- >>> printSQL expr
265-- ($1 :: int4)
266-- ($1 :: int4)
266param
267param
267− :: forall n db commons schemas params from grp ty
268+ :: forall n commons schemas params from grp ty
268− . (db ~ (commons :=> schemas), PGTyped schemas ty, HasParameter n params ty)
269+ . (PGTyped schemas ty, HasParameter n params ty)
269− => Expression db params grp from ty -- ^ param
270+ => Expression commons schemas params grp from ty -- ^ param
270param = parameter @n (pgtype @schemas)
271param = parameter @n (pgtype @schemas)
271
272
272instance (HasUnique tab from row, Has col row ty)
273instance (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
274 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
275 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
275instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
276instance (HasUnique tab from row, Has col row ty, column ~ (col ::: ty))
276 => IsLabel col
277 => IsLabel col
277− (Aliased (Expression db params 'Ungrouped from) column) where
278+ (Aliased (Expression commons schemas params 'Ungrouped from) column) where
278 fromLabel = fromLabel @col `As` Alias
279 fromLabel = fromLabel @col `As` Alias
279instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: ty])
280instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: ty])
280 => IsLabel col
281 => IsLabel col
281− (NP (Aliased (Expression db params 'Ungrouped from)) columns) where
282+ (NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns) where
282 fromLabel = fromLabel @col :* Nil
283 fromLabel = fromLabel @col :* Nil
283
284
284instance (Has tab from row, Has col row ty)
285instance (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
286 tab ! col = UnsafeExpression $
287 tab ! col = UnsafeExpression $
287 renderSQL tab <> "." <> renderSQL col
288 renderSQL tab <> "." <> renderSQL col
288instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
289instance (Has tab from row, Has col row ty, column ~ (col ::: ty))
289 => IsQualified tab col
290 => IsQualified tab col
290− (Aliased (Expression db params 'Ungrouped from) column) where
291+ (Aliased (Expression commons schemas params 'Ungrouped from) column) where
291 tab ! col = tab ! col `As` col
292 tab ! col = tab ! col `As` col
292instance (Has tab from row, Has col row ty, columns ~ '[col ::: ty])
293instance (Has tab from row, Has col row ty, columns ~ '[col ::: ty])
293 => IsQualified tab col
294 => IsQualified tab col
294− (NP (Aliased (Expression db params 'Ungrouped from)) columns) where
295+ (NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns) where
295 tab ! col = tab ! col :* Nil
296 tab ! col = tab ! col :* Nil
296
297
297instance
298instance
@@ -299,7 +300,7 @@ instance
299 , Has col row ty
300 , Has col row ty
300 , GroupedBy tab col bys
301 , GroupedBy tab col bys
301 ) => IsLabel col
302 ) => IsLabel col
302− (Expression db params ('Grouped bys) from ty) where
303+ (Expression commons schemas params ('Grouped bys) from ty) where
303 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
304 fromLabel = UnsafeExpression $ renderSQL (Alias @col)
304instance
305instance
305 ( HasUnique tab from row
306 ( HasUnique tab from row
@@ -307,7 +308,7 @@ instance
307 , GroupedBy tab col bys
308 , GroupedBy tab col bys
308 , column ~ (col ::: ty)
309 , column ~ (col ::: ty)
309 ) => IsLabel col
310 ) => IsLabel col
310− (Aliased (Expression db params ('Grouped bys) from) column) where
311+ (Aliased (Expression commons schemas params ('Grouped bys) from) column) where
311 fromLabel = fromLabel @col `As` Alias
312 fromLabel = fromLabel @col `As` Alias
312instance
313instance
313 ( HasUnique tab from row
314 ( HasUnique tab from row
@@ -315,7 +316,7 @@ instance
315 , GroupedBy tab col bys
316 , GroupedBy tab col bys
316 , columns ~ '[col ::: ty]
317 , columns ~ '[col ::: ty]
317 ) => IsLabel col
318 ) => 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
319 fromLabel = fromLabel @col :* Nil
320 fromLabel = fromLabel @col :* Nil
320
321
321instance
322instance
@@ -323,7 +324,7 @@ instance
323 , Has col row ty
324 , Has col row ty
324 , GroupedBy tab col bys
325 , GroupedBy tab col bys
325 ) => IsQualified tab col
326 ) => IsQualified tab col
326− (Expression db params ('Grouped bys) from ty) where
327+ (Expression commons schemas params ('Grouped bys) from ty) where
327 tab ! col = UnsafeExpression $
328 tab ! col = UnsafeExpression $
328 renderSQL tab <> "." <> renderSQL col
329 renderSQL tab <> "." <> renderSQL col
329instance
330instance
@@ -332,7 +333,7 @@ instance
332 , GroupedBy tab col bys
333 , GroupedBy tab col bys
333 , column ~ (col ::: ty)
334 , column ~ (col ::: ty)
334 ) => IsQualified tab col
335 ) => IsQualified tab col
335− (Aliased (Expression db params ('Grouped bys) from) column) where
336+ (Aliased (Expression commons schemas params ('Grouped bys) from) column) where
336 tab ! col = tab ! col `As` col
337 tab ! col = tab ! col `As` col
337instance
338instance
338 ( Has tab from row
339 ( Has tab from row
@@ -340,14 +341,14 @@ instance
340 , GroupedBy tab col bys
341 , GroupedBy tab col bys
341 , columns ~ '[col ::: ty]
342 , columns ~ '[col ::: ty]
342 ) => IsQualified tab col
343 ) => 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
344 tab ! col = tab ! col :* Nil
345 tab ! col = tab ! col :* Nil
345
346
346-- | analagous to `Nothing`
347-- | analagous to `Nothing`
347--
348--
348-- >>> printSQL null_
349-- >>> printSQL null_
349-- NULL
350-- NULL
350−null_ :: Expression db rels grouping params ('Null ty)
351+null_ :: Expression commons schemas rels grouping params ('Null ty)
351null_ = UnsafeExpression "NULL"
352null_ = UnsafeExpression "NULL"
352
353
353-- | analagous to `Just`
354-- | analagous to `Just`
@@ -355,8 +356,8 @@ null_ = UnsafeExpression "NULL"
355-- >>> printSQL $ notNull true
356-- >>> printSQL $ notNull true
356-- TRUE
357-- TRUE
357notNull
358notNull
358− :: Expression db rels grouping params ('NotNull ty)
359+ :: Expression commons schemas rels grouping params ('NotNull ty)
359− -> Expression db rels grouping params ('Null ty)
360+ -> Expression commons schemas rels grouping params ('Null ty)
360notNull = UnsafeExpression . renderSQL
361notNull = UnsafeExpression . renderSQL
361
362
362-- | return the leftmost value which is not NULL
363-- | return the leftmost value which is not NULL
@@ -364,11 +365,11 @@ notNull = UnsafeExpression . renderSQL
364-- >>> printSQL $ coalesce [null_, true] false
365-- >>> printSQL $ coalesce [null_, true] false
365-- COALESCE(NULL, TRUE, FALSE)
366-- COALESCE(NULL, TRUE, FALSE)
366coalesce
367coalesce
367− :: [Expression db params grp from ('Null ty)]
368+ :: [Expression commons schemas params grp from ('Null ty)]
368 -- ^ @NULL@s may be present
369 -- ^ @NULL@s may be present
369− -> Expression db params grp from ('NotNull ty)
370+ -> Expression commons schemas params grp from ('NotNull ty)
370 -- ^ @NULL@ is absent
371 -- ^ @NULL@ is absent
371− -> Expression db params grp from ('NotNull ty)
372+ -> Expression commons schemas params grp from ('NotNull ty)
372coalesce nullxs notNullx = UnsafeExpression $
373coalesce nullxs notNullx = UnsafeExpression $
373 "COALESCE" <> parenthesized (commaSeparated
374 "COALESCE" <> parenthesized (commaSeparated
374 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
375 ((renderSQL <$> nullxs) <> [renderSQL notNullx]))
@@ -378,26 +379,26 @@ coalesce nullxs notNullx = UnsafeExpression $
378-- >>> printSQL $ fromNull true null_
379-- >>> printSQL $ fromNull true null_
379-- COALESCE(NULL, TRUE)
380-- COALESCE(NULL, TRUE)
380fromNull
381fromNull
381− :: Expression db params grp from ('NotNull ty)
382+ :: Expression commons schemas params grp from ('NotNull ty)
382 -- ^ what to convert @NULL@ to
383 -- ^ what to convert @NULL@ to
383− -> Expression db params grp from ('Null ty)
384+ -> Expression commons schemas params grp from ('Null ty)
384− -> Expression db params grp from ('NotNull ty)
385+ -> Expression commons schemas params grp from ('NotNull ty)
385fromNull notNullx nullx = coalesce [nullx] notNullx
386fromNull notNullx nullx = coalesce [nullx] notNullx
386
387
387-- | >>> printSQL $ null_ & isNull
388-- | >>> printSQL $ null_ & isNull
388-- NULL IS NULL
389-- NULL IS NULL
389isNull
390isNull
390− :: Expression db params grp from ('Null ty)
391+ :: Expression commons schemas params grp from ('Null ty)
391 -- ^ possibly @NULL@
392 -- ^ possibly @NULL@
392− -> Condition db params grp from
393+ -> Condition commons schemas params grp from
393isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
394isNull x = UnsafeExpression $ renderSQL x <+> "IS NULL"
394
395
395-- | >>> printSQL $ null_ & isNotNull
396-- | >>> printSQL $ null_ & isNotNull
396-- NULL IS NOT NULL
397-- NULL IS NOT NULL
397isNotNull
398isNotNull
398− :: Expression db params grp from ('Null ty)
399+ :: Expression commons schemas params grp from ('Null ty)
399 -- ^ possibly @NULL@
400 -- ^ possibly @NULL@
400− -> Condition db params grp from
401+ -> Condition commons schemas params grp from
401isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
402isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
402
403
403-- | analagous to `maybe` using @IS NULL@
404-- | analagous to `maybe` using @IS NULL@
@@ -405,13 +406,13 @@ isNotNull x = UnsafeExpression $ renderSQL x <+> "IS NOT NULL"
405-- >>> printSQL $ matchNull true not_ null_
406-- >>> printSQL $ matchNull true not_ null_
406-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
407matchNull
408matchNull
408− :: Expression db params grp from (nullty)
409+ :: Expression commons schemas params grp from (nullty)
409 -- ^ what to convert @NULL@ to
410 -- ^ what to convert @NULL@ to
410− -> ( Expression db params grp from ('NotNull ty)
411+ -> ( Expression commons schemas params grp from ('NotNull ty)
411− -> Expression db params grp from (nullty) )
412+ -> Expression commons schemas params grp from (nullty) )
412 -- ^ function to perform when @NULL@ is absent
413 -- ^ function to perform when @NULL@ is absent
413− -> Expression db params grp from ('Null ty)
414+ -> Expression commons schemas params grp from ('Null ty)
414− -> Expression db params grp from (nullty)
415+ -> Expression commons schemas params grp from (nullty)
415matchNull y f x = ifThenElse (isNull x) y
416matchNull y f x = ifThenElse (isNull x) y
416 (f (UnsafeExpression (renderSQL x)))
417 (f (UnsafeExpression (renderSQL x)))
417
418
@@ -419,25 +420,25 @@ matchNull y f x = ifThenElse (isNull x) y
419`nullIf` gives @NULL@.
420`nullIf` gives @NULL@.
420
421
421>>> :set -XTypeApplications -XDataKinds
422>>> :set -XTypeApplications -XDataKinds
422−>>> let expr = nullIf false (param @1) :: Expression (commons :=> schema) '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
423+>>> let expr = nullIf false (param @1) :: Expression commons schemas '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
423>>> printSQL expr
424>>> printSQL expr
424NULL IF (FALSE, ($1 :: bool))
425NULL IF (FALSE, ($1 :: bool))
425-}
426-}
426nullIf
427nullIf
427− :: Expression db params grp from ('NotNull ty)
428+ :: Expression commons schemas params grp from ('NotNull ty)
428 -- ^ @NULL@ is absent
429 -- ^ @NULL@ is absent
429− -> Expression db params grp from ('NotNull ty)
430+ -> Expression commons schemas params grp from ('NotNull ty)
430 -- ^ @NULL@ is absent
431 -- ^ @NULL@ is absent
431− -> Expression db params grp from ('Null ty)
432+ -> Expression commons schemas params grp from ('Null ty)
432nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
433nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
433 (renderSQL x <> ", " <> renderSQL y)
434 (renderSQL x <> ", " <> renderSQL y)
434
435
435-- | >>> printSQL $ array [null_, false, true]
436-- | >>> printSQL $ array [null_, false, true]
436-- ARRAY[NULL, FALSE, TRUE]
437-- ARRAY[NULL, FALSE, TRUE]
437array
438array
438− :: [Expression db params grp from ty]
439+ :: [Expression commons schemas params grp from ty]
439 -- ^ array elements
440 -- ^ array elements
440− -> Expression db params grp from (nullity ('PGvararray ty))
441+ -> Expression commons schemas params grp from (nullity ('PGvararray ty))
441array xs = UnsafeExpression $
442array xs = UnsafeExpression $
442 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
443 "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
443
444
@@ -445,13 +446,13 @@ array xs = UnsafeExpression $
445-- (ARRAY[NULL, FALSE, TRUE])[2]
446-- (ARRAY[NULL, FALSE, TRUE])[2]
446index
447index
447 :: Word64 -- ^ index
448 :: Word64 -- ^ index
448− -> Expression db params grp from (nullity ('PGvararray ty)) -- ^ array
449+ -> Expression commons schemas params grp from (nullity ('PGvararray ty)) -- ^ array
449− -> Expression db params grp from (NullifyType ty)
450+ -> Expression commons schemas params grp from (NullifyType ty)
450index n expr = UnsafeExpression $
451index n expr = UnsafeExpression $
451 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
452 parenthesized (renderSQL expr) <> "[" <> fromString (show n) <> "]"
452
453
453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
454instance (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
455 label = UnsafeExpression $ renderSQL (PGlabel @label)
456 label = UnsafeExpression $ renderSQL (PGlabel @label)
456
457
457-- | A row constructor is an expression that builds a row value
458-- | A row constructor is an expression that builds a row value
@@ -463,14 +464,14 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
463-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
464-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
464-- :}
465-- :}
465--
466--
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)
467-- >>> printSQL i
468-- >>> printSQL i
468-- ROW(0, 1)
469-- ROW(0, 1)
469row
470row
470 :: SListI row
471 :: SListI row
471− => NP (Aliased (Expression db params grp from)) row
472+ => NP (Aliased (Expression commons schemas params grp from)) row
472 -- ^ zero or more expressions for the row field values
473 -- ^ 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))
474row exprs = UnsafeExpression $ "ROW" <> parenthesized
475row exprs = UnsafeExpression $ "ROW" <> parenthesized
475 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
476 (renderCommaSeparated (\ (expr `As` _) -> renderSQL expr) exprs)
476
477
@@ -479,10 +480,9 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
479-- '[ "real" ::: 'NotNull 'PGfloat8
480-- '[ "real" ::: 'NotNull 'PGfloat8
480-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
481-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
481-- type Schema = '["complex" ::: 'Typedef Complex]
482-- type Schema = '["complex" ::: 'Typedef Complex]
482−-- type DB = DBof (Public Schema)
483-- :}
483-- :}
484--
484--
485−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression DB from grp params ('NotNull Complex)
485+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] (Public Schema) from grp params ('NotNull Complex)
486-- >>> printSQL $ i & field #complex #imaginary
486-- >>> printSQL $ i & field #complex #imaginary
487-- (ROW(0, 1)::"complex")."imaginary"
487-- (ROW(0, 1)::"complex")."imaginary"
488field
488field
@@ -491,41 +491,41 @@ field
491 , Has field row ty)
491 , Has field row ty)
492 => QualifiedAlias sch tydef -- ^ row type
492 => QualifiedAlias sch tydef -- ^ row type
493 -> Alias field -- ^ field name
493 -> Alias field -- ^ field name
494− -> Expression (commons :=> schemas) params grp from ('NotNull ('PGcomposite row))
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 ty
496field td fld expr = UnsafeExpression $
496field td fld expr = UnsafeExpression $
497 parenthesized (renderSQL expr <> "::" <> renderSQL td)
497 parenthesized (renderSQL expr <> "::" <> renderSQL td)
498 <> "." <> renderSQL fld
498 <> "." <> renderSQL fld
499
499
500instance Semigroup
500instance Semigroup
501− (Expression db params grp from (nullity ('PGvararray ty))) where
501+ (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
502 (<>) = unsafeBinaryOp "||"
502 (<>) = unsafeBinaryOp "||"
503
503
504instance Monoid
504instance Monoid
505− (Expression db params grp from (nullity ('PGvararray ty))) where
505+ (Expression commons schemas params grp from (nullity ('PGvararray ty))) where
506 mempty = array []
506 mempty = array []
507 mappend = (<>)
507 mappend = (<>)
508
508
509−-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression (commons :=> schemas) '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
509+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression commons schemas '[ 'NotNull 'PGtimestamptz] grp from ('NotNull 'PGtimestamptz)
510-- >>> printSQL expr
510-- >>> printSQL expr
511-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
511-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
512greatest
512greatest
513− :: Expression db params grp from (nullty)
513+ :: Expression commons schemas params grp from (nullty)
514 -- ^ needs at least 1 argument
514 -- ^ needs at least 1 argument
515− -> [Expression db params grp from (nullty)]
515+ -> [Expression commons schemas params grp from (nullty)]
516 -- ^ or more
516 -- ^ or more
517− -> Expression db params grp from (nullty)
517+ -> Expression commons schemas params grp from (nullty)
518greatest x xs = UnsafeExpression $ "GREATEST("
518greatest x xs = UnsafeExpression $ "GREATEST("
519 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
519 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
520
520
521-- | >>> printSQL $ least currentTimestamp [null_]
521-- | >>> printSQL $ least currentTimestamp [null_]
522-- LEAST(CURRENT_TIMESTAMP, NULL)
522-- LEAST(CURRENT_TIMESTAMP, NULL)
523least
523least
524− :: Expression db params grp from (nullty)
524+ :: Expression commons schemas params grp from (nullty)
525 -- ^ needs at least 1 argument
525 -- ^ needs at least 1 argument
526− -> [Expression db params grp from (nullty)]
526+ -> [Expression commons schemas params grp from (nullty)]
527 -- ^ or more
527 -- ^ or more
528− -> Expression db params grp from (nullty)
528+ -> Expression commons schemas params grp from (nullty)
529least x xs = UnsafeExpression $ "LEAST("
529least x xs = UnsafeExpression $ "LEAST("
530 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
530 <> commaSeparated (renderSQL <$> (x:xs)) <> ")"
531
531
@@ -534,9 +534,9 @@ least x xs = UnsafeExpression $ "LEAST("
534unsafeBinaryOp
534unsafeBinaryOp
535 :: ByteString
535 :: ByteString
536 -- ^ operator
536 -- ^ operator
537− -> Expression db params grp from (ty0)
537+ -> Expression commons schemas params grp from (ty0)
538− -> Expression db params grp from (ty1)
538+ -> Expression commons schemas params grp from (ty1)
539− -> Expression db params grp from (ty2)
539+ -> Expression commons schemas params grp from (ty2)
540unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
540unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
541 renderSQL x <+> op <+> renderSQL y
541 renderSQL x <+> op <+> renderSQL y
542
542
@@ -545,8 +545,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
545unsafeUnaryOp
545unsafeUnaryOp
546 :: ByteString
546 :: ByteString
547 -- ^ operator
547 -- ^ operator
548− -> Expression db params grp from (ty0)
548+ -> Expression commons schemas params grp from (ty0)
549− -> Expression db params grp from (ty1)
549+ -> Expression commons schemas params grp from (ty1)
550unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
550unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
551 op <+> renderSQL x
551 op <+> renderSQL x
552
552
@@ -555,8 +555,8 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
555unsafeFunction
555unsafeFunction
556 :: ByteString
556 :: ByteString
557 -- ^ function
557 -- ^ function
558− -> Expression db params grp from (xty)
558+ -> Expression commons schemas params grp from (xty)
559− -> Expression db params grp from (yty)
559+ -> Expression commons schemas params grp from (yty)
560unsafeFunction fun x = UnsafeExpression $
560unsafeFunction fun x = UnsafeExpression $
561 fun <> parenthesized (renderSQL x)
561 fun <> parenthesized (renderSQL x)
562
562
@@ -565,13 +565,13 @@ unsafeVariadicFunction
565 :: SListI elems
565 :: SListI elems
566 => ByteString
566 => ByteString
567 -- ^ function
567 -- ^ function
568− -> NP (Expression db params grp from) elems
568+ -> NP (Expression commons schemas params grp from) elems
569− -> Expression db params grp from ret
569+ -> Expression commons schemas params grp from ret
570unsafeVariadicFunction fun x = UnsafeExpression $
570unsafeVariadicFunction fun x = UnsafeExpression $
571 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
571 fun <> parenthesized (commaSeparated (hcollapse (hmap (K . renderSQL) x)))
572
572
573instance ty `In` PGNum
573instance ty `In` PGNum
574− => Num (Expression db params grp from (nullity ty)) where
574+ => Num (Expression commons schemas params grp from (nullity ty)) where
575 (+) = unsafeBinaryOp "+"
575 (+) = unsafeBinaryOp "+"
576 (-) = unsafeBinaryOp "-"
576 (-) = unsafeBinaryOp "-"
577 (*) = unsafeBinaryOp "*"
577 (*) = unsafeBinaryOp "*"
@@ -583,12 +583,12 @@ instance ty `In` PGNum
583 . show
583 . show
584
584
585instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
585instance (ty `In` PGNum, ty `In` PGFloating) => Fractional
586− (Expression db params grp from (nullity ty)) where
586+ (Expression commons schemas params grp from (nullity ty)) where
587 (/) = unsafeBinaryOp "/"
587 (/) = unsafeBinaryOp "/"
588 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
588 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
589
589
590instance (ty `In` PGNum, ty `In` PGFloating) => Floating
590instance (ty `In` PGNum, ty `In` PGFloating) => Floating
591− (Expression db params grp from (nullity ty)) where
591+ (Expression commons schemas params grp from (nullity ty)) where
592 pi = UnsafeExpression "pi()"
592 pi = UnsafeExpression "pi()"
593 exp = unsafeFunction "exp"
593 exp = unsafeFunction "exp"
594 log = unsafeFunction "ln"
594 log = unsafeFunction "ln"
@@ -611,18 +611,18 @@ instance (ty `In` PGNum, ty `In` PGFloating) => Floating
611
611
612-- | >>> :{
612-- | >>> :{
613-- let
613-- let
614−-- expression :: Expression db params grp from (nullity 'PGfloat4)
614+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
615-- expression = atan2_ pi 2
615-- expression = atan2_ pi 2
616-- in printSQL expression
616-- in printSQL expression
617-- :}
617-- :}
618-- atan2(pi(), 2)
618-- atan2(pi(), 2)
619atan2_
619atan2_
620 :: float `In` PGFloating
620 :: float `In` PGFloating
621− => Expression db params grp from (nullity float)
621+ => Expression commons schemas params grp from (nullity float)
622 -- ^ numerator
622 -- ^ numerator
623− -> Expression db params grp from (nullity float)
623+ -> Expression commons schemas params grp from (nullity float)
624 -- ^ denominator
624 -- ^ denominator
625− -> Expression db params grp from (nullity float)
625+ -> Expression commons schemas params grp from (nullity float)
626atan2_ y x = UnsafeExpression $
626atan2_ y x = UnsafeExpression $
627 "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
627 "atan2(" <> renderSQL y <> ", " <> renderSQL x <> ")"
628
628
@@ -635,9 +635,9 @@ atan2_ y x = UnsafeExpression $
635cast
635cast
636 :: TypeExpression schemas ty1
636 :: TypeExpression schemas ty1
637 -- ^ type to cast as
637 -- ^ type to cast as
638− -> Expression (commons :=> schemas) params grp from ty0
638+ -> Expression commons schemas params grp from ty0
639 -- ^ value to convert
639 -- ^ value to convert
640− -> Expression (commons :=> schemas) params grp from ty1
640+ -> Expression commons schemas params grp from ty1
641cast ty x = UnsafeExpression $ parenthesized $
641cast ty x = UnsafeExpression $ parenthesized $
642 renderSQL x <+> "::" <+> renderSQL ty
642 renderSQL x <+> "::" <+> renderSQL ty
643
643
@@ -645,136 +645,136 @@ cast ty x = UnsafeExpression $ parenthesized $
645--
645--
646-- >>> :{
646-- >>> :{
647-- let
647-- let
648−-- expression :: Expression db params grp from (nullity 'PGint2)
648+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
649-- expression = 5 `quot_` 2
649-- expression = 5 `quot_` 2
650-- in printSQL expression
650-- in printSQL expression
651-- :}
651-- :}
652-- (5 / 2)
652-- (5 / 2)
653quot_
653quot_
654 :: int `In` PGIntegral
654 :: int `In` PGIntegral
655− => Expression db params grp from (nullity int)
655+ => Expression commons schemas params grp from (nullity int)
656 -- ^ numerator
656 -- ^ numerator
657− -> Expression db params grp from (nullity int)
657+ -> Expression commons schemas params grp from (nullity int)
658 -- ^ denominator
658 -- ^ denominator
659− -> Expression db params grp from (nullity int)
659+ -> Expression commons schemas params grp from (nullity int)
660quot_ = unsafeBinaryOp "/"
660quot_ = unsafeBinaryOp "/"
661
661
662-- | remainder upon integer division
662-- | remainder upon integer division
663--
663--
664-- >>> :{
664-- >>> :{
665-- let
665-- let
666−-- expression :: Expression db params grp from (nullity 'PGint2)
666+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
667-- expression = 5 `rem_` 2
667-- expression = 5 `rem_` 2
668-- in printSQL expression
668-- in printSQL expression
669-- :}
669-- :}
670-- (5 % 2)
670-- (5 % 2)
671rem_
671rem_
672 :: int `In` PGIntegral
672 :: int `In` PGIntegral
673− => Expression db params grp from (nullity int)
673+ => Expression commons schemas params grp from (nullity int)
674 -- ^ numerator
674 -- ^ numerator
675− -> Expression db params grp from (nullity int)
675+ -> Expression commons schemas params grp from (nullity int)
676 -- ^ denominator
676 -- ^ denominator
677− -> Expression db params grp from (nullity int)
677+ -> Expression commons schemas params grp from (nullity int)
678rem_ = unsafeBinaryOp "%"
678rem_ = unsafeBinaryOp "%"
679
679
680-- | >>> :{
680-- | >>> :{
681-- let
681-- let
682−-- expression :: Expression db params grp from (nullity 'PGfloat4)
682+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
683-- expression = trunc pi
683-- expression = trunc pi
684-- in printSQL expression
684-- in printSQL expression
685-- :}
685-- :}
686-- trunc(pi())
686-- trunc(pi())
687trunc
687trunc
688 :: frac `In` PGFloating
688 :: frac `In` PGFloating
689− => Expression db params grp from (nullity frac)
689+ => Expression commons schemas params grp from (nullity frac)
690 -- ^ fractional number
690 -- ^ fractional number
691− -> Expression db params grp from (nullity frac)
691+ -> Expression commons schemas params grp from (nullity frac)
692trunc = unsafeFunction "trunc"
692trunc = unsafeFunction "trunc"
693
693
694-- | >>> :{
694-- | >>> :{
695-- let
695-- let
696−-- expression :: Expression db params grp from (nullity 'PGfloat4)
696+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
697-- expression = round_ pi
697-- expression = round_ pi
698-- in printSQL expression
698-- in printSQL expression
699-- :}
699-- :}
700-- round(pi())
700-- round(pi())
701round_
701round_
702 :: frac `In` PGFloating
702 :: frac `In` PGFloating
703− => Expression db params grp from (nullity frac)
703+ => Expression commons schemas params grp from (nullity frac)
704 -- ^ fractional number
704 -- ^ fractional number
705− -> Expression db params grp from (nullity frac)
705+ -> Expression commons schemas params grp from (nullity frac)
706round_ = unsafeFunction "round"
706round_ = unsafeFunction "round"
707
707
708-- | >>> :{
708-- | >>> :{
709-- let
709-- let
710−-- expression :: Expression db params grp from (nullity 'PGfloat4)
710+-- expression :: Expression commons schemas params grp from (nullity 'PGfloat4)
711-- expression = ceiling_ pi
711-- expression = ceiling_ pi
712-- in printSQL expression
712-- in printSQL expression
713-- :}
713-- :}
714-- ceiling(pi())
714-- ceiling(pi())
715ceiling_
715ceiling_
716 :: frac `In` PGFloating
716 :: frac `In` PGFloating
717− => Expression db params grp from (nullity frac)
717+ => Expression commons schemas params grp from (nullity frac)
718 -- ^ fractional number
718 -- ^ fractional number
719− -> Expression db params grp from (nullity frac)
719+ -> Expression commons schemas params grp from (nullity frac)
720ceiling_ = unsafeFunction "ceiling"
720ceiling_ = unsafeFunction "ceiling"
721
721
722-- | A `Condition` is an `Expression`, which can evaluate
722-- | A `Condition` is an `Expression`, which can evaluate
723-- to `true`, `false` or `null_`. This is because SQL uses
723-- to `true`, `false` or `null_`. This is because SQL uses
724-- a three valued logic.
724-- a three valued logic.
725−type Condition db params grp from =
725+type Condition commons schemas params grp from =
726− Expression db params grp from ('Null 'PGbool)
726+ Expression commons schemas params grp from ('Null 'PGbool)
727
727
728-- | >>> printSQL true
728-- | >>> printSQL true
729-- TRUE
729-- TRUE
730−true :: Expression db params grp from (nullity 'PGbool)
730+true :: Expression commons schemas params grp from (nullity 'PGbool)
731true = UnsafeExpression "TRUE"
731true = UnsafeExpression "TRUE"
732
732
733-- | >>> printSQL false
733-- | >>> printSQL false
734-- FALSE
734-- FALSE
735−false :: Expression db params grp from (nullity 'PGbool)
735+false :: Expression commons schemas params grp from (nullity 'PGbool)
736false = UnsafeExpression "FALSE"
736false = UnsafeExpression "FALSE"
737
737
738-- | >>> printSQL $ not_ true
738-- | >>> printSQL $ not_ true
739-- (NOT TRUE)
739-- (NOT TRUE)
740not_
740not_
741− :: Expression db params grp from (nullity 'PGbool)
741+ :: Expression commons schemas params grp from (nullity 'PGbool)
742− -> Expression db params grp from (nullity 'PGbool)
742+ -> Expression commons schemas params grp from (nullity 'PGbool)
743not_ = unsafeUnaryOp "NOT"
743not_ = unsafeUnaryOp "NOT"
744
744
745-- | >>> printSQL $ true .&& false
745-- | >>> printSQL $ true .&& false
746-- (TRUE AND FALSE)
746-- (TRUE AND FALSE)
747(.&&)
747(.&&)
748− :: Expression db params grp from (nullity 'PGbool)
748+ :: Expression commons schemas params grp from (nullity 'PGbool)
749− -> Expression db params grp from (nullity 'PGbool)
749+ -> Expression commons schemas params grp from (nullity 'PGbool)
750− -> Expression db params grp from (nullity 'PGbool)
750+ -> Expression commons schemas params grp from (nullity 'PGbool)
751infixr 3 .&&
751infixr 3 .&&
752(.&&) = unsafeBinaryOp "AND"
752(.&&) = unsafeBinaryOp "AND"
753
753
754-- | >>> printSQL $ true .|| false
754-- | >>> printSQL $ true .|| false
755-- (TRUE OR FALSE)
755-- (TRUE OR FALSE)
756(.||)
756(.||)
757− :: Expression db params grp from (nullity 'PGbool)
757+ :: Expression commons schemas params grp from (nullity 'PGbool)
758− -> Expression db params grp from (nullity 'PGbool)
758+ -> Expression commons schemas params grp from (nullity 'PGbool)
759− -> Expression db params grp from (nullity 'PGbool)
759+ -> Expression commons schemas params grp from (nullity 'PGbool)
760infixr 2 .||
760infixr 2 .||
761(.||) = unsafeBinaryOp "OR"
761(.||) = unsafeBinaryOp "OR"
762
762
763-- | >>> :{
763-- | >>> :{
764-- let
764-- let
765−-- expression :: Expression db params grp from (nullity 'PGint2)
765+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
766-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
766-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
767-- in printSQL expression
767-- in printSQL expression
768-- :}
768-- :}
769-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
769-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
770caseWhenThenElse
770caseWhenThenElse
771− :: [ ( Condition db params grp from
771+ :: [ ( Condition commons schemas params grp from
772− , Expression db params grp from ty
772+ , Expression commons schemas params grp from ty
773 ) ]
773 ) ]
774 -- ^ whens and thens
774 -- ^ whens and thens
775− -> Expression db params grp from ty
775+ -> Expression commons schemas params grp from ty
776 -- ^ else
776 -- ^ else
777− -> Expression db params grp from ty
777+ -> Expression commons schemas params grp from ty
778caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
778caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
779 [ "CASE"
779 [ "CASE"
780 , mconcat
780 , mconcat
@@ -790,16 +790,16 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
790
790
791-- | >>> :{
791-- | >>> :{
792-- let
792-- let
793−-- expression :: Expression db params grp from (nullity 'PGint2)
793+-- expression :: Expression commons schemas params grp from (nullity 'PGint2)
794-- expression = ifThenElse true 1 0
794-- expression = ifThenElse true 1 0
795-- in printSQL expression
795-- in printSQL expression
796-- :}
796-- :}
797-- CASE WHEN TRUE THEN 1 ELSE 0 END
797-- CASE WHEN TRUE THEN 1 ELSE 0 END
798ifThenElse
798ifThenElse
799− :: Condition db params grp from
799+ :: Condition commons schemas params grp from
800− -> Expression db params grp from ty -- ^ then
800+ -> Expression commons schemas params grp from ty -- ^ then
801− -> Expression db params grp from ty -- ^ else
801+ -> Expression commons schemas params grp from ty -- ^ else
802− -> Expression db params grp from ty
802+ -> Expression commons schemas params grp from ty
803ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
803ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
804
804
805-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
805-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -808,85 +808,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
808-- >>> printSQL $ true .== null_
808-- >>> printSQL $ true .== null_
809-- (TRUE = NULL)
809-- (TRUE = NULL)
810(.==)
810(.==)
811− :: Expression db params grp from (nullity0 ty) -- ^ lhs
811+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
812− -> Expression db params grp from (nullity1 ty) -- ^ rhs
812+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
813− -> Condition db params grp from
813+ -> Condition commons schemas params grp from
814(.==) = unsafeBinaryOp "="
814(.==) = unsafeBinaryOp "="
815infix 4 .==
815infix 4 .==
816
816
817-- | >>> printSQL $ true ./= null_
817-- | >>> printSQL $ true ./= null_
818-- (TRUE <> NULL)
818-- (TRUE <> NULL)
819(./=)
819(./=)
820− :: Expression db params grp from (nullity0 ty) -- ^ lhs
820+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
821− -> Expression db params grp from (nullity1 ty) -- ^ rhs
821+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
822− -> Condition db params grp from
822+ -> Condition commons schemas params grp from
823(./=) = unsafeBinaryOp "<>"
823(./=) = unsafeBinaryOp "<>"
824infix 4 ./=
824infix 4 ./=
825
825
826-- | >>> printSQL $ true .>= null_
826-- | >>> printSQL $ true .>= null_
827-- (TRUE >= NULL)
827-- (TRUE >= NULL)
828(.>=)
828(.>=)
829− :: Expression db params grp from (nullity0 ty) -- ^ lhs
829+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
830− -> Expression db params grp from (nullity1 ty) -- ^ rhs
830+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
831− -> Condition db params grp from
831+ -> Condition commons schemas params grp from
832(.>=) = unsafeBinaryOp ">="
832(.>=) = unsafeBinaryOp ">="
833infix 4 .>=
833infix 4 .>=
834
834
835-- | >>> printSQL $ true .< null_
835-- | >>> printSQL $ true .< null_
836-- (TRUE < NULL)
836-- (TRUE < NULL)
837(.<)
837(.<)
838− :: Expression db params grp from (nullity0 ty) -- ^ lhs
838+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
839− -> Expression db params grp from (nullity1 ty) -- ^ rhs
839+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
840− -> Condition db params grp from
840+ -> Condition commons schemas params grp from
841(.<) = unsafeBinaryOp "<"
841(.<) = unsafeBinaryOp "<"
842infix 4 .<
842infix 4 .<
843
843
844-- | >>> printSQL $ true .<= null_
844-- | >>> printSQL $ true .<= null_
845-- (TRUE <= NULL)
845-- (TRUE <= NULL)
846(.<=)
846(.<=)
847− :: Expression db params grp from (nullity0 ty) -- ^ lhs
847+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
848− -> Expression db params grp from (nullity1 ty) -- ^ rhs
848+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
849− -> Condition db params grp from
849+ -> Condition commons schemas params grp from
850(.<=) = unsafeBinaryOp "<="
850(.<=) = unsafeBinaryOp "<="
851infix 4 .<=
851infix 4 .<=
852
852
853-- | >>> printSQL $ true .> null_
853-- | >>> printSQL $ true .> null_
854-- (TRUE > NULL)
854-- (TRUE > NULL)
855(.>)
855(.>)
856− :: Expression db params grp from (nullity0 ty) -- ^ lhs
856+ :: Expression commons schemas params grp from (nullity0 ty) -- ^ lhs
857− -> Expression db params grp from (nullity1 ty) -- ^ rhs
857+ -> Expression commons schemas params grp from (nullity1 ty) -- ^ rhs
858− -> Condition db params grp from
858+ -> Condition commons schemas params grp from
859(.>) = unsafeBinaryOp ">"
859(.>) = unsafeBinaryOp ">"
860infix 4 .>
860infix 4 .>
861
861
862-- | >>> printSQL currentDate
862-- | >>> printSQL currentDate
863-- CURRENT_DATE
863-- CURRENT_DATE
864currentDate
864currentDate
865− :: Expression db params grp from (nullity 'PGdate)
865+ :: Expression commons schemas params grp from (nullity 'PGdate)
866currentDate = UnsafeExpression "CURRENT_DATE"
866currentDate = UnsafeExpression "CURRENT_DATE"
867
867
868-- | >>> printSQL currentTime
868-- | >>> printSQL currentTime
869-- CURRENT_TIME
869-- CURRENT_TIME
870currentTime
870currentTime
871− :: Expression db params grp from (nullity 'PGtimetz)
871+ :: Expression commons schemas params grp from (nullity 'PGtimetz)
872currentTime = UnsafeExpression "CURRENT_TIME"
872currentTime = UnsafeExpression "CURRENT_TIME"
873
873
874-- | >>> printSQL currentTimestamp
874-- | >>> printSQL currentTimestamp
875-- CURRENT_TIMESTAMP
875-- CURRENT_TIMESTAMP
876currentTimestamp
876currentTimestamp
877− :: Expression db params grp from (nullity 'PGtimestamptz)
877+ :: Expression commons schemas params grp from (nullity 'PGtimestamptz)
878currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
878currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
879
879
880-- | >>> printSQL localTime
880-- | >>> printSQL localTime
881-- LOCALTIME
881-- LOCALTIME
882localTime
882localTime
883− :: Expression db params grp from (nullity 'PGtime)
883+ :: Expression commons schemas params grp from (nullity 'PGtime)
884localTime = UnsafeExpression "LOCALTIME"
884localTime = UnsafeExpression "LOCALTIME"
885
885
886-- | >>> printSQL localTimestamp
886-- | >>> printSQL localTimestamp
887-- LOCALTIMESTAMP
887-- LOCALTIMESTAMP
888localTimestamp
888localTimestamp
889− :: Expression db params grp from (nullity 'PGtimestamp)
889+ :: Expression commons schemas params grp from (nullity 'PGtimestamp)
890localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
890localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
891
891
892{-----------------------------------------
892{-----------------------------------------
@@ -894,7 +894,7 @@ text
894-----------------------------------------}
894-----------------------------------------}
895
895
896instance IsString
896instance IsString
897− (Expression db params grp from (nullity 'PGtext)) where
897+ (Expression commons schemas params grp from (nullity 'PGtext)) where
898 fromString str = UnsafeExpression $
898 fromString str = UnsafeExpression $
899 "E\'" <> fromString (escape =<< str) <> "\'"
899 "E\'" <> fromString (escape =<< str) <> "\'"
900 where
900 where
@@ -910,36 +910,36 @@ instance IsString
910 c -> [c]
910 c -> [c]
911
911
912instance Semigroup
912instance Semigroup
913− (Expression db params grp from (nullity 'PGtext)) where
913+ (Expression commons schemas params grp from (nullity 'PGtext)) where
914 (<>) = unsafeBinaryOp "||"
914 (<>) = unsafeBinaryOp "||"
915
915
916instance Monoid
916instance Monoid
917− (Expression db params grp from (nullity 'PGtext)) where
917+ (Expression commons schemas params grp from (nullity 'PGtext)) where
918 mempty = fromString ""
918 mempty = fromString ""
919 mappend = (<>)
919 mappend = (<>)
920
920
921-- | >>> printSQL $ lower "ARRRGGG"
921-- | >>> printSQL $ lower "ARRRGGG"
922-- lower(E'ARRRGGG')
922-- lower(E'ARRRGGG')
923lower
923lower
924− :: Expression db params grp from (nullity 'PGtext)
924+ :: Expression commons schemas params grp from (nullity 'PGtext)
925 -- ^ string to lower case
925 -- ^ string to lower case
926− -> Expression db params grp from (nullity 'PGtext)
926+ -> Expression commons schemas params grp from (nullity 'PGtext)
927lower = unsafeFunction "lower"
927lower = unsafeFunction "lower"
928
928
929-- | >>> printSQL $ upper "eeee"
929-- | >>> printSQL $ upper "eeee"
930-- upper(E'eeee')
930-- upper(E'eeee')
931upper
931upper
932− :: Expression db params grp from (nullity 'PGtext)
932+ :: Expression commons schemas params grp from (nullity 'PGtext)
933 -- ^ string to upper case
933 -- ^ string to upper case
934− -> Expression db params grp from (nullity 'PGtext)
934+ -> Expression commons schemas params grp from (nullity 'PGtext)
935upper = unsafeFunction "upper"
935upper = unsafeFunction "upper"
936
936
937-- | >>> printSQL $ charLength "four"
937-- | >>> printSQL $ charLength "four"
938-- char_length(E'four')
938-- char_length(E'four')
939charLength
939charLength
940− :: Expression db params grp from (nullity 'PGtext)
940+ :: Expression commons schemas params grp from (nullity 'PGtext)
941 -- ^ string to measure
941 -- ^ string to measure
942− -> Expression db params grp from (nullity 'PGint4)
942+ -> Expression commons schemas params grp from (nullity 'PGint4)
943charLength = unsafeFunction "char_length"
943charLength = unsafeFunction "char_length"
944
944
945-- | The `like` expression returns true if the @string@ matches
945-- | The `like` expression returns true if the @string@ matches
@@ -952,11 +952,11 @@ charLength = unsafeFunction "char_length"
952-- >>> printSQL $ "abc" `like` "a%"
952-- >>> printSQL $ "abc" `like` "a%"
953-- (E'abc' LIKE E'a%')
953-- (E'abc' LIKE E'a%')
954like
954like
955− :: Expression db params grp from (nullity 'PGtext)
955+ :: Expression commons schemas params grp from (nullity 'PGtext)
956 -- ^ string
956 -- ^ string
957− -> Expression db params grp from (nullity 'PGtext)
957+ -> Expression commons schemas params grp from (nullity 'PGtext)
958 -- ^ pattern
958 -- ^ pattern
959− -> Expression db params grp from (nullity 'PGbool)
959+ -> Expression commons schemas params grp from (nullity 'PGbool)
960like = unsafeBinaryOp "LIKE"
960like = unsafeBinaryOp "LIKE"
961
961
962-- | The key word ILIKE can be used instead of LIKE to make the
962-- | The key word ILIKE can be used instead of LIKE to make the
@@ -965,11 +965,11 @@ like = unsafeBinaryOp "LIKE"
965-- >>> printSQL $ "abc" `ilike` "a%"
965-- >>> printSQL $ "abc" `ilike` "a%"
966-- (E'abc' ILIKE E'a%')
966-- (E'abc' ILIKE E'a%')
967ilike
967ilike
968− :: Expression db params grp from (nullity 'PGtext)
968+ :: Expression commons schemas params grp from (nullity 'PGtext)
969 -- ^ string
969 -- ^ string
970− -> Expression db params grp from (nullity 'PGtext)
970+ -> Expression commons schemas params grp from (nullity 'PGtext)
971 -- ^ pattern
971 -- ^ pattern
972− -> Expression db params grp from (nullity 'PGbool)
972+ -> Expression commons schemas params grp from (nullity 'PGbool)
973ilike = unsafeBinaryOp "ILIKE"
973ilike = unsafeBinaryOp "ILIKE"
974
974
975{-----------------------------------------
975{-----------------------------------------
@@ -984,36 +984,36 @@ Table 9.44: json and jsonb operators
984-- | Get JSON value (object field or array element) at a key.
984-- | Get JSON value (object field or array element) at a key.
985(.->)
985(.->)
986 :: (json `In` PGJsonType, key `In` PGJsonKey)
986 :: (json `In` PGJsonType, key `In` PGJsonKey)
987− => Expression db params grp from (nullity json)
987+ => Expression commons schemas params grp from (nullity json)
988− -> Expression db params grp from (nullity key)
988+ -> Expression commons schemas params grp from (nullity key)
989− -> Expression db params grp from ('Null json)
989+ -> Expression commons schemas params grp from ('Null json)
990infixl 8 .->
990infixl 8 .->
991(.->) = unsafeBinaryOp "->"
991(.->) = unsafeBinaryOp "->"
992
992
993-- | Get JSON value (object field or array element) at a key, as text.
993-- | Get JSON value (object field or array element) at a key, as text.
994(.->>)
994(.->>)
995 :: (json `In` PGJsonType, key `In` PGJsonKey)
995 :: (json `In` PGJsonType, key `In` PGJsonKey)
996− => Expression db params grp from (nullity json)
996+ => Expression commons schemas params grp from (nullity json)
997− -> Expression db params grp from (nullity key)
997+ -> Expression commons schemas params grp from (nullity key)
998− -> Expression db params grp from ('Null 'PGtext)
998+ -> Expression commons schemas params grp from ('Null 'PGtext)
999infixl 8 .->>
999infixl 8 .->>
1000(.->>) = unsafeBinaryOp "->>"
1000(.->>) = unsafeBinaryOp "->>"
1001
1001
1002-- | Get JSON value at a specified path.
1002-- | Get JSON value at a specified path.
1003(.#>)
1003(.#>)
1004 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1004 :: (json `In` PGJsonType, PGTextArray "(.#>)" path)
1005− => Expression db params grp from (nullity json)
1005+ => Expression commons schemas params grp from (nullity json)
1006− -> Expression db params grp from (nullity path)
1006+ -> Expression commons schemas params grp from (nullity path)
1007− -> Expression db params grp from ('Null json)
1007+ -> Expression commons schemas params grp from ('Null json)
1008infixl 8 .#>
1008infixl 8 .#>
1009(.#>) = unsafeBinaryOp "#>"
1009(.#>) = unsafeBinaryOp "#>"
1010
1010
1011-- | Get JSON value at a specified path as text.
1011-- | Get JSON value at a specified path as text.
1012(.#>>)
1012(.#>>)
1013 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1013 :: (json `In` PGJsonType, PGTextArray "(.#>>)" path)
1014− => Expression db params grp from (nullity json)
1014+ => Expression commons schemas params grp from (nullity json)
1015− -> Expression db params grp from (nullity path)
1015+ -> Expression commons schemas params grp from (nullity path)
1016− -> Expression db params grp from ('Null 'PGtext)
1016+ -> Expression commons schemas params grp from ('Null 'PGtext)
1017infixl 8 .#>>
1017infixl 8 .#>>
1018(.#>>) = unsafeBinaryOp "#>>"
1018(.#>>) = unsafeBinaryOp "#>>"
1019
1019
@@ -1022,48 +1022,48 @@ infixl 8 .#>>
1022-- | Does the left JSON value contain the right JSON path/value entries at the
1022-- | Does the left JSON value contain the right JSON path/value entries at the
1023-- top level?
1023-- top level?
1024(.@>)
1024(.@>)
1025− :: Expression db params grp from (nullity 'PGjsonb)
1025+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1026− -> Expression db params grp from (nullity 'PGjsonb)
1026+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1027− -> Condition db params grp from
1027+ -> Condition commons schemas params grp from
1028infixl 9 .@>
1028infixl 9 .@>
1029(.@>) = unsafeBinaryOp "@>"
1029(.@>) = unsafeBinaryOp "@>"
1030
1030
1031-- | Are the left JSON path/value entries contained at the top level within the
1031-- | Are the left JSON path/value entries contained at the top level within the
1032-- right JSON value?
1032-- right JSON value?
1033(.<@)
1033(.<@)
1034− :: Expression db params grp from (nullity 'PGjsonb)
1034+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1035− -> Expression db params grp from (nullity 'PGjsonb)
1035+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1036− -> Condition db params grp from
1036+ -> Condition commons schemas params grp from
1037infixl 9 .<@
1037infixl 9 .<@
1038(.<@) = unsafeBinaryOp "<@"
1038(.<@) = unsafeBinaryOp "<@"
1039
1039
1040-- | Does the string exist as a top-level key within the JSON value?
1040-- | Does the string exist as a top-level key within the JSON value?
1041(.?)
1041(.?)
1042− :: Expression db params grp from (nullity 'PGjsonb)
1042+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1043− -> Expression db params grp from (nullity 'PGtext)
1043+ -> Expression commons schemas params grp from (nullity 'PGtext)
1044− -> Condition db params grp from
1044+ -> Condition commons schemas params grp from
1045infixl 9 .?
1045infixl 9 .?
1046(.?) = unsafeBinaryOp "?"
1046(.?) = unsafeBinaryOp "?"
1047
1047
1048-- | Do any of these array strings exist as top-level keys?
1048-- | Do any of these array strings exist as top-level keys?
1049(.?|)
1049(.?|)
1050− :: Expression db params grp from (nullity 'PGjsonb)
1050+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1051− -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1051+ -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1052− -> Condition db params grp from
1052+ -> Condition commons schemas params grp from
1053infixl 9 .?|
1053infixl 9 .?|
1054(.?|) = unsafeBinaryOp "?|"
1054(.?|) = unsafeBinaryOp "?|"
1055
1055
1056-- | Do all of these array strings exist as top-level keys?
1056-- | Do all of these array strings exist as top-level keys?
1057(.?&)
1057(.?&)
1058− :: Expression db params grp from (nullity 'PGjsonb)
1058+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1059− -> Expression db params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1059+ -> Expression commons schemas params grp from (nullity ('PGvararray ('NotNull 'PGtext)))
1060− -> Condition db params grp from
1060+ -> Condition commons schemas params grp from
1061infixl 9 .?&
1061infixl 9 .?&
1062(.?&) = unsafeBinaryOp "?&"
1062(.?&) = unsafeBinaryOp "?&"
1063
1063
1064-- | Concatenate two jsonb values into a new jsonb value.
1064-- | Concatenate two jsonb values into a new jsonb value.
1065instance
1065instance
1066− Semigroup (Expression db from grouping param (nullity 'PGjsonb)) where
1066+ Semigroup (Expression commons schemas from grouping param (nullity 'PGjsonb)) where
1067 (<>) = unsafeBinaryOp "||"
1067 (<>) = unsafeBinaryOp "||"
1068
1068
1069-- | Delete a key or keys from a JSON object, or remove an array element.
1069-- | Delete a key or keys from a JSON object, or remove an array element.
@@ -1080,9 +1080,9 @@ instance
1080-- count from the end). Throws an error if top level container is not an array.
1080-- count from the end). Throws an error if top level container is not an array.
1081(.-.)
1081(.-.)
1082 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1082 :: (key `In` '[ 'PGtext, 'PGvararray ('NotNull 'PGtext), 'PGint4, 'PGint2 ]) -- hlint error without parens here
1083− => Expression db params grp from (nullity 'PGjsonb)
1083+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1084− -> Expression db params grp from (nullity key)
1084+ -> Expression commons schemas params grp from (nullity key)
1085− -> Expression db params grp from (nullity 'PGjsonb)
1085+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1086infixl 6 .-.
1086infixl 6 .-.
1087(.-.) = unsafeBinaryOp "-"
1087(.-.) = unsafeBinaryOp "-"
1088
1088
@@ -1090,9 +1090,9 @@ infixl 6 .-.
1090-- integers count from the end)
1090-- integers count from the end)
1091(#-.)
1091(#-.)
1092 :: PGTextArray "(#-.)" arrayty
1092 :: PGTextArray "(#-.)" arrayty
1093− => Expression db params grp from (nullity 'PGjsonb)
1093+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1094− -> Expression db params grp from (nullity arrayty)
1094+ -> Expression commons schemas params grp from (nullity arrayty)
1095− -> Expression db params grp from (nullity 'PGjsonb)
1095+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1096infixl 6 #-.
1096infixl 6 #-.
1097(#-.) = unsafeBinaryOp "#-"
1097(#-.) = unsafeBinaryOp "#-"
1098
1098
@@ -1103,14 +1103,14 @@ Table 9.45: JSON creation functions
1103-- | Literal binary JSON
1103-- | Literal binary JSON
1104jsonbLit
1104jsonbLit
1105 :: JSON.ToJSON x
1105 :: JSON.ToJSON x
1106− => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjsonb)
1106+ => x -> Expression commons schemas params grp from (nullity 'PGjsonb)
1107jsonbLit = cast jsonb . UnsafeExpression
1107jsonbLit = cast jsonb . UnsafeExpression
1108 . singleQuotedUtf8 . toStrict . JSON.encode
1108 . singleQuotedUtf8 . toStrict . JSON.encode
1109
1109
1110-- | Literal JSON
1110-- | Literal JSON
1111jsonLit
1111jsonLit
1112 :: JSON.ToJSON x
1112 :: JSON.ToJSON x
1113− => x -> Expression (commons :=> schemas) params grp from (nullity 'PGjson)
1113+ => x -> Expression commons schemas params grp from (nullity 'PGjson)
1114jsonLit = cast json . UnsafeExpression
1114jsonLit = cast json . UnsafeExpression
1115 . singleQuotedUtf8 . toStrict . JSON.encode
1115 . singleQuotedUtf8 . toStrict . JSON.encode
1116
1116
@@ -1121,8 +1121,8 @@ jsonLit = cast json . UnsafeExpression
1121-- number, a Boolean, or a null value, the text representation will be used, in
1121-- number, a Boolean, or a null value, the text representation will be used, in
1122-- such a fashion that it is a valid json value.
1122-- such a fashion that it is a valid json value.
1123toJson
1123toJson
1124− :: Expression db params grp from (nullity ty)
1124+ :: Expression commons schemas params grp from (nullity ty)
1125− -> Expression db params grp from (nullity 'PGjson)
1125+ -> Expression commons schemas params grp from (nullity 'PGjson)
1126toJson = unsafeFunction "to_json"
1126toJson = unsafeFunction "to_json"
1127
1127
1128-- | Returns the value as jsonb. Arrays and composites are converted
1128-- | Returns the value as jsonb. Arrays and composites are converted
@@ -1132,43 +1132,43 @@ toJson = unsafeFunction "to_json"
1132-- number, a Boolean, or a null value, the text representation will be used, in
1132-- number, a Boolean, or a null value, the text representation will be used, in
1133-- such a fashion that it is a valid jsonb value.
1133-- such a fashion that it is a valid jsonb value.
1134toJsonb
1134toJsonb
1135− :: Expression db params grp from (nullity ty)
1135+ :: Expression commons schemas params grp from (nullity ty)
1136− -> Expression db params grp from (nullity 'PGjsonb)
1136+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1137toJsonb = unsafeFunction "to_jsonb"
1137toJsonb = unsafeFunction "to_jsonb"
1138
1138
1139-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1139-- | Returns the array as a JSON array. A PostgreSQL multidimensional array
1140-- becomes a JSON array of arrays.
1140-- becomes a JSON array of arrays.
1141arrayToJson
1141arrayToJson
1142 :: PGArray "arrayToJson" arr
1142 :: PGArray "arrayToJson" arr
1143− => Expression db params grp from (nullity arr)
1143+ => Expression commons schemas params grp from (nullity arr)
1144− -> Expression db params grp from (nullity 'PGjson)
1144+ -> Expression commons schemas params grp from (nullity 'PGjson)
1145arrayToJson = unsafeFunction "array_to_json"
1145arrayToJson = unsafeFunction "array_to_json"
1146
1146
1147-- | Returns the row as a JSON object.
1147-- | Returns the row as a JSON object.
1148rowToJson
1148rowToJson
1149− :: Expression db params grp from (nullity ('PGcomposite ty))
1149+ :: Expression commons schemas params grp from (nullity ('PGcomposite ty))
1150− -> Expression db params grp from (nullity 'PGjson)
1150+ -> Expression commons schemas params grp from (nullity 'PGjson)
1151rowToJson = unsafeFunction "row_to_json"
1151rowToJson = unsafeFunction "row_to_json"
1152
1152
1153-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1153-- | Builds a possibly-heterogeneously-typed JSON array out of a variadic
1154-- argument list.
1154-- argument list.
1155jsonBuildArray
1155jsonBuildArray
1156 :: SListI elems
1156 :: SListI elems
1157− => NP (Expression db params grp from) elems
1157+ => NP (Expression commons schemas params grp from) elems
1158− -> Expression db params grp from (nullity 'PGjson)
1158+ -> Expression commons schemas params grp from (nullity 'PGjson)
1159jsonBuildArray = unsafeVariadicFunction "json_build_array"
1159jsonBuildArray = unsafeVariadicFunction "json_build_array"
1160
1160
1161-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1161-- | Builds a possibly-heterogeneously-typed (binary) JSON array out of a
1162-- variadic argument list.
1162-- variadic argument list.
1163jsonbBuildArray
1163jsonbBuildArray
1164 :: SListI elems
1164 :: SListI elems
1165− => NP (Expression db params grp from) elems
1165+ => NP (Expression commons schemas params grp from) elems
1166− -> Expression db params grp from (nullity 'PGjsonb)
1166+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1167jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1167jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1168
1168
1169unsafeRowFunction
1169unsafeRowFunction
1170 :: All Top elems
1170 :: All Top elems
1171− => NP (Aliased (Expression db params grp from)) elems
1171+ => NP (Aliased (Expression commons schemas params grp from)) elems
1172 -> [ByteString]
1172 -> [ByteString]
1173unsafeRowFunction =
1173unsafeRowFunction =
1174 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
1174 (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
@@ -1183,8 +1183,8 @@ unsafeRowFunction =
1183-- and values.
1183-- and values.
1184jsonBuildObject
1184jsonBuildObject
1185 :: All Top elems
1185 :: All Top elems
1186− => NP (Aliased (Expression db params grp from)) elems
1186+ => NP (Aliased (Expression commons schemas params grp from)) elems
1187− -> Expression db params grp from (nullity 'PGjson)
1187+ -> Expression commons schemas params grp from (nullity 'PGjson)
1188jsonBuildObject
1188jsonBuildObject
1189 = unsafeFunction "json_build_object"
1189 = unsafeFunction "json_build_object"
1190 . UnsafeExpression
1190 . UnsafeExpression
@@ -1196,8 +1196,8 @@ jsonBuildObject
1196-- between text and values.
1196-- between text and values.
1197jsonbBuildObject
1197jsonbBuildObject
1198 :: All Top elems
1198 :: All Top elems
1199− => NP (Aliased (Expression db params grp from)) elems
1199+ => NP (Aliased (Expression commons schemas params grp from)) elems
1200− -> Expression db params grp from (nullity 'PGjsonb)
1200+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1201jsonbBuildObject
1201jsonbBuildObject
1202 = unsafeFunction "jsonb_build_object"
1202 = unsafeFunction "jsonb_build_object"
1203 . UnsafeExpression
1203 . UnsafeExpression
@@ -1210,8 +1210,8 @@ jsonbBuildObject
1210-- array has exactly two elements, which are taken as a key/value pair.
1210-- array has exactly two elements, which are taken as a key/value pair.
1211jsonObject
1211jsonObject
1212 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1212 :: PGArrayOf "jsonObject" arr ('NotNull 'PGtext)
1213− => Expression db params grp from (nullity arr)
1213+ => Expression commons schemas params grp from (nullity arr)
1214− -> Expression db params grp from (nullity 'PGjson)
1214+ -> Expression commons schemas params grp from (nullity 'PGjson)
1215jsonObject = unsafeFunction "json_object"
1215jsonObject = unsafeFunction "json_object"
1216
1216
1217-- | Builds a binary JSON object out of a text array. The array must have either
1217-- | Builds a binary JSON object out of a text array. The array must have either
@@ -1220,8 +1220,8 @@ jsonObject = unsafeFunction "json_object"
1220-- array has exactly two elements, which are taken as a key/value pair.
1220-- array has exactly two elements, which are taken as a key/value pair.
1221jsonbObject
1221jsonbObject
1222 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1222 :: PGArrayOf "jsonbObject" arr ('NotNull 'PGtext)
1223− => Expression db params grp from (nullity arr)
1223+ => Expression commons schemas params grp from (nullity arr)
1224− -> Expression db params grp from (nullity 'PGjsonb)
1224+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1225jsonbObject = unsafeFunction "jsonb_object"
1225jsonbObject = unsafeFunction "jsonb_object"
1226
1226
1227-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
1227-- | This is an alternate form of 'jsonObject' that takes two arrays; one for
@@ -1229,9 +1229,9 @@ jsonbObject = unsafeFunction "jsonb_object"
1229jsonZipObject
1229jsonZipObject
1230 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1230 :: ( PGArrayOf "jsonZipObject" keysArray ('NotNull 'PGtext)
1231 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1231 , PGArrayOf "jsonZipObject" valuesArray ('NotNull 'PGtext))
1232− => Expression db params grp from (nullity keysArray)
1232+ => Expression commons schemas params grp from (nullity keysArray)
1233− -> Expression db params grp from (nullity valuesArray)
1233+ -> Expression commons schemas params grp from (nullity valuesArray)
1234− -> Expression db params grp from (nullity 'PGjson)
1234+ -> Expression commons schemas params grp from (nullity 'PGjson)
1235jsonZipObject ks vs =
1235jsonZipObject ks vs =
1236 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1236 unsafeVariadicFunction "json_object" (ks :* vs :* Nil)
1237
1237
@@ -1241,9 +1241,9 @@ jsonZipObject ks vs =
1241jsonbZipObject
1241jsonbZipObject
1242 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1242 :: ( PGArrayOf "jsonbZipObject" keysArray ('NotNull 'PGtext)
1243 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1243 , PGArrayOf "jsonbZipObject" valuesArray ('NotNull 'PGtext))
1244− => Expression db params grp from (nullity keysArray)
1244+ => Expression commons schemas params grp from (nullity keysArray)
1245− -> Expression db params grp from (nullity valuesArray)
1245+ -> Expression commons schemas params grp from (nullity valuesArray)
1246− -> Expression db params grp from (nullity 'PGjsonb)
1246+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1247jsonbZipObject ks vs =
1247jsonbZipObject ks vs =
1248 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1248 unsafeVariadicFunction "jsonb_object" (ks :* vs :* Nil)
1249
1249
@@ -1253,23 +1253,23 @@ Table 9.46: JSON processing functions
1253
1253
1254-- | Returns the number of elements in the outermost JSON array.
1254-- | Returns the number of elements in the outermost JSON array.
1255jsonArrayLength
1255jsonArrayLength
1256− :: Expression db params grp from (nullity 'PGjson)
1256+ :: Expression commons schemas params grp from (nullity 'PGjson)
1257− -> Expression db params grp from (nullity 'PGint4)
1257+ -> Expression commons schemas params grp from (nullity 'PGint4)
1258jsonArrayLength = unsafeFunction "json_array_length"
1258jsonArrayLength = unsafeFunction "json_array_length"
1259
1259
1260-- | Returns the number of elements in the outermost binary JSON array.
1260-- | Returns the number of elements in the outermost binary JSON array.
1261jsonbArrayLength
1261jsonbArrayLength
1262− :: Expression db params grp from (nullity 'PGjsonb)
1262+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1263− -> Expression db params grp from (nullity 'PGint4)
1263+ -> Expression commons schemas params grp from (nullity 'PGint4)
1264jsonbArrayLength = unsafeFunction "jsonb_array_length"
1264jsonbArrayLength = unsafeFunction "jsonb_array_length"
1265
1265
1266-- | Returns JSON value pointed to by the given path (equivalent to #>
1266-- | Returns JSON value pointed to by the given path (equivalent to #>
1267-- operator).
1267-- operator).
1268jsonExtractPath
1268jsonExtractPath
1269 :: SListI elems
1269 :: SListI elems
1270− => Expression db params grp from (nullity 'PGjson)
1270+ => Expression commons schemas params grp from (nullity 'PGjson)
1271− -> NP (Expression db params grp from) elems
1271+ -> NP (Expression commons schemas params grp from) elems
1272− -> Expression db params grp from (nullity 'PGjsonb)
1272+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1273jsonExtractPath x xs =
1273jsonExtractPath x xs =
1274 unsafeVariadicFunction "json_extract_path" (x :* xs)
1274 unsafeVariadicFunction "json_extract_path" (x :* xs)
1275
1275
@@ -1277,9 +1277,9 @@ jsonExtractPath x xs =
1277-- operator).
1277-- operator).
1278jsonbExtractPath
1278jsonbExtractPath
1279 :: SListI elems
1279 :: SListI elems
1280− => Expression db params grp from (nullity 'PGjsonb)
1280+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1281− -> NP (Expression db params grp from) elems
1281+ -> NP (Expression commons schemas params grp from) elems
1282− -> Expression db params grp from (nullity 'PGjsonb)
1282+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1283jsonbExtractPath x xs =
1283jsonbExtractPath x xs =
1284 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1284 unsafeVariadicFunction "jsonb_extract_path" (x :* xs)
1285
1285
@@ -1287,9 +1287,9 @@ jsonbExtractPath x xs =
1287-- operator), as text.
1287-- operator), as text.
1288jsonExtractPathAsText
1288jsonExtractPathAsText
1289 :: SListI elems
1289 :: SListI elems
1290− => Expression db params grp from (nullity 'PGjson)
1290+ => Expression commons schemas params grp from (nullity 'PGjson)
1291− -> NP (Expression db params grp from) elems
1291+ -> NP (Expression commons schemas params grp from) elems
1292− -> Expression db params grp from (nullity 'PGjson)
1292+ -> Expression commons schemas params grp from (nullity 'PGjson)
1293jsonExtractPathAsText x xs =
1293jsonExtractPathAsText x xs =
1294 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1294 unsafeVariadicFunction "json_extract_path_text" (x :* xs)
1295
1295
@@ -1297,38 +1297,38 @@ jsonExtractPathAsText x xs =
1297-- operator), as text.
1297-- operator), as text.
1298jsonbExtractPathAsText
1298jsonbExtractPathAsText
1299 :: SListI elems
1299 :: SListI elems
1300− => Expression db params grp from (nullity 'PGjsonb)
1300+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1301− -> NP (Expression db params grp from) elems
1301+ -> NP (Expression commons schemas params grp from) elems
1302− -> Expression db params grp from (nullity 'PGjsonb)
1302+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1303jsonbExtractPathAsText x xs =
1303jsonbExtractPathAsText x xs =
1304 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1304 unsafeVariadicFunction "jsonb_extract_path_text" (x :* xs)
1305
1305
1306-- | Returns the type of the outermost JSON value as a text string. Possible
1306-- | Returns the type of the outermost JSON value as a text string. Possible
1307-- types are object, array, string, number, boolean, and null.
1307-- types are object, array, string, number, boolean, and null.
1308jsonTypeof
1308jsonTypeof
1309− :: Expression db params grp from (nullity 'PGjson)
1309+ :: Expression commons schemas params grp from (nullity 'PGjson)
1310− -> Expression db params grp from (nullity 'PGtext)
1310+ -> Expression commons schemas params grp from (nullity 'PGtext)
1311jsonTypeof = unsafeFunction "json_typeof"
1311jsonTypeof = unsafeFunction "json_typeof"
1312
1312
1313-- | Returns the type of the outermost binary JSON value as a text string.
1313-- | Returns the type of the outermost binary JSON value as a text string.
1314-- Possible types are object, array, string, number, boolean, and null.
1314-- Possible types are object, array, string, number, boolean, and null.
1315jsonbTypeof
1315jsonbTypeof
1316− :: Expression db params grp from (nullity 'PGjsonb)
1316+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1317− -> Expression db params grp from (nullity 'PGtext)
1317+ -> Expression commons schemas params grp from (nullity 'PGtext)
1318jsonbTypeof = unsafeFunction "jsonb_typeof"
1318jsonbTypeof = unsafeFunction "jsonb_typeof"
1319
1319
1320-- | Returns its argument with all object fields that have null values omitted.
1320-- | Returns its argument with all object fields that have null values omitted.
1321-- Other null values are untouched.
1321-- Other null values are untouched.
1322jsonStripNulls
1322jsonStripNulls
1323− :: Expression db params grp from (nullity 'PGjson)
1323+ :: Expression commons schemas params grp from (nullity 'PGjson)
1324− -> Expression db params grp from (nullity 'PGjson)
1324+ -> Expression commons schemas params grp from (nullity 'PGjson)
1325jsonStripNulls = unsafeFunction "json_strip_nulls"
1325jsonStripNulls = unsafeFunction "json_strip_nulls"
1326
1326
1327-- | Returns its argument with all object fields that have null values omitted.
1327-- | Returns its argument with all object fields that have null values omitted.
1328-- Other null values are untouched.
1328-- Other null values are untouched.
1329jsonbStripNulls
1329jsonbStripNulls
1330− :: Expression db params grp from (nullity 'PGjsonb)
1330+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1331− -> Expression db params grp from (nullity 'PGjsonb)
1331+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1332jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1332jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1333
1333
1334-- | @ jsonbSet target path new_value create_missing @
1334-- | @ jsonbSet target path new_value create_missing @
@@ -1340,11 +1340,11 @@ jsonbStripNulls = unsafeFunction "jsonb_strip_nulls"
1340-- arrays.
1340-- arrays.
1341jsonbSet
1341jsonbSet
1342 :: PGTextArray "jsonbSet" arr
1342 :: PGTextArray "jsonbSet" arr
1343− => Expression db params grp from (nullity 'PGjsonb)
1343+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1344− -> Expression db params grp from (nullity arr)
1344+ -> Expression commons schemas params grp from (nullity arr)
1345− -> Expression db params grp from (nullity 'PGjsonb)
1345+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1346− -> Maybe (Expression db params grp from (nullity 'PGbool))
1346+ -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1347− -> Expression db params grp from (nullity 'PGjsonb)
1347+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1348jsonbSet tgt path val createMissing = case createMissing of
1348jsonbSet tgt path val createMissing = case createMissing of
1349 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1349 Just m -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* m :* Nil)
1350 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
1350 Nothing -> unsafeVariadicFunction "jsonb_set" (tgt :* path :* val :* Nil)
@@ -1359,19 +1359,19 @@ jsonbSet tgt path val createMissing = case createMissing of
1359-- in path count from the end of JSON arrays.
1359-- in path count from the end of JSON arrays.
1360jsonbInsert
1360jsonbInsert
1361 :: PGTextArray "jsonbInsert" arr
1361 :: PGTextArray "jsonbInsert" arr
1362− => Expression db params grp from (nullity 'PGjsonb)
1362+ => Expression commons schemas params grp from (nullity 'PGjsonb)
1363− -> Expression db params grp from (nullity arr)
1363+ -> Expression commons schemas params grp from (nullity arr)
1364− -> Expression db params grp from (nullity 'PGjsonb)
1364+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1365− -> Maybe (Expression db params grp from (nullity 'PGbool))
1365+ -> Maybe (Expression commons schemas params grp from (nullity 'PGbool))
1366− -> Expression db params grp from (nullity 'PGjsonb)
1366+ -> Expression commons schemas params grp from (nullity 'PGjsonb)
1367jsonbInsert tgt path val insertAfter = case insertAfter of
1367jsonbInsert tgt path val insertAfter = case insertAfter of
1368 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1368 Just i -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* i :* Nil)
1369 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1369 Nothing -> unsafeVariadicFunction "jsonb_insert" (tgt :* path :* val :* Nil)
1370
1370
1371-- | Returns its argument as indented JSON text.
1371-- | Returns its argument as indented JSON text.
1372jsonbPretty
1372jsonbPretty
1373− :: Expression db params grp from (nullity 'PGjsonb)
1373+ :: Expression commons schemas params grp from (nullity 'PGjsonb)
1374− -> Expression db params grp from (nullity 'PGtext)
1374+ -> Expression commons schemas params grp from (nullity 'PGtext)
1375jsonbPretty = unsafeFunction "jsonb_pretty"
1375jsonbPretty = unsafeFunction "jsonb_pretty"
1376
1376
1377{-----------------------------------------
1377{-----------------------------------------
@@ -1381,54 +1381,54 @@ aggregation
1381-- | escape hatch to define aggregate functions
1381-- | escape hatch to define aggregate functions
1382unsafeAggregate
1382unsafeAggregate
1383 :: ByteString -- ^ aggregate function
1383 :: ByteString -- ^ aggregate function
1384− -> Expression db from 'Ungrouped params (xty)
1384+ -> Expression commons schemas from 'Ungrouped params (xty)
1385− -> Expression db from ('Grouped bys) params (yty)
1385+ -> Expression commons schemas from ('Grouped bys) params (yty)
1386unsafeAggregate fun x = UnsafeExpression $ mconcat
1386unsafeAggregate fun x = UnsafeExpression $ mconcat
1387 [fun, "(", renderSQL x, ")"]
1387 [fun, "(", renderSQL x, ")"]
1388
1388
1389-- | escape hatch to define aggregate functions over distinct values
1389-- | escape hatch to define aggregate functions over distinct values
1390unsafeAggregateDistinct
1390unsafeAggregateDistinct
1391 :: ByteString -- ^ aggregate function
1391 :: ByteString -- ^ aggregate function
1392− -> Expression db from 'Ungrouped params (xty)
1392+ -> Expression commons schemas from 'Ungrouped params (xty)
1393− -> Expression db from ('Grouped bys) params (yty)
1393+ -> Expression commons schemas from ('Grouped bys) params (yty)
1394unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1394unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
1395 [fun, "(DISTINCT ", renderSQL x, ")"]
1395 [fun, "(DISTINCT ", renderSQL x, ")"]
1396
1396
1397-- | >>> :{
1397-- | >>> :{
1398-- let
1398-- let
1399−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1399+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1400-- expression = sum_ #col
1400-- expression = sum_ #col
1401-- in printSQL expression
1401-- in printSQL expression
1402-- :}
1402-- :}
1403-- sum("col")
1403-- sum("col")
1404sum_
1404sum_
1405 :: ty `In` PGNum
1405 :: ty `In` PGNum
1406− => Expression db from 'Ungrouped params (nullity ty)
1406+ => Expression commons schemas from 'Ungrouped params (nullity ty)
1407 -- ^ what to sum
1407 -- ^ what to sum
1408− -> Expression db from ('Grouped bys) params (nullity ty)
1408+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
1409sum_ = unsafeAggregate "sum"
1409sum_ = unsafeAggregate "sum"
1410
1410
1411-- | >>> :{
1411-- | >>> :{
1412-- let
1412-- let
1413−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
1413+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGnumeric]] (nullity 'PGnumeric)
1414-- expression = sumDistinct #col
1414-- expression = sumDistinct #col
1415-- in printSQL expression
1415-- in printSQL expression
1416-- :}
1416-- :}
1417-- sum(DISTINCT "col")
1417-- sum(DISTINCT "col")
1418sumDistinct
1418sumDistinct
1419 :: ty `In` PGNum
1419 :: ty `In` PGNum
1420− => Expression db from 'Ungrouped params (nullity ty)
1420+ => Expression commons schemas from 'Ungrouped params (nullity ty)
1421 -- ^ what to sum
1421 -- ^ what to sum
1422− -> Expression db from ('Grouped bys) params (nullity ty)
1422+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
1423sumDistinct = unsafeAggregateDistinct "sum"
1423sumDistinct = unsafeAggregateDistinct "sum"
1424
1424
1425-- | A constraint for `PGType`s that you can take averages of and the resulting
1425-- | A constraint for `PGType`s that you can take averages of and the resulting
1426-- `PGType`.
1426-- `PGType`.
1427class PGAvg ty avg | ty -> avg where
1427class PGAvg ty avg | ty -> avg where
1428 avg, avgDistinct
1428 avg, avgDistinct
1429− :: Expression db from 'Ungrouped params (nullity ty)
1429+ :: Expression commons schemas from 'Ungrouped params (nullity ty)
1430 -- ^ what to average
1430 -- ^ what to average
1431− -> Expression db from ('Grouped bys) params (nullity avg)
1431+ -> Expression commons schemas from ('Grouped bys) params (nullity avg)
1432 avg = unsafeAggregate "avg"
1432 avg = unsafeAggregate "avg"
1433 avgDistinct = unsafeAggregateDistinct "avg"
1433 avgDistinct = unsafeAggregateDistinct "avg"
1434instance PGAvg 'PGint2 'PGnumeric
1434instance PGAvg 'PGint2 'PGnumeric
@@ -1441,110 +1441,110 @@ instance PGAvg 'PGinterval 'PGinterval
1441
1441
1442-- | >>> :{
1442-- | >>> :{
1443-- let
1443-- let
1444−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1444+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1445-- expression = bitAnd #col
1445-- expression = bitAnd #col
1446-- in printSQL expression
1446-- in printSQL expression
1447-- :}
1447-- :}
1448-- bit_and("col")
1448-- bit_and("col")
1449bitAnd
1449bitAnd
1450 :: int `In` PGIntegral
1450 :: int `In` PGIntegral
1451− => Expression db from 'Ungrouped params (nullity int)
1451+ => Expression commons schemas from 'Ungrouped params (nullity int)
1452 -- ^ what to aggregate
1452 -- ^ what to aggregate
1453− -> Expression db from ('Grouped bys) params (nullity int)
1453+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
1454bitAnd = unsafeAggregate "bit_and"
1454bitAnd = unsafeAggregate "bit_and"
1455
1455
1456-- | >>> :{
1456-- | >>> :{
1457-- let
1457-- let
1458−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1458+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1459-- expression = bitOr #col
1459-- expression = bitOr #col
1460-- in printSQL expression
1460-- in printSQL expression
1461-- :}
1461-- :}
1462-- bit_or("col")
1462-- bit_or("col")
1463bitOr
1463bitOr
1464 :: int `In` PGIntegral
1464 :: int `In` PGIntegral
1465− => Expression db from 'Ungrouped params (nullity int)
1465+ => Expression commons schemas from 'Ungrouped params (nullity int)
1466 -- ^ what to aggregate
1466 -- ^ what to aggregate
1467− -> Expression db from ('Grouped bys) params (nullity int)
1467+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
1468bitOr = unsafeAggregate "bit_or"
1468bitOr = unsafeAggregate "bit_or"
1469
1469
1470-- | >>> :{
1470-- | >>> :{
1471-- let
1471-- let
1472−-- expression :: Expression db params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1472+-- expression :: Expression commons schemas params ('Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1473-- expression = bitAndDistinct #col
1473-- expression = bitAndDistinct #col
1474-- in printSQL expression
1474-- in printSQL expression
1475-- :}
1475-- :}
1476-- bit_and(DISTINCT "col")
1476-- bit_and(DISTINCT "col")
1477bitAndDistinct
1477bitAndDistinct
1478 :: int `In` PGIntegral
1478 :: int `In` PGIntegral
1479− => Expression db from 'Ungrouped params (nullity int)
1479+ => Expression commons schemas from 'Ungrouped params (nullity int)
1480 -- ^ what to aggregate
1480 -- ^ what to aggregate
1481− -> Expression db from ('Grouped bys) params (nullity int)
1481+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
1482bitAndDistinct = unsafeAggregateDistinct "bit_and"
1482bitAndDistinct = unsafeAggregateDistinct "bit_and"
1483
1483
1484-- | >>> :{
1484-- | >>> :{
1485-- let
1485-- let
1486−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1486+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1487-- expression = bitOrDistinct #col
1487-- expression = bitOrDistinct #col
1488-- in printSQL expression
1488-- in printSQL expression
1489-- :}
1489-- :}
1490-- bit_or(DISTINCT "col")
1490-- bit_or(DISTINCT "col")
1491bitOrDistinct
1491bitOrDistinct
1492 :: int `In` PGIntegral
1492 :: int `In` PGIntegral
1493− => Expression db from 'Ungrouped params (nullity int)
1493+ => Expression commons schemas from 'Ungrouped params (nullity int)
1494 -- ^ what to aggregate
1494 -- ^ what to aggregate
1495− -> Expression db from ('Grouped bys) params (nullity int)
1495+ -> Expression commons schemas from ('Grouped bys) params (nullity int)
1496bitOrDistinct = unsafeAggregateDistinct "bit_or"
1496bitOrDistinct = unsafeAggregateDistinct "bit_or"
1497
1497
1498-- | >>> :{
1498-- | >>> :{
1499-- let
1499-- let
1500−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1500+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1501-- expression = boolAnd #col
1501-- expression = boolAnd #col
1502-- in printSQL expression
1502-- in printSQL expression
1503-- :}
1503-- :}
1504-- bool_and("col")
1504-- bool_and("col")
1505boolAnd
1505boolAnd
1506− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1506+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1507 -- ^ what to aggregate
1507 -- ^ what to aggregate
1508− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1508+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1509boolAnd = unsafeAggregate "bool_and"
1509boolAnd = unsafeAggregate "bool_and"
1510
1510
1511-- | >>> :{
1511-- | >>> :{
1512-- let
1512-- let
1513−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1513+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1514-- expression = boolOr #col
1514-- expression = boolOr #col
1515-- in printSQL expression
1515-- in printSQL expression
1516-- :}
1516-- :}
1517-- bool_or("col")
1517-- bool_or("col")
1518boolOr
1518boolOr
1519− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1519+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1520 -- ^ what to aggregate
1520 -- ^ what to aggregate
1521− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1521+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1522boolOr = unsafeAggregate "bool_or"
1522boolOr = unsafeAggregate "bool_or"
1523
1523
1524-- | >>> :{
1524-- | >>> :{
1525-- let
1525-- let
1526−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1526+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1527-- expression = boolAndDistinct #col
1527-- expression = boolAndDistinct #col
1528-- in printSQL expression
1528-- in printSQL expression
1529-- :}
1529-- :}
1530-- bool_and(DISTINCT "col")
1530-- bool_and(DISTINCT "col")
1531boolAndDistinct
1531boolAndDistinct
1532− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1532+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1533 -- ^ what to aggregate
1533 -- ^ what to aggregate
1534− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1534+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1535boolAndDistinct = unsafeAggregateDistinct "bool_and"
1535boolAndDistinct = unsafeAggregateDistinct "bool_and"
1536
1536
1537-- | >>> :{
1537-- | >>> :{
1538-- let
1538-- let
1539−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1539+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1540-- expression = boolOrDistinct #col
1540-- expression = boolOrDistinct #col
1541-- in printSQL expression
1541-- in printSQL expression
1542-- :}
1542-- :}
1543-- bool_or(DISTINCT "col")
1543-- bool_or(DISTINCT "col")
1544boolOrDistinct
1544boolOrDistinct
1545− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1545+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1546 -- ^ what to aggregate
1546 -- ^ what to aggregate
1547− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1547+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1548boolOrDistinct = unsafeAggregateDistinct "bool_or"
1548boolOrDistinct = unsafeAggregateDistinct "bool_or"
1549
1549
1550-- | A special aggregation that does not require an input
1550-- | A special aggregation that does not require an input
@@ -1552,70 +1552,70 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
1552-- >>> printSQL countStar
1552-- >>> printSQL countStar
1553-- count(*)
1553-- count(*)
1554countStar
1554countStar
1555− :: Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1555+ :: Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
1556countStar = UnsafeExpression $ "count(*)"
1556countStar = UnsafeExpression $ "count(*)"
1557
1557
1558-- | >>> :{
1558-- | >>> :{
1559-- let
1559-- let
1560−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1560+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1561-- expression = count #col
1561-- expression = count #col
1562-- in printSQL expression
1562-- in printSQL expression
1563-- :}
1563-- :}
1564-- count("col")
1564-- count("col")
1565count
1565count
1566− :: Expression db from 'Ungrouped params ty
1566+ :: Expression commons schemas from 'Ungrouped params ty
1567 -- ^ what to count
1567 -- ^ what to count
1568− -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1568+ -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
1569count = unsafeAggregate "count"
1569count = unsafeAggregate "count"
1570
1570
1571-- | >>> :{
1571-- | >>> :{
1572-- let
1572-- let
1573−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1573+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1574-- expression = countDistinct #col
1574-- expression = countDistinct #col
1575-- in printSQL expression
1575-- in printSQL expression
1576-- :}
1576-- :}
1577-- count(DISTINCT "col")
1577-- count(DISTINCT "col")
1578countDistinct
1578countDistinct
1579− :: Expression db from 'Ungrouped params ty
1579+ :: Expression commons schemas from 'Ungrouped params ty
1580 -- ^ what to count
1580 -- ^ what to count
1581− -> Expression db from ('Grouped bys) params ('NotNull 'PGint8)
1581+ -> Expression commons schemas from ('Grouped bys) params ('NotNull 'PGint8)
1582countDistinct = unsafeAggregateDistinct "count"
1582countDistinct = unsafeAggregateDistinct "count"
1583
1583
1584-- | synonym for `boolAnd`
1584-- | synonym for `boolAnd`
1585--
1585--
1586-- >>> :{
1586-- >>> :{
1587-- let
1587-- let
1588−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1588+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1589-- expression = every #col
1589-- expression = every #col
1590-- in printSQL expression
1590-- in printSQL expression
1591-- :}
1591-- :}
1592-- every("col")
1592-- every("col")
1593every
1593every
1594− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1594+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1595 -- ^ what to aggregate
1595 -- ^ what to aggregate
1596− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1596+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1597every = unsafeAggregate "every"
1597every = unsafeAggregate "every"
1598
1598
1599-- | synonym for `boolAndDistinct`
1599-- | synonym for `boolAndDistinct`
1600--
1600--
1601-- >>> :{
1601-- >>> :{
1602-- let
1602-- let
1603−-- expression :: Expression db params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1603+-- expression :: Expression commons schemas params (Grouped bys) '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1604-- expression = everyDistinct #col
1604-- expression = everyDistinct #col
1605-- in printSQL expression
1605-- in printSQL expression
1606-- :}
1606-- :}
1607-- every(DISTINCT "col")
1607-- every(DISTINCT "col")
1608everyDistinct
1608everyDistinct
1609− :: Expression db from 'Ungrouped params (nullity 'PGbool)
1609+ :: Expression commons schemas from 'Ungrouped params (nullity 'PGbool)
1610 -- ^ what to aggregate
1610 -- ^ what to aggregate
1611− -> Expression db from ('Grouped bys) params (nullity 'PGbool)
1611+ -> Expression commons schemas from ('Grouped bys) params (nullity 'PGbool)
1612everyDistinct = unsafeAggregateDistinct "every"
1612everyDistinct = unsafeAggregateDistinct "every"
1613
1613
1614-- | minimum and maximum aggregation
1614-- | minimum and maximum aggregation
1615max_, min_, maxDistinct, minDistinct
1615max_, min_, maxDistinct, minDistinct
1616− :: Expression db from 'Ungrouped params (nullity ty)
1616+ :: Expression commons schemas from 'Ungrouped params (nullity ty)
1617 -- ^ what to aggregate
1617 -- ^ what to aggregate
1618− -> Expression db from ('Grouped bys) params (nullity ty)
1618+ -> Expression commons schemas from ('Grouped bys) params (nullity ty)
1619max_ = unsafeAggregate "max"
1619max_ = unsafeAggregate "max"
1620min_ = unsafeAggregate "min"
1620min_ = unsafeAggregate "min"
1621maxDistinct = unsafeAggregateDistinct "max"
1621maxDistinct = unsafeAggregateDistinct "max"
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+98−93
@@ -21,6 +21,7 @@ Squeal data manipulation language.
21 , RankNTypes
21 , RankNTypes
22 , ScopedTypeVariables
22 , ScopedTypeVariables
23 , TypeApplications
23 , TypeApplications
24+ , TypeFamilies
24 , TypeInType
25 , TypeInType
25 , TypeOperators
26 , TypeOperators
26 , UndecidableInstances
27 , UndecidableInstances
@@ -29,6 +30,7 @@ Squeal data manipulation language.
29module Squeal.PostgreSQL.Manipulation
30module Squeal.PostgreSQL.Manipulation
30 ( -- * Manipulation
31 ( -- * Manipulation
31 Manipulation (..)
32 Manipulation (..)
33+ , Manipulation_
32 , queryStatement
34 , queryStatement
33 , QueryClause (..)
35 , QueryClause (..)
34 , pattern Values_
36 , pattern Values_
@@ -54,6 +56,7 @@ module Squeal.PostgreSQL.Manipulation
54
56
55import Control.DeepSeq
57import Control.DeepSeq
56import Data.ByteString hiding (foldr)
58import Data.ByteString hiding (foldr)
59+import Data.Kind (Type)
57import GHC.TypeLits (KnownSymbol)
60import GHC.TypeLits (KnownSymbol)
58
61
59import qualified Generics.SOP as SOP
62import qualified Generics.SOP as SOP
@@ -75,7 +78,7 @@ simple insert:
75>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
78>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
76>>> :{
79>>> :{
77let
80let
78− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
81+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
79 manipulation =
82 manipulation =
80 insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
83 insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
81in printSQL manipulation
84in printSQL manipulation
@@ -88,7 +91,7 @@ parameterized insert:
88>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
91>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
89>>> :{
92>>> :{
90let
93let
91− manipulation :: Manipulation (DBof (Public Schema)) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
94+ manipulation :: Manipulation '[] (Public Schema) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
92 manipulation =
95 manipulation =
93 insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
96 insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
94in printSQL manipulation
97in printSQL manipulation
@@ -99,7 +102,7 @@ returning insert:
99
102
100>>> :{
103>>> :{
101let
104let
102− manipulation :: Manipulation (DBof (Public Schema)) '[] '["fromOnly" ::: 'NotNull 'PGint4]
105+ manipulation :: Manipulation '[] (Public Schema) '[] '["fromOnly" ::: 'NotNull 'PGint4]
103 manipulation =
106 manipulation =
104 insertInto #tab (Values_ (2 `as` #col1 :* 3 `as` #col2))
107 insertInto #tab (Values_ (2 `as` #col1 :* 3 `as` #col2))
105 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
108 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
@@ -114,7 +117,7 @@ upsert:
114>>> type CustomersSchema = '["customers" ::: 'Table (CustomersConstraints :=> CustomersColumns)]
117>>> type CustomersSchema = '["customers" ::: 'Table (CustomersConstraints :=> CustomersColumns)]
115>>> :{
118>>> :{
116let
119let
117− manipulation :: Manipulation (DBof (Public CustomersSchema)) '[] '[]
120+ manipulation :: Manipulation '[] (Public CustomersSchema) '[] '[]
118 manipulation =
121 manipulation =
119 insertInto #customers
122 insertInto #customers
120 (Values_ ("John Smith" `as` #name :* "john@smith.com" `as` #email))
123 (Values_ ("John Smith" `as` #name :* "john@smith.com" `as` #email))
@@ -129,7 +132,7 @@ query insert:
129
132
130>>> :{
133>>> :{
131let
134let
132− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
135+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
133 manipulation = insertInto_ #tab (Subquery (select Star (from (table #tab))))
136 manipulation = insertInto_ #tab (Subquery (select Star (from (table #tab))))
134in printSQL manipulation
137in printSQL manipulation
135:}
138:}
@@ -139,7 +142,7 @@ update:
139
142
140>>> :{
143>>> :{
141let
144let
142− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
145+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
143 manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
146 manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
144in printSQL manipulation
147in printSQL manipulation
145:}
148:}
@@ -149,7 +152,7 @@ delete:
149
152
150>>> :{
153>>> :{
151let
154let
152− manipulation :: Manipulation (DBof (Public Schema)) '[]
155+ manipulation :: Manipulation '[] (Public Schema) '[]
153 '[ "col1" ::: 'NotNull 'PGint4
156 '[ "col1" ::: 'NotNull 'PGint4
154 , "col2" ::: 'NotNull 'PGint4 ]
157 , "col2" ::: 'NotNull 'PGint4 ]
155 manipulation = deleteFrom #tab NoUsing (#col1 .== #col2) (Returning Star)
158 manipulation = deleteFrom #tab NoUsing (#col1 .== #col2) (Returning Star)
@@ -168,7 +171,7 @@ type Schema3 =
168
171
169>>> :{
172>>> :{
170let
173let
171− manipulation :: Manipulation (DBof (Public Schema3)) '[] '[]
174+ manipulation :: Manipulation '[] (Public Schema3) '[] '[]
172 manipulation =
175 manipulation =
173 deleteFrom_ #tab (Using (table #other_tab & also (table #third_tab)))
176 deleteFrom_ #tab (Using (table #other_tab & also (table #third_tab)))
174 ( (#tab ! #col2 .== #other_tab ! #col2)
177 ( (#tab ! #col2 .== #other_tab ! #col2)
@@ -183,7 +186,7 @@ with manipulation:
183>>> type ProductsSchema = '["products" ::: 'Table ('[] :=> ProductsColumns), "products_deleted" ::: 'Table ('[] :=> ProductsColumns)]
186>>> type ProductsSchema = '["products" ::: 'Table ('[] :=> ProductsColumns), "products_deleted" ::: 'Table ('[] :=> ProductsColumns)]
184>>> :{
187>>> :{
185let
188let
186− manipulation :: Manipulation (DBof (Public ProductsSchema)) '[ 'NotNull 'PGdate] '[]
189+ manipulation :: Manipulation '[] (Public ProductsSchema) '[ 'NotNull 'PGdate] '[]
187 manipulation = with
190 manipulation = with
188 (deleteFrom #products NoUsing (#date .< param @1) (Returning Star) `as` #del)
191 (deleteFrom #products NoUsing (#date .< param @1) (Returning Star) `as` #del)
189 (insertInto_ #products_deleted (Subquery (select Star (from (common #del)))))
192 (insertInto_ #products_deleted (Subquery (select Star (from (common #del)))))
@@ -193,12 +196,13 @@ WITH "del" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RETURNING *)
193-}
196-}
194
197
195newtype Manipulation
198newtype Manipulation
196− (db :: DBType)
199+ (commons :: FromType)
200+ (schemas :: SchemasType)
197 (params :: [NullityType])
201 (params :: [NullityType])
198 (columns :: RowType)
202 (columns :: RowType)
199 = UnsafeManipulation { renderManipulation :: ByteString }
203 = UnsafeManipulation { renderManipulation :: ByteString }
200 deriving (GHC.Generic,Show,Eq,Ord,NFData)
204 deriving (GHC.Generic,Show,Eq,Ord,NFData)
201−instance RenderSQL (Manipulation db params columns) where
205+instance RenderSQL (Manipulation commons schemas params columns) where
202 renderSQL = renderManipulation
206 renderSQL = renderManipulation
203instance With Manipulation where
207instance With Manipulation where
204 with Done manip = manip
208 with Done manip = manip
@@ -206,10 +210,13 @@ instance With Manipulation where
206 "WITH" <+> renderCommonTableExpressions renderSQL cte ctes
210 "WITH" <+> renderCommonTableExpressions renderSQL cte ctes
207 <+> renderSQL manip
211 <+> renderSQL manip
208
212
213+type family Manipulation_ (schemas :: SchemasType) (params :: Type) (row :: Type) where
214+ Manipulation_ schemas params row = Manipulation '[] schemas (TuplePG params) (RowPG row)
215+
209-- | Convert a `Query` into a `Manipulation`.
216-- | Convert a `Query` into a `Manipulation`.
210queryStatement
217queryStatement
211− :: Query db params columns
218+ :: Query commons schemas params columns
212− -> Manipulation db params columns
219+ -> Manipulation commons schemas params columns
213queryStatement q = UnsafeManipulation $ renderSQL q
220queryStatement q = UnsafeManipulation $ renderSQL q
214
221
215{-----------------------------------------
222{-----------------------------------------
@@ -224,18 +231,17 @@ more than one row, but there is no way to insert less than one row.
224Even if you know only some column values, a complete row must be created.
231Even if you know only some column values, a complete row must be created.
225-}
232-}
226insertInto
233insertInto
227− :: ( db ~ (commons :=> schemas)
228− , Has sch schemas schema
234+ :: ( Has sch schemas schema
229 , Has tab schema ('Table table)
235 , Has tab schema ('Table table)
230 , columns ~ TableToColumns table
236 , columns ~ TableToColumns table
231 , row0 ~ TableToRow table
237 , row0 ~ TableToRow table
232 , SOP.SListI columns
238 , SOP.SListI columns
233 , SOP.SListI row1 )
239 , SOP.SListI row1 )
234 => QualifiedAlias sch tab
240 => QualifiedAlias sch tab
235− -> QueryClause db params columns
241+ -> QueryClause commons schemas params columns
236− -> ConflictClause tab db params table
242+ -> ConflictClause tab commons schemas params table
237− -> ReturningClause db params '[tab ::: row0] row1
243+ -> ReturningClause commons schemas params '[tab ::: row0] row1
238− -> Manipulation db params row1
244+ -> Manipulation commons schemas params row1
239insertInto tab qry conflict ret = UnsafeManipulation $
245insertInto tab qry conflict ret = UnsafeManipulation $
240 "INSERT" <+> "INTO" <+> renderSQL tab
246 "INSERT" <+> "INTO" <+> renderSQL tab
241 <+> renderSQL qry
247 <+> renderSQL qry
@@ -243,35 +249,34 @@ insertInto tab qry conflict ret = UnsafeManipulation $
243 <> renderSQL ret
249 <> renderSQL ret
244
250
245insertInto_
251insertInto_
246− :: ( db ~ (commons :=> schemas)
247− , Has sch schemas schema
252+ :: ( Has sch schemas schema
248 , Has tab schema ('Table table)
253 , Has tab schema ('Table table)
249 , columns ~ TableToColumns table
254 , columns ~ TableToColumns table
250 , row ~ TableToRow table
255 , row ~ TableToRow table
251 , SOP.SListI columns )
256 , SOP.SListI columns )
252 => QualifiedAlias sch tab
257 => QualifiedAlias sch tab
253− -> QueryClause db params columns
258+ -> QueryClause commons schemas params columns
254− -> Manipulation db params '[]
259+ -> Manipulation commons schemas params '[]
255insertInto_ tab qry =
260insertInto_ tab qry =
256 insertInto tab qry OnConflictDoRaise (Returning_ Nil)
261 insertInto tab qry OnConflictDoRaise (Returning_ Nil)
257
262
258−data QueryClause db params columns where
263+data QueryClause commons schemas params columns where
259 Values
264 Values
260 :: SOP.SListI columns
265 :: SOP.SListI columns
261− => NP (ColumnExpression db params 'Ungrouped '[]) columns
266+ => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
262− -> [NP (ColumnExpression db params 'Ungrouped '[]) columns]
267+ -> [NP (ColumnExpression schemas params 'Ungrouped '[]) columns]
263− -> QueryClause db params columns
268+ -> QueryClause commons schemas params columns
264 Select
269 Select
265 :: SOP.SListI columns
270 :: SOP.SListI columns
266− => NP (ColumnExpression db params grp from) columns
271+ => NP (ColumnExpression schemas params grp from) columns
267− -> TableExpression db params grp from
272+ -> TableExpression commons schemas params grp from
268− -> QueryClause db params columns
273+ -> QueryClause commons schemas params columns
269 Subquery
274 Subquery
270 :: ColumnsToRow columns ~ row
275 :: ColumnsToRow columns ~ row
271− => Query db params row
276+ => Query commons schemas params row
272− -> QueryClause db params columns
277+ -> QueryClause commons schemas params columns
273
278
274−instance RenderSQL (QueryClause db params columns) where
279+instance RenderSQL (QueryClause commons schemas params columns) where
275 renderSQL = \case
280 renderSQL = \case
276 Values row0 rows ->
281 Values row0 rows ->
277 parenthesized (renderCommaSeparated renderSQLPart row0)
282 parenthesized (renderCommaSeparated renderSQLPart row0)
@@ -287,7 +292,7 @@ instance RenderSQL (QueryClause db params columns) where
287 Subquery qry -> renderQuery qry
292 Subquery qry -> renderQuery qry
288 where
293 where
289 renderSQLPartMaybe, renderValuePartMaybe
294 renderSQLPartMaybe, renderValuePartMaybe
290− :: ColumnExpression db params grp from column -> Maybe ByteString
295+ :: ColumnExpression schemas params grp from column -> Maybe ByteString
291 renderSQLPartMaybe = \case
296 renderSQLPartMaybe = \case
292 DefaultAs _ -> Nothing
297 DefaultAs _ -> Nothing
293 Specific (_ `As` name) -> Just $ renderSQL name
298 Specific (_ `As` name) -> Just $ renderSQL name
@@ -295,7 +300,7 @@ instance RenderSQL (QueryClause db params columns) where
295 DefaultAs _ -> Nothing
300 DefaultAs _ -> Nothing
296 Specific (value `As` _) -> Just $ renderExpression value
301 Specific (value `As` _) -> Just $ renderExpression value
297 renderSQLPart, renderValuePart
302 renderSQLPart, renderValuePart
298− :: ColumnExpression db params grp from column -> ByteString
303+ :: ColumnExpression schemas params grp from column -> ByteString
299 renderSQLPart = \case
304 renderSQLPart = \case
300 DefaultAs name -> renderSQL name
305 DefaultAs name -> renderSQL name
301 Specific (_ `As` name) -> renderSQL name
306 Specific (_ `As` name) -> renderSQL name
@@ -305,49 +310,49 @@ instance RenderSQL (QueryClause db params columns) where
305
310
306pattern Values_
311pattern Values_
307 :: SOP.SListI columns
312 :: SOP.SListI columns
308− => NP (ColumnExpression db params 'Ungrouped '[]) columns
313+ => NP (ColumnExpression schemas params 'Ungrouped '[]) columns
309− -> QueryClause db params columns
314+ -> QueryClause commons schemas params columns
310pattern Values_ vals = Values vals []
315pattern Values_ vals = Values vals []
311
316
312−data ColumnExpression db params grp from column where
317+data ColumnExpression schemas params grp from column where
313 DefaultAs
318 DefaultAs
314 :: KnownSymbol col
319 :: KnownSymbol col
315 => Alias col
320 => Alias col
316− -> ColumnExpression db params grp from (col ::: 'Def :=> ty)
321+ -> ColumnExpression schemas params grp from (col ::: 'Def :=> ty)
317 Specific
322 Specific
318− :: Aliased (Expression db params grp from) (col ::: ty)
323+ :: Aliased (Expression '[] schemas params grp from) (col ::: ty)
319− -> ColumnExpression db params grp from (col ::: defness :=> ty)
324+ -> ColumnExpression schemas params grp from (col ::: defness :=> ty)
320
325
321instance (KnownSymbol col, column ~ (col ::: defness :=> ty))
326instance (KnownSymbol col, column ~ (col ::: defness :=> ty))
322 => Aliasable col
327 => Aliasable col
323− (Expression db params grp from ty)
328+ (Expression '[] schemas params grp from ty)
324− (ColumnExpression db params grp from column) where
329+ (ColumnExpression schemas params grp from column) where
325 expression `as` col = Specific (expression `As` col)
330 expression `as` col = Specific (expression `As` col)
326instance (KnownSymbol col, columns ~ '[col ::: defness :=> ty])
331instance (KnownSymbol col, columns ~ '[col ::: defness :=> ty])
327 => Aliasable col
332 => Aliasable col
328− (Expression db params grp from ty)
333+ (Expression '[] schemas params grp from ty)
329− (NP (ColumnExpression db params grp from) columns) where
334+ (NP (ColumnExpression schemas params grp from) columns) where
330 expression `as` col = expression `as` col :* Nil
335 expression `as` col = expression `as` col :* Nil
331instance (KnownSymbol col, column ~ (col ::: 'Def :=> ty))
336instance (KnownSymbol col, column ~ (col ::: 'Def :=> ty))
332− => DefaultAliasable col (ColumnExpression db params grp from column) where
337+ => DefaultAliasable col (ColumnExpression schemas params grp from column) where
333 defaultAs = DefaultAs
338 defaultAs = DefaultAs
334instance (KnownSymbol col, columns ~ '[col ::: 'Def :=> ty])
339instance (KnownSymbol col, columns ~ '[col ::: 'Def :=> ty])
335− => DefaultAliasable col (NP (ColumnExpression db params grp from) columns) where
340+ => DefaultAliasable col (NP (ColumnExpression schemas params grp from) columns) where
336 defaultAs col = defaultAs col :* Nil
341 defaultAs col = defaultAs col :* Nil
337
342
338instance (HasUnique tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
343instance (HasUnique tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
339− => IsLabel col (ColumnExpression db params 'Ungrouped from column) where
344+ => IsLabel col (ColumnExpression schemas params 'Ungrouped from column) where
340 fromLabel = fromLabel @col `as` Alias
345 fromLabel = fromLabel @col `as` Alias
341instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
346instance (HasUnique tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
342 => IsLabel col
347 => IsLabel col
343− (NP (ColumnExpression db params 'Ungrouped from) columns) where
348+ (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
344 fromLabel = fromLabel @col `as` Alias
349 fromLabel = fromLabel @col `as` Alias
345
350
346instance (Has tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
351instance (Has tab from row, Has col row ty, column ~ (col ::: defness :=> ty))
347− => IsQualified tab col (ColumnExpression db params 'Ungrouped from column) where
352+ => IsQualified tab col (ColumnExpression schemas params 'Ungrouped from column) where
348 tab ! col = tab ! col `as` col
353 tab ! col = tab ! col `as` col
349instance (Has tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
354instance (Has tab from row, Has col row ty, columns ~ '[col ::: defness :=> ty])
350− => IsQualified tab col (NP (ColumnExpression db params 'Ungrouped from) columns) where
355+ => IsQualified tab col (NP (ColumnExpression schemas params 'Ungrouped from) columns) where
351 tab ! col = tab ! col `as` col
356 tab ! col = tab ! col `as` col
352
357
353instance
358instance
@@ -356,7 +361,7 @@ instance
356 , GroupedBy tab col bys
361 , GroupedBy tab col bys
357 , column ~ (col ::: defness :=> ty)
362 , column ~ (col ::: defness :=> ty)
358 ) => IsLabel col
363 ) => IsLabel col
359− (ColumnExpression db params ('Grouped bys) from column) where
364+ (ColumnExpression schemas params ('Grouped bys) from column) where
360 fromLabel = fromLabel @col `as` Alias
365 fromLabel = fromLabel @col `as` Alias
361instance
366instance
362 ( HasUnique tab from row
367 ( HasUnique tab from row
@@ -364,7 +369,7 @@ instance
364 , GroupedBy tab col bys
369 , GroupedBy tab col bys
365 , columns ~ '[col ::: defness :=> ty]
370 , columns ~ '[col ::: defness :=> ty]
366 ) => IsLabel col
371 ) => IsLabel col
367− (NP (ColumnExpression db params ('Grouped bys) from) columns) where
372+ (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
368 fromLabel = fromLabel @col `as` Alias
373 fromLabel = fromLabel @col `as` Alias
369
374
370instance
375instance
@@ -373,7 +378,7 @@ instance
373 , GroupedBy tab col bys
378 , GroupedBy tab col bys
374 , column ~ (col ::: defness :=> ty)
379 , column ~ (col ::: defness :=> ty)
375 ) => IsQualified tab col
380 ) => IsQualified tab col
376− (ColumnExpression db params ('Grouped bys) from column) where
381+ (ColumnExpression schemas params ('Grouped bys) from column) where
377 tab ! col = tab ! col `as` col
382 tab ! col = tab ! col `as` col
378instance
383instance
379 ( Has tab from row
384 ( Has tab from row
@@ -381,10 +386,10 @@ instance
381 , GroupedBy tab col bys
386 , GroupedBy tab col bys
382 , columns ~ '[col ::: defness :=> ty]
387 , columns ~ '[col ::: defness :=> ty]
383 ) => IsQualified tab col
388 ) => IsQualified tab col
384− (NP (ColumnExpression db params ('Grouped bys) from) columns) where
389+ (NP (ColumnExpression schemas params ('Grouped bys) from) columns) where
385 tab ! col = tab ! col :* Nil
390 tab ! col = tab ! col :* Nil
386
391
387−instance RenderSQL (ColumnExpression db params grp from column) where
392+instance RenderSQL (ColumnExpression schemas params grp from column) where
388 renderSQL = \case
393 renderSQL = \case
389 DefaultAs col ->
394 DefaultAs col ->
390 renderSQL col <+> "=" <+> "DEFAULT"
395 renderSQL col <+> "=" <+> "DEFAULT"
@@ -401,18 +406,18 @@ instance RenderSQL (ColumnExpression db params grp from column) where
401-- the row will not be returned. `ReturningStar` will return all columns
406-- the row will not be returned. `ReturningStar` will return all columns
402-- in the row. Use @Returning Nil@ in the common case where no return
407-- in the row. Use @Returning Nil@ in the common case where no return
403-- values are desired.
408-- values are desired.
404−newtype ReturningClause db params from row =
409+newtype ReturningClause commons schemas params from row =
405− Returning (Selection db params 'Ungrouped from row)
410+ Returning (Selection commons schemas params 'Ungrouped from row)
406
411
407−instance RenderSQL (ReturningClause db params from row) where
412+instance RenderSQL (ReturningClause commons schemas params from row) where
408 renderSQL = \case
413 renderSQL = \case
409 Returning (List Nil) -> ""
414 Returning (List Nil) -> ""
410 Returning selection -> " RETURNING" <+> renderSQL selection
415 Returning selection -> " RETURNING" <+> renderSQL selection
411
416
412pattern Returning_
417pattern Returning_
413 :: SOP.SListI row
418 :: SOP.SListI row
414− => NP (Aliased (Expression db params 'Ungrouped from)) row
419+ => NP (Aliased (Expression commons schemas params 'Ungrouped from)) row
415− -> ReturningClause db params from row
420+ -> ReturningClause commons schemas params from row
416pattern Returning_ list = Returning (List list)
421pattern Returning_ list = Returning (List list)
417
422
418-- | A `ConflictClause` specifies an action to perform upon a constraint
423-- | A `ConflictClause` specifies an action to perform upon a constraint
@@ -420,34 +425,34 @@ pattern Returning_ list = Returning (List list)
420-- `OnConflictDoNothing` simply avoids inserting a row.
425-- `OnConflictDoNothing` simply avoids inserting a row.
421-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
426-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
422-- proposed for insertion.
427-- proposed for insertion.
423−data ConflictClause tab db params table where
428+data ConflictClause tab commons schemas params table where
424− OnConflictDoRaise :: ConflictClause tab db params table
429+ OnConflictDoRaise :: ConflictClause tab commons schemas params table
425 OnConflict
430 OnConflict
426 :: ConflictTarget constraints
431 :: ConflictTarget constraints
427− -> ConflictAction tab db params columns
432+ -> ConflictAction tab commons schemas params columns
428− -> ConflictClause tab db params (constraints :=> columns)
433+ -> ConflictClause tab commons schemas params (constraints :=> columns)
429
434
430-- | Render a `ConflictClause`.
435-- | Render a `ConflictClause`.
431instance SOP.SListI (TableToColumns table)
436instance SOP.SListI (TableToColumns table)
432− => RenderSQL (ConflictClause tab db params table) where
437+ => RenderSQL (ConflictClause tab commons schemas params table) where
433 renderSQL = \case
438 renderSQL = \case
434 OnConflictDoRaise -> ""
439 OnConflictDoRaise -> ""
435 OnConflict target action -> " ON CONFLICT"
440 OnConflict target action -> " ON CONFLICT"
436 <+> renderSQL target <+> renderSQL action
441 <+> renderSQL target <+> renderSQL action
437
442
438−data ConflictAction tab db params columns where
443+data ConflictAction tab commons schemas params columns where
439− DoNothing :: ConflictAction tab db params columns
444+ DoNothing :: ConflictAction tab commons schemas params columns
440 DoUpdate
445 DoUpdate
441 :: ( row ~ ColumnsToRow columns
446 :: ( row ~ ColumnsToRow columns
442 , SOP.SListI columns
447 , SOP.SListI columns
443 , columns ~ (col0 ': cols)
448 , columns ~ (col0 ': cols)
444 , SOP.All (HasIn columns) subcolumns
449 , SOP.All (HasIn columns) subcolumns
445 , AllUnique subcolumns )
450 , AllUnique subcolumns )
446− => NP (ColumnExpression db params 'Ungrouped '[tab ::: row, "excluded" ::: row]) subcolumns
451+ => NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]) subcolumns
447− -> [Condition db params 'Ungrouped '[tab ::: row, "excluded" ::: row]]
452+ -> [Condition commons schemas params 'Ungrouped '[tab ::: row, "excluded" ::: row]]
448− -> ConflictAction tab db params columns
453+ -> ConflictAction tab commons schemas params columns
449
454
450−instance RenderSQL (ConflictAction tab db params columns) where
455+instance RenderSQL (ConflictAction tab commons schemas params columns) where
451 renderSQL = \case
456 renderSQL = \case
452 DoNothing -> "DO NOTHING"
457 DoNothing -> "DO NOTHING"
453 DoUpdate updates whs'
458 DoUpdate updates whs'
@@ -487,12 +492,12 @@ update
487 , SOP.All (HasIn columns) subcolumns
492 , SOP.All (HasIn columns) subcolumns
488 , AllUnique subcolumns )
493 , AllUnique subcolumns )
489 => QualifiedAlias sch tab -- ^ table to update
494 => QualifiedAlias sch tab -- ^ table to update
490− -> NP (ColumnExpression db params 'Ungrouped '[tab ::: row0]) subcolumns
495+ -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row0]) subcolumns
491 -- ^ modified values to replace old values
496 -- ^ modified values to replace old values
492− -> Condition db params 'Ungrouped '[tab ::: row0]
497+ -> Condition commons schemas params 'Ungrouped '[tab ::: row0]
493 -- ^ condition under which to perform update on a row
498 -- ^ condition under which to perform update on a row
494− -> ReturningClause db params '[tab ::: row0] row1 -- ^ results to return
499+ -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
495− -> Manipulation db params row1
500+ -> Manipulation commons schemas params row1
496update tab columns wh returning = UnsafeManipulation $
501update tab columns wh returning = UnsafeManipulation $
497 "UPDATE"
502 "UPDATE"
498 <+> renderSQL tab
503 <+> renderSQL tab
@@ -512,22 +517,22 @@ update_
512 , SOP.All (HasIn columns) subcolumns
517 , SOP.All (HasIn columns) subcolumns
513 , AllUnique subcolumns )
518 , AllUnique subcolumns )
514 => QualifiedAlias sch tab -- ^ table to update
519 => QualifiedAlias sch tab -- ^ table to update
515− -> NP (ColumnExpression db params 'Ungrouped '[tab ::: row]) subcolumns
520+ -> NP (ColumnExpression schemas params 'Ungrouped '[tab ::: row]) subcolumns
516 -- ^ modified values to replace old values
521 -- ^ modified values to replace old values
517− -> Condition db params 'Ungrouped '[tab ::: row]
522+ -> Condition commons schemas params 'Ungrouped '[tab ::: row]
518 -- ^ condition under which to perform update on a row
523 -- ^ condition under which to perform update on a row
519− -> Manipulation db params '[]
524+ -> Manipulation commons schemas params '[]
520update_ tab columns wh = update tab columns wh (Returning_ Nil)
525update_ tab columns wh = update tab columns wh (Returning_ Nil)
521
526
522{-----------------------------------------
527{-----------------------------------------
523DELETE statements
528DELETE statements
524-----------------------------------------}
529-----------------------------------------}
525
530
526−data UsingClause db params from where
531+data UsingClause commons schemas params from where
527− NoUsing :: UsingClause db params '[]
532+ NoUsing :: UsingClause commons schemas params '[]
528 Using
533 Using
529− :: FromClause db params from
534+ :: FromClause commons schemas params from
530− -> UsingClause db params from
535+ -> UsingClause commons schemas params from
531
536
532-- | Delete rows from a table.
537-- | Delete rows from a table.
533deleteFrom
538deleteFrom
@@ -538,11 +543,11 @@ deleteFrom
538 , row0 ~ TableToRow table
543 , row0 ~ TableToRow table
539 , columns ~ TableToColumns table )
544 , columns ~ TableToColumns table )
540 => QualifiedAlias sch tab -- ^ table to delete from
545 => QualifiedAlias sch tab -- ^ table to delete from
541− -> UsingClause db params from
546+ -> UsingClause commons schemas params from
542− -> Condition db params 'Ungrouped (tab ::: row0 ': from)
547+ -> Condition commons schemas params 'Ungrouped (tab ::: row0 ': from)
543 -- ^ condition under which to delete a row
548 -- ^ condition under which to delete a row
544− -> ReturningClause db params '[tab ::: row0] row1 -- ^ results to return
549+ -> ReturningClause commons schemas params '[tab ::: row0] row1 -- ^ results to return
545− -> Manipulation db params row1
550+ -> Manipulation commons schemas params row1
546deleteFrom tab using wh returning = UnsafeManipulation $
551deleteFrom tab using wh returning = UnsafeManipulation $
547 "DELETE FROM"
552 "DELETE FROM"
548 <+> renderSQL tab
553 <+> renderSQL tab
@@ -560,10 +565,10 @@ deleteFrom_
560 , row ~ TableToRow table
565 , row ~ TableToRow table
561 , columns ~ TableToColumns table )
566 , columns ~ TableToColumns table )
562 => QualifiedAlias sch tab -- ^ table to delete from
567 => QualifiedAlias sch tab -- ^ table to delete from
563− -> UsingClause db params from
568+ -> UsingClause commons schemas params from
564− -> Condition db params 'Ungrouped (tab ::: row ': from)
569+ -> Condition commons schemas params 'Ungrouped (tab ::: row ': from)
565 -- ^ condition under which to delete a row
570 -- ^ condition under which to delete a row
566− -> Manipulation db params '[]
571+ -> Manipulation commons schemas params '[]
567deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
572deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
568
573
569-- | This has the behaviour of a cartesian product, taking all
574-- | This has the behaviour of a cartesian product, taking all
@@ -572,10 +577,10 @@ deleteFrom_ tab uses wh = deleteFrom tab uses wh (Returning_ Nil)
572-- a comma separated list of tables. Typical case is the `USING` clause
577-- a comma separated list of tables. Typical case is the `USING` clause
573-- of a DELETE query.
578-- of a DELETE query.
574also
579also
575− :: FromClause schema params right
580+ :: FromClause commons schemas params right
576 -- ^ right
581 -- ^ right
577− -> FromClause schema params left
582+ -> FromClause commons schemas params left
578 -- ^ left
583 -- ^ left
579− -> FromClause schema params (Join left right)
584+ -> FromClause commons schemas params (Join left right)
580also right left = UnsafeFromClause $
585also right left = UnsafeFromClause $
581 renderSQL left <> "," <+> renderSQL right
586 renderSQL left <> "," <+> renderSQL right
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+3−3
@@ -275,21 +275,21 @@ createMigrations =
275-- | Inserts a `Migration` into the `MigrationsTable`
275-- | Inserts a `Migration` into the `MigrationsTable`
276insertMigration
276insertMigration
277 :: Has "migrations" schemas MigrationsSchema
277 :: Has "migrations" schemas MigrationsSchema
278− => Manipulation ('[] :=> schemas) '[ 'NotNull 'PGtext] '[]
278+ => Manipulation '[] schemas '[ 'NotNull 'PGtext] '[]
279insertMigration = insertInto_ (#migrations ! #schema_migrations) . Values_ $
279insertMigration = insertInto_ (#migrations ! #schema_migrations) . Values_ $
280 (param @1) `as` #name :* defaultAs #executed_at
280 (param @1) `as` #name :* defaultAs #executed_at
281
281
282-- | Deletes a `Migration` from the `MigrationsTable`
282-- | Deletes a `Migration` from the `MigrationsTable`
283deleteMigration
283deleteMigration
284 :: Has "migrations" schemas MigrationsSchema
284 :: Has "migrations" schemas MigrationsSchema
285− => Manipulation ('[] :=> schemas) '[ 'NotNull 'PGtext ] '[]
285+ => Manipulation '[] schemas '[ 'NotNull 'PGtext ] '[]
286deleteMigration = deleteFrom_ (#migrations ! #schema_migrations) NoUsing (#name .== param @1)
286deleteMigration = deleteFrom_ (#migrations ! #schema_migrations) NoUsing (#name .== param @1)
287
287
288-- | Selects a `Migration` from the `MigrationsTable`, returning
288-- | Selects a `Migration` from the `MigrationsTable`, returning
289-- the time at which it was executed.
289-- the time at which it was executed.
290selectMigration
290selectMigration
291 :: Has "migrations" schemas MigrationsSchema
291 :: Has "migrations" schemas MigrationsSchema
292− => Query ('[] :=> schemas) '[ 'NotNull 'PGtext ]
292+ => Query '[] schemas '[ 'NotNull 'PGtext ]
293 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
293 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
294selectMigration = select_
294selectMigration = select_
295 (#executed_at `as` #executed_at)
295 (#executed_at `as` #executed_at)
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+14−14
@@ -315,63 +315,63 @@ a default instance.
315class Monad pq => MonadPQ schemas pq | pq -> schemas where
315class Monad pq => MonadPQ schemas pq | pq -> schemas where
316 manipulateParams
316 manipulateParams
317 :: ToParams x params
317 :: ToParams x params
318− => Manipulation ('[] :=> schemas) params ys
318+ => Manipulation '[] schemas params ys
319 -- ^ `insertRows`, `update` or `deleteFrom`
319 -- ^ `insertRows`, `update` or `deleteFrom`
320 -> x -> pq (K LibPQ.Result ys)
320 -> x -> pq (K LibPQ.Result ys)
321 default manipulateParams
321 default manipulateParams
322 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
322 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
323 => ToParams x params
323 => ToParams x params
324− => Manipulation ('[] :=> schemas) params ys
324+ => Manipulation '[] schemas params ys
325 -- ^ `insertRows`, `update` or `deleteFrom`
325 -- ^ `insertRows`, `update` or `deleteFrom`
326 -> x -> pq (K LibPQ.Result ys)
326 -> x -> pq (K LibPQ.Result ys)
327 manipulateParams manipulation params = lift $
327 manipulateParams manipulation params = lift $
328 manipulateParams manipulation params
328 manipulateParams manipulation params
329
329
330− manipulate :: Manipulation ('[] :=> schemas) '[] ys -> pq (K LibPQ.Result ys)
330+ manipulate :: Manipulation '[] schemas '[] ys -> pq (K LibPQ.Result ys)
331 manipulate statement = manipulateParams statement ()
331 manipulate statement = manipulateParams statement ()
332
332
333 runQueryParams
333 runQueryParams
334 :: ToParams x params
334 :: ToParams x params
335− => Query ('[] :=> schemas) params ys
335+ => Query '[] schemas params ys
336 -- ^ `select` and friends
336 -- ^ `select` and friends
337 -> x -> pq (K LibPQ.Result ys)
337 -> x -> pq (K LibPQ.Result ys)
338 runQueryParams = manipulateParams . queryStatement
338 runQueryParams = manipulateParams . queryStatement
339
339
340 runQuery
340 runQuery
341− :: Query ('[] :=> schemas) '[] ys
341+ :: Query '[] schemas '[] ys
342 -- ^ `select` and friends
342 -- ^ `select` and friends
343 -> pq (K LibPQ.Result ys)
343 -> pq (K LibPQ.Result ys)
344 runQuery q = runQueryParams q ()
344 runQuery q = runQueryParams q ()
345
345
346 traversePrepared
346 traversePrepared
347 :: (ToParams x params, Traversable list)
347 :: (ToParams x params, Traversable list)
348− => Manipulation ('[] :=> schemas) params ys
348+ => Manipulation '[] schemas params ys
349 -- ^ `insertRows`, `update`, or `deleteFrom`, and friends
349 -- ^ `insertRows`, `update`, or `deleteFrom`, and friends
350 -> list x -> pq (list (K LibPQ.Result ys))
350 -> list x -> pq (list (K LibPQ.Result ys))
351 default traversePrepared
351 default traversePrepared
352 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
352 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
353 => (ToParams x params, Traversable list)
353 => (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))
355 traversePrepared manipulation params = lift $
355 traversePrepared manipulation params = lift $
356 traversePrepared manipulation params
356 traversePrepared manipulation params
357
357
358 forPrepared
358 forPrepared
359 :: (ToParams x params, Traversable list)
359 :: (ToParams x params, Traversable list)
360 => list x
360 => list x
361− -> Manipulation ('[] :=> schemas) params ys
361+ -> Manipulation '[] schemas params ys
362 -- ^ `insertRows`, `update` or `deleteFrom`
362 -- ^ `insertRows`, `update` or `deleteFrom`
363 -> pq (list (K LibPQ.Result ys))
363 -> pq (list (K LibPQ.Result ys))
364 forPrepared = flip traversePrepared
364 forPrepared = flip traversePrepared
365
365
366 traversePrepared_
366 traversePrepared_
367 :: (ToParams x params, Foldable list)
367 :: (ToParams x params, Foldable list)
368− => Manipulation ('[] :=> schemas) params '[]
368+ => Manipulation '[] schemas params '[]
369 -- ^ `insertRows`, `update` or `deleteFrom`
369 -- ^ `insertRows`, `update` or `deleteFrom`
370 -> list x -> pq ()
370 -> list x -> pq ()
371 default traversePrepared_
371 default traversePrepared_
372 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
372 :: (MonadTrans t, MonadPQ schemas pq1, pq ~ t pq1)
373 => (ToParams x params, Foldable list)
373 => (ToParams x params, Foldable list)
374− => Manipulation ('[] :=> schemas) params '[]
374+ => Manipulation '[] schemas params '[]
375 -- ^ `insertRows`, `update` or `deleteFrom`
375 -- ^ `insertRows`, `update` or `deleteFrom`
376 -> list x -> pq ()
376 -> list x -> pq ()
377 traversePrepared_ manipulation params = lift $
377 traversePrepared_ manipulation params = lift $
@@ -380,7 +380,7 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where
380 forPrepared_
380 forPrepared_
381 :: (ToParams x params, Foldable list)
381 :: (ToParams x params, Foldable list)
382 => list x
382 => list x
383− -> Manipulation ('[] :=> schemas) params '[]
383+ -> Manipulation '[] schemas params '[]
384 -- ^ `insertRows`, `update` or `deleteFrom`
384 -- ^ `insertRows`, `update` or `deleteFrom`
385 -> pq ()
385 -> pq ()
386 forPrepared_ = flip traversePrepared_
386 forPrepared_ = flip traversePrepared_
@@ -395,7 +395,7 @@ instance (MonadBase IO io, schemas0 ~ schemas, schemas1 ~ schemas)
395 => MonadPQ schemas (PQ schemas0 schemas1 io) where
395 => MonadPQ schemas (PQ schemas0 schemas1 io) where
396
396
397 manipulateParams
397 manipulateParams
398− (UnsafeManipulation q :: Manipulation ('[] :=> schemas) ps ys) (params :: x) =
398+ (UnsafeManipulation q :: Manipulation '[] schemas ps ys) (params :: x) =
399 PQ $ \ (K conn) -> do
399 PQ $ \ (K conn) -> do
400 let
400 let
401 toParam' encoding =
401 toParam' encoding =
@@ -411,7 +411,7 @@ instance (MonadBase IO io, schemas0 ~ schemas, schemas1 ~ schemas)
411 return $ K (K result)
411 return $ K (K result)
412
412
413 traversePrepared
413 traversePrepared
414− (UnsafeManipulation q :: Manipulation ('[] :=> schemas) xs ys) (list :: list x) =
414+ (UnsafeManipulation q :: Manipulation '[] schemas xs ys) (list :: list x) =
415 PQ $ \ (K conn) -> liftBase $ do
415 PQ $ \ (K conn) -> liftBase $ do
416 let temp = "temporary_statement"
416 let temp = "temporary_statement"
417 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
417 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
@@ -438,7 +438,7 @@ instance (MonadBase IO io, schemas0 ~ schemas, schemas1 ~ schemas)
438 return (K results)
438 return (K results)
439
439
440 traversePrepared_
440 traversePrepared_
441− (UnsafeManipulation q :: Manipulation ('[] :=> schemas) xs '[]) (list :: list x) =
441+ (UnsafeManipulation q :: Manipulation '[] schemas xs '[]) (list :: list x) =
442 PQ $ \ (K conn) -> liftBase $ do
442 PQ $ \ (K conn) -> liftBase $ do
443 let temp = "temporary_statement"
443 let temp = "temporary_statement"
444 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
444 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+297−292
@@ -31,6 +31,7 @@ Squeal queries.
31module Squeal.PostgreSQL.Query
31module Squeal.PostgreSQL.Query
32 ( -- * Queries
32 ( -- * Queries
33 Query (..)
33 Query (..)
34+ , Query_
34 -- ** Select
35 -- ** Select
35 , select
36 , select
36 , select_
37 , select_
@@ -124,6 +125,7 @@ module Squeal.PostgreSQL.Query
124
125
125import Control.DeepSeq
126import Control.DeepSeq
126import Data.ByteString (ByteString)
127import Data.ByteString (ByteString)
128+import Data.Kind (Type)
127import Data.String
129import Data.String
128import Data.Word
130import Data.Word
129import Generics.SOP hiding (from)
131import Generics.SOP hiding (from)
@@ -145,7 +147,7 @@ simple query:
145>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
147>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
146>>> :{
148>>> :{
147let
149let
148− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
150+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
149 query = select Star (from (table #tab))
151 query = select Star (from (table #tab))
150in printSQL query
152in printSQL query
151:}
153:}
@@ -155,7 +157,7 @@ restricted query:
155
157
156>>> :{
158>>> :{
157let
159let
158− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
160+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
159 query =
161 query =
160 select_ ((#col1 + #col2) `as` #sum :* #col1)
162 select_ ((#col1 + #col2) `as` #sum :* #col1)
161 ( from (table #tab)
163 ( from (table #tab)
@@ -169,7 +171,7 @@ subquery:
169
171
170>>> :{
172>>> :{
171let
173let
172− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
174+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
173 query = select Star (from (subquery (select Star (from (table #tab)) `as` #sub)))
175 query = select Star (from (subquery (select Star (from (table #tab)) `as` #sub)))
174in printSQL query
176in printSQL query
175:}
177:}
@@ -179,7 +181,7 @@ limits and offsets:
179
181
180>>> :{
182>>> :{
181let
183let
182− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
184+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
183 query = select Star (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
185 query = select Star (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
184in printSQL query
186in printSQL query
185:}
187:}
@@ -189,7 +191,7 @@ parameterized query:
189
191
190>>> :{
192>>> :{
191let
193let
192− query :: Query (DBof (Public Schema)) '[ 'NotNull 'PGint4] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
194+ query :: Query '[] (Public Schema) '[ 'NotNull 'PGint4] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
193 query = select Star (from (table #tab) & where_ (#col1 .> param @1))
195 query = select Star (from (table #tab) & where_ (#col1 .> param @1))
194in printSQL query
196in printSQL query
195:}
197:}
@@ -199,7 +201,7 @@ aggregation query:
199
201
200>>> :{
202>>> :{
201let
203let
202− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
204+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
203 query =
205 query =
204 select_ (sum_ #col2 `as` #sum :* #col1)
206 select_ (sum_ #col2 `as` #sum :* #col1)
205 ( from (table (#tab `as` #table1))
207 ( from (table (#tab `as` #table1))
@@ -213,7 +215,7 @@ sorted query:
213
215
214>>> :{
216>>> :{
215let
217let
216− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
218+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
217 query = select Star (from (table #tab) & orderBy [#col1 & Asc])
219 query = select Star (from (table #tab) & orderBy [#col1 & Asc])
218in printSQL query
220in printSQL query
219:}
221:}
@@ -250,7 +252,7 @@ type OrdersSchema =
250
252
251>>> :{
253>>> :{
252let
254let
253− query :: Query (DBof (Public OrdersSchema))
255+ query :: Query '[] (Public OrdersSchema)
254 '[]
256 '[]
255 '[ "order_price" ::: 'NotNull 'PGfloat4
257 '[ "order_price" ::: 'NotNull 'PGfloat4
256 , "customer_name" ::: 'NotNull 'PGtext
258 , "customer_name" ::: 'NotNull 'PGtext
@@ -273,7 +275,7 @@ self-join:
273
275
274>>> :{
276>>> :{
275let
277let
276− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
278+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
277 query = select (#t1 & DotStar) (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
279 query = select (#t1 & DotStar) (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
278in printSQL query
280in printSQL query
279:}
281:}
@@ -283,7 +285,7 @@ value queries:
283
285
284>>> :{
286>>> :{
285let
287let
286− query :: Query db '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
288+ query :: Query commons schemas '[] '["foo" ::: 'NotNull 'PGint2, "bar" ::: 'NotNull 'PGbool]
287 query = values (1 `as` #foo :* true `as` #bar) [2 `as` #foo :* false `as` #bar]
289 query = values (1 `as` #foo :* true `as` #bar) [2 `as` #foo :* false `as` #bar]
288in printSQL query
290in printSQL query
289:}
291:}
@@ -293,7 +295,7 @@ set operations:
293
295
294>>> :{
296>>> :{
295let
297let
296− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
298+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
297 query = select Star (from (table #tab)) `unionAll` select Star (from (table #tab))
299 query = select Star (from (table #tab)) `unionAll` select Star (from (table #tab))
298in printSQL query
300in printSQL query
299:}
301:}
@@ -303,7 +305,7 @@ with queries:
303
305
304>>> :{
306>>> :{
305let
307let
306− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
308+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
307 query = with (
309 query = with (
308 select Star (from (table #tab)) `as` #cte1 :>>
310 select Star (from (table #tab)) `as` #cte1 :>>
309 select Star (from (common #cte1)) `as` #cte2
311 select Star (from (common #cte1)) `as` #cte2
@@ -313,19 +315,23 @@ in printSQL query
313WITH "cte1" AS (SELECT * FROM "tab" AS "tab"), "cte2" AS (SELECT * FROM "cte1" AS "cte1") SELECT * FROM "cte2" AS "cte2"
315WITH "cte1" AS (SELECT * FROM "tab" AS "tab"), "cte2" AS (SELECT * FROM "cte1" AS "cte1") SELECT * FROM "cte2" AS "cte2"
314-}
316-}
315newtype Query
317newtype Query
316− (db :: DBType)
318+ (commons :: FromType)
319+ (schemas :: SchemasType)
317 (params :: [NullityType])
320 (params :: [NullityType])
318− (columns :: RowType)
321+ (row :: RowType)
319 = UnsafeQuery { renderQuery :: ByteString }
322 = UnsafeQuery { renderQuery :: ByteString }
320 deriving (GHC.Generic,Show,Eq,Ord,NFData)
323 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)
322
328
323-- | The results of two queries can be combined using the set operation
329-- | The results of two queries can be combined using the set operation
324-- `union`. Duplicate rows are eliminated.
330-- `union`. Duplicate rows are eliminated.
325union
331union
326− :: Query db params columns
332+ :: Query commons schemas params columns
327− -> Query db params columns
333+ -> Query commons schemas params columns
328− -> Query db params columns
334+ -> Query commons schemas params columns
329q1 `union` q2 = UnsafeQuery $
335q1 `union` q2 = UnsafeQuery $
330 parenthesized (renderSQL q1)
336 parenthesized (renderSQL q1)
331 <+> "UNION"
337 <+> "UNION"
@@ -334,9 +340,9 @@ q1 `union` q2 = UnsafeQuery $
334-- | The results of two queries can be combined using the set operation
340-- | The results of two queries can be combined using the set operation
335-- `unionAll`, the disjoint union. Duplicate rows are retained.
341-- `unionAll`, the disjoint union. Duplicate rows are retained.
336unionAll
342unionAll
337− :: Query db params columns
343+ :: Query commons schemas params columns
338− -> Query db params columns
344+ -> Query commons schemas params columns
339− -> Query db params columns
345+ -> Query commons schemas params columns
340q1 `unionAll` q2 = UnsafeQuery $
346q1 `unionAll` q2 = UnsafeQuery $
341 parenthesized (renderSQL q1)
347 parenthesized (renderSQL q1)
342 <+> "UNION" <+> "ALL"
348 <+> "UNION" <+> "ALL"
@@ -345,9 +351,9 @@ q1 `unionAll` q2 = UnsafeQuery $
345-- | The results of two queries can be combined using the set operation
351-- | The results of two queries can be combined using the set operation
346-- `intersect`, the intersection. Duplicate rows are eliminated.
352-- `intersect`, the intersection. Duplicate rows are eliminated.
347intersect
353intersect
348− :: Query db params columns
354+ :: Query commons schemas params columns
349− -> Query db params columns
355+ -> Query commons schemas params columns
350− -> Query db params columns
356+ -> Query commons schemas params columns
351q1 `intersect` q2 = UnsafeQuery $
357q1 `intersect` q2 = UnsafeQuery $
352 parenthesized (renderSQL q1)
358 parenthesized (renderSQL q1)
353 <+> "INTERSECT"
359 <+> "INTERSECT"
@@ -356,9 +362,9 @@ q1 `intersect` q2 = UnsafeQuery $
356-- | The results of two queries can be combined using the set operation
362-- | The results of two queries can be combined using the set operation
357-- `intersectAll`, the intersection. Duplicate rows are retained.
363-- `intersectAll`, the intersection. Duplicate rows are retained.
358intersectAll
364intersectAll
359− :: Query db params columns
365+ :: Query commons schemas params columns
360− -> Query db params columns
366+ -> Query commons schemas params columns
361− -> Query db params columns
367+ -> Query commons schemas params columns
362q1 `intersectAll` q2 = UnsafeQuery $
368q1 `intersectAll` q2 = UnsafeQuery $
363 parenthesized (renderSQL q1)
369 parenthesized (renderSQL q1)
364 <+> "INTERSECT" <+> "ALL"
370 <+> "INTERSECT" <+> "ALL"
@@ -367,9 +373,9 @@ q1 `intersectAll` q2 = UnsafeQuery $
367-- | The results of two queries can be combined using the set operation
373-- | The results of two queries can be combined using the set operation
368-- `except`, the set difference. Duplicate rows are eliminated.
374-- `except`, the set difference. Duplicate rows are eliminated.
369except
375except
370− :: Query db params columns
376+ :: Query commons schemas params columns
371− -> Query db params columns
377+ -> Query commons schemas params columns
372− -> Query db params columns
378+ -> Query commons schemas params columns
373q1 `except` q2 = UnsafeQuery $
379q1 `except` q2 = UnsafeQuery $
374 parenthesized (renderSQL q1)
380 parenthesized (renderSQL q1)
375 <+> "EXCEPT"
381 <+> "EXCEPT"
@@ -378,9 +384,9 @@ q1 `except` q2 = UnsafeQuery $
378-- | The results of two queries can be combined using the set operation
384-- | The results of two queries can be combined using the set operation
379-- `exceptAll`, the set difference. Duplicate rows are retained.
385-- `exceptAll`, the set difference. Duplicate rows are retained.
380exceptAll
386exceptAll
381− :: Query db params columns
387+ :: Query commons schemas params columns
382− -> Query db params columns
388+ -> Query commons schemas params columns
383− -> Query db params columns
389+ -> Query commons schemas params columns
384q1 `exceptAll` q2 = UnsafeQuery $
390q1 `exceptAll` q2 = UnsafeQuery $
385 parenthesized (renderSQL q1)
391 parenthesized (renderSQL q1)
386 <+> "EXCEPT" <+> "ALL"
392 <+> "EXCEPT" <+> "ALL"
@@ -390,49 +396,49 @@ q1 `exceptAll` q2 = UnsafeQuery $
390SELECT queries
396SELECT queries
391-----------------------------------------}
397-----------------------------------------}
392
398
393−data Selection db params grp from row where
399+data Selection commons schemas params grp from row where
394 List
400 List
395 :: SListI row
401 :: SListI row
396− => NP (Aliased (Expression db params grp from)) row
402+ => NP (Aliased (Expression commons schemas params grp from)) row
397− -> Selection db params grp from row
403+ -> Selection commons schemas params grp from row
398 Star
404 Star
399 :: HasUnique tab from row
405 :: HasUnique tab from row
400− => Selection db params 'Ungrouped from row
406+ => Selection commons schemas params 'Ungrouped from row
401 DotStar
407 DotStar
402 :: Has tab from row
408 :: Has tab from row
403 => Alias tab
409 => Alias tab
404− -> Selection db params 'Ungrouped from row
410+ -> Selection commons schemas params 'Ungrouped from row
405 Also
411 Also
406− :: Selection db params grp from right
412+ :: Selection commons schemas params grp from right
407− -> Selection db params grp from left
413+ -> Selection commons schemas params grp from left
408− -> Selection db params grp from (Join left right)
414+ -> Selection commons schemas params grp from (Join left right)
409instance (KnownSymbol col, row ~ '[col ::: ty])
415instance (KnownSymbol col, row ~ '[col ::: ty])
410 => Aliasable col
416 => Aliasable col
411− (Expression db params grp from ty)
417+ (Expression commons schemas params grp from ty)
412− (Selection db params grp from row) where
418+ (Selection commons schemas params grp from row) where
413 expr `as` col = List (expr `as` col)
419 expr `as` col = List (expr `as` col)
414instance (Has tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
420instance (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
416 tab ! col = tab ! col `as` col
422 tab ! col = tab ! col `as` col
417instance
423instance
418 ( Has tab from row0
424 ( Has tab from row0
419 , Has col row0 ty
425 , Has col row0 ty
420 , row1 ~ '[col ::: ty]
426 , row1 ~ '[col ::: ty]
421 , GroupedBy tab col bys )
427 , 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
423 tab ! col = tab ! col `as` col
429 tab ! col = tab ! col `as` col
424instance (HasUnique tab from row0, Has col row0 ty, row1 ~ '[col ::: ty])
430instance (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
426 fromLabel = fromLabel @col `as` Alias
432 fromLabel = fromLabel @col `as` Alias
427instance
433instance
428 ( HasUnique tab from row0
434 ( HasUnique tab from row0
429 , Has col row0 ty
435 , Has col row0 ty
430 , row1 ~ '[col ::: ty]
436 , row1 ~ '[col ::: ty]
431 , GroupedBy tab col bys )
437 , 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
433 fromLabel = fromLabel @col `as` Alias
439 fromLabel = fromLabel @col `as` Alias
434
440
435−instance RenderSQL (Selection db params grp from row) where
441+instance RenderSQL (Selection commons schemas params grp from row) where
436 renderSQL = \case
442 renderSQL = \case
437 List list -> renderCommaSeparated (renderAliased renderSQL) list
443 List list -> renderCommaSeparated (renderAliased renderSQL) list
438 Star -> "*"
444 Star -> "*"
@@ -446,11 +452,11 @@ instance RenderSQL (Selection db params grp from row) where
446-- the intermediate table are actually output.
452-- the intermediate table are actually output.
447select
453select
448 :: (SListI row, row ~ (x ': xs))
454 :: (SListI row, row ~ (x ': xs))
449− => Selection db params grp from row
455+ => Selection commons schemas params grp from row
450 -- ^ select list
456 -- ^ select list
451− -> TableExpression db params grp from
457+ -> TableExpression commons schemas params grp from
452 -- ^ intermediate virtual table
458 -- ^ intermediate virtual table
453− -> Query db params row
459+ -> Query commons schemas params row
454select selection tabexpr = UnsafeQuery $
460select selection tabexpr = UnsafeQuery $
455 "SELECT"
461 "SELECT"
456 <+> renderSQL selection
462 <+> renderSQL selection
@@ -458,20 +464,20 @@ select selection tabexpr = UnsafeQuery $
458
464
459select_
465select_
460 :: (SListI row, row ~ (x ': xs))
466 :: (SListI row, row ~ (x ': xs))
461− => NP (Aliased (Expression db params grp from)) row
467+ => NP (Aliased (Expression commons schemas params grp from)) row
462− -> TableExpression db params grp from
468+ -> TableExpression commons schemas params grp from
463− -> Query db params row
469+ -> Query commons schemas params row
464select_ list = select (List list)
470select_ list = select (List list)
465
471
466-- | After the select list has been processed, the result table can
472-- | After the select list has been processed, the result table can
467-- be subject to the elimination of duplicate rows using `selectDistinct`.
473-- be subject to the elimination of duplicate rows using `selectDistinct`.
468selectDistinct
474selectDistinct
469 :: (SListI columns, columns ~ (col ': cols))
475 :: (SListI columns, columns ~ (col ': cols))
470− => Selection db params 'Ungrouped from columns
476+ => Selection commons schemas params 'Ungrouped from columns
471 -- ^ select list
477 -- ^ select list
472− -> TableExpression db params 'Ungrouped from
478+ -> TableExpression commons schemas params 'Ungrouped from
473 -- ^ intermediate virtual table
479 -- ^ intermediate virtual table
474− -> Query db params columns
480+ -> Query commons schemas params columns
475selectDistinct selection tabexpr = UnsafeQuery $
481selectDistinct selection tabexpr = UnsafeQuery $
476 "SELECT DISTINCT"
482 "SELECT DISTINCT"
477 <+> renderSQL selection
483 <+> renderSQL selection
@@ -479,11 +485,11 @@ selectDistinct selection tabexpr = UnsafeQuery $
479
485
480selectDistinct_
486selectDistinct_
481 :: (SListI columns, columns ~ (col ': cols))
487 :: (SListI columns, columns ~ (col ': cols))
482− => NP (Aliased (Expression db params 'Ungrouped from)) columns
488+ => NP (Aliased (Expression commons schemas params 'Ungrouped from)) columns
483 -- ^ select list
489 -- ^ select list
484− -> TableExpression db params 'Ungrouped from
490+ -> TableExpression commons schemas params 'Ungrouped from
485 -- ^ intermediate virtual table
491 -- ^ intermediate virtual table
486− -> Query db params columns
492+ -> Query commons schemas params columns
487selectDistinct_ list = select (List list)
493selectDistinct_ list = select (List list)
488
494
489-- | `values` computes a row value or set of row values
495-- | `values` computes a row value or set of row values
@@ -492,16 +498,16 @@ selectDistinct_ list = select (List list)
492-- but it can be used on its own.
498-- but it can be used on its own.
493--
499--
494-- >>> type Row = '["a" ::: 'NotNull 'PGint4, "b" ::: 'NotNull 'PGtext]
500-- >>> 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
496-- >>> printSQL query
502-- >>> printSQL query
497-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
503-- SELECT * FROM (VALUES (1, E'one')) AS t ("a", "b")
498values
504values
499 :: SListI cols
505 :: SListI cols
500− => NP (Aliased (Expression db params 'Ungrouped '[] )) cols
506+ => NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols
501− -> [NP (Aliased (Expression db params 'Ungrouped '[] )) cols]
507+ -> [NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols]
502 -- ^ When more than one row is specified, all the rows must
508 -- ^ When more than one row is specified, all the rows must
503 -- must have the same number of elements
509 -- must have the same number of elements
504− -> Query db params cols
510+ -> Query commons schemas params cols
505values rw rws = UnsafeQuery $ "SELECT * FROM"
511values rw rws = UnsafeQuery $ "SELECT * FROM"
506 <+> parenthesized (
512 <+> parenthesized (
507 "VALUES"
513 "VALUES"
@@ -512,7 +518,7 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
512 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
518 <+> parenthesized (renderCommaSeparated renderAliasPart rw)
513 where
519 where
514 renderAliasPart, renderValuePart
520 renderAliasPart, renderValuePart
515− :: Aliased (Expression db params 'Ungrouped '[] ) ty -> ByteString
521+ :: Aliased (Expression commons schemas params 'Ungrouped '[] ) ty -> ByteString
516 renderAliasPart (_ `As` name) = renderSQL name
522 renderAliasPart (_ `As` name) = renderSQL name
517 renderValuePart (value `As` _) = renderSQL value
523 renderValuePart (value `As` _) = renderSQL value
518
524
@@ -520,9 +526,9 @@ values rw rws = UnsafeQuery $ "SELECT * FROM"
520-- specified by value expressions.
526-- specified by value expressions.
521values_
527values_
522 :: SListI cols
528 :: SListI cols
523− => NP (Aliased (Expression db params 'Ungrouped '[] )) cols
529+ => NP (Aliased (Expression commons schemas params 'Ungrouped '[] )) cols
524 -- ^ one row of values
530 -- ^ one row of values
525− -> Query db params cols
531+ -> Query commons schemas params cols
526values_ rw = values rw []
532values_ rw = values rw []
527
533
528{-----------------------------------------
534{-----------------------------------------
@@ -536,15 +542,16 @@ Table Expressions
536-- to a table on disk, a so-called base table, but more complex expressions
542-- to a table on disk, a so-called base table, but more complex expressions
537-- can be used to modify or combine base tables in various ways.
543-- can be used to modify or combine base tables in various ways.
538data TableExpression
544data TableExpression
539− (db :: DBType)
545+ (commons :: FromType)
546+ (schemas :: SchemasType)
540 (params :: [NullityType])
547 (params :: [NullityType])
541 (grp :: Grouping)
548 (grp :: Grouping)
542 (from :: FromType)
549 (from :: FromType)
543 = TableExpression
550 = TableExpression
544− { fromClause :: FromClause db params from
551+ { fromClause :: FromClause commons schemas params from
545 -- ^ A table reference that can be a table name, or a derived table such
552 -- ^ A table reference that can be a table name, or a derived table such
546 -- as a subquery, a @JOIN@ construct, or complex combinations of these.
553 -- 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]
548 -- ^ optional search coditions, combined with `.&&`. After the processing
555 -- ^ optional search coditions, combined with `.&&`. After the processing
549 -- of the `fromClause` is done, each row of the derived virtual table
556 -- of the `fromClause` is done, each row of the derived virtual table
550 -- is checked against the search condition. If the result of the
557 -- is checked against the search condition. If the result of the
@@ -560,13 +567,13 @@ data TableExpression
560 -- set of rows having common values into one group row that represents all
567 -- set of rows having common values into one group row that represents all
561 -- rows in the group. This is done to eliminate redundancy in the output
568 -- rows in the group. This is done to eliminate redundancy in the output
562 -- and/or compute aggregates that apply to these groups.
569 -- and/or compute aggregates that apply to these groups.
563− , havingClause :: HavingClause db params grp from
570+ , havingClause :: HavingClause commons schemas params grp from
564 -- ^ If a table has been grouped using `groupBy`, but only certain groups
571 -- ^ If a table has been grouped using `groupBy`, but only certain groups
565 -- are of interest, the `havingClause` can be used, much like a
572 -- are of interest, the `havingClause` can be used, much like a
566 -- `whereClause`, to eliminate groups from the result. Expressions in the
573 -- `whereClause`, to eliminate groups from the result. Expressions in the
567 -- `havingClause` can refer both to grouped expressions and to ungrouped
574 -- `havingClause` can refer both to grouped expressions and to ungrouped
568 -- expressions (which necessarily involve an aggregate function).
575 -- expressions (which necessarily involve an aggregate function).
569− , orderByClause :: [SortExpression db params grp from]
576+ , orderByClause :: [SortExpression commons schemas params grp from]
570 -- ^ The `orderByClause` is for optional sorting. When more than one
577 -- ^ The `orderByClause` is for optional sorting. When more than one
571 -- `SortExpression` is specified, the later (right) values are used to sort
578 -- `SortExpression` is specified, the later (right) values are used to sort
572 -- rows that are equal according to the earlier (left) values.
579 -- rows that are equal according to the earlier (left) values.
@@ -583,7 +590,7 @@ data TableExpression
583 }
590 }
584
591
585-- | Render a `TableExpression`
592-- | Render a `TableExpression`
586−instance RenderSQL (TableExpression db params grp from) where
593+instance RenderSQL (TableExpression commons schemas params grp from) where
587 renderSQL
594 renderSQL
588 (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
595 (TableExpression frm' whs' grps' hvs' srts' lims' offs') = mconcat
589 [ "FROM ", renderSQL frm'
596 [ "FROM ", renderSQL frm'
@@ -616,16 +623,16 @@ instance RenderSQL (TableExpression db params grp from) where
616-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
623-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
617-- to match the left-to-right sequencing of their placement in SQL.
624-- to match the left-to-right sequencing of their placement in SQL.
618from
625from
619− :: FromClause db params from -- ^ table reference
626+ :: FromClause commons schemas params from -- ^ table reference
620− -> TableExpression db params 'Ungrouped from
627+ -> TableExpression commons schemas params 'Ungrouped from
621from rels = TableExpression rels [] NoGroups NoHaving [] [] []
628from rels = TableExpression rels [] NoGroups NoHaving [] [] []
622
629
623-- | A `where_` is an endomorphism of `TableExpression`s which adds a
630-- | A `where_` is an endomorphism of `TableExpression`s which adds a
624-- search condition to the `whereClause`.
631-- search condition to the `whereClause`.
625where_
632where_
626− :: Condition db params 'Ungrouped from -- ^ filtering condition
633+ :: Condition commons schemas params 'Ungrouped from -- ^ filtering condition
627− -> TableExpression db params grp from
634+ -> TableExpression commons schemas params grp from
628− -> TableExpression db params grp from
635+ -> TableExpression commons schemas params grp from
629where_ wh rels = rels {whereClause = wh : whereClause rels}
636where_ wh rels = rels {whereClause = wh : whereClause rels}
630
637
631-- | A `groupBy` is a transformation of `TableExpression`s which switches
638-- | A `groupBy` is a transformation of `TableExpression`s which switches
@@ -634,8 +641,8 @@ where_ wh rels = rels {whereClause = wh : whereClause rels}
634groupBy
641groupBy
635 :: SListI bys
642 :: SListI bys
636 => NP (By from) bys -- ^ grouped columns
643 => NP (By from) bys -- ^ grouped columns
637− -> TableExpression db params 'Ungrouped from
644+ -> TableExpression commons schemas params 'Ungrouped from
638− -> TableExpression db params ('Grouped bys) from
645+ -> TableExpression commons schemas params ('Grouped bys) from
639groupBy bys rels = TableExpression
646groupBy bys rels = TableExpression
640 { fromClause = fromClause rels
647 { fromClause = fromClause rels
641 , whereClause = whereClause rels
648 , whereClause = whereClause rels
@@ -649,34 +656,34 @@ groupBy bys rels = TableExpression
649-- | A `having` is an endomorphism of `TableExpression`s which adds a
656-- | A `having` is an endomorphism of `TableExpression`s which adds a
650-- search condition to the `havingClause`.
657-- search condition to the `havingClause`.
651having
658having
652− :: Condition db params ('Grouped bys) from -- ^ having condition
659+ :: Condition commons schemas params ('Grouped bys) from -- ^ having condition
653− -> TableExpression db params ('Grouped bys) from
660+ -> TableExpression commons schemas params ('Grouped bys) from
654− -> TableExpression db params ('Grouped bys) from
661+ -> TableExpression commons schemas params ('Grouped bys) from
655having hv rels = rels
662having hv rels = rels
656 { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
663 { havingClause = case havingClause rels of Having hvs -> Having (hv:hvs) }
657
664
658-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
665-- | An `orderBy` is an endomorphism of `TableExpression`s which appends an
659-- ordering to the right of the `orderByClause`.
666-- ordering to the right of the `orderByClause`.
660orderBy
667orderBy
661− :: [SortExpression db params grp from] -- ^ sort expressions
668+ :: [SortExpression commons schemas params grp from] -- ^ sort expressions
662− -> TableExpression db params grp from
669+ -> TableExpression commons schemas params grp from
663− -> TableExpression db params grp from
670+ -> TableExpression commons schemas params grp from
664orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
671orderBy srts rels = rels {orderByClause = orderByClause rels ++ srts}
665
672
666-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
673-- | A `limit` is an endomorphism of `TableExpression`s which adds to the
667-- `limitClause`.
674-- `limitClause`.
668limit
675limit
669 :: Word64 -- ^ limit parameter
676 :: Word64 -- ^ limit parameter
670− -> TableExpression db params grp from
677+ -> TableExpression commons schemas params grp from
671− -> TableExpression db params grp from
678+ -> TableExpression commons schemas params grp from
672limit lim rels = rels {limitClause = lim : limitClause rels}
679limit lim rels = rels {limitClause = lim : limitClause rels}
673
680
674-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
681-- | An `offset` is an endomorphism of `TableExpression`s which adds to the
675-- `offsetClause`.
682-- `offsetClause`.
676offset
683offset
677 :: Word64 -- ^ offset parameter
684 :: Word64 -- ^ offset parameter
678− -> TableExpression db params grp from
685+ -> TableExpression commons schemas params grp from
679− -> TableExpression db params grp from
686+ -> TableExpression commons schemas params grp from
680offset off rels = rels {offsetClause = off : offsetClause rels}
687offset off rels = rels {offsetClause = off : offsetClause rels}
681
688
682{-----------------------------------------
689{-----------------------------------------
@@ -685,56 +692,56 @@ JSON stuff
685
692
686unsafeSetOfFunction
693unsafeSetOfFunction
687 :: ByteString
694 :: ByteString
688− -> Expression db params 'Ungrouped '[] ty
695+ -> Expression commons schemas params 'Ungrouped '[] ty
689− -> Query db params row
696+ -> Query commons schemas params row
690unsafeSetOfFunction fun expr = UnsafeQuery $
697unsafeSetOfFunction fun expr = UnsafeQuery $
691 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
698 "SELECT * FROM " <> fun <> "(" <> renderSQL expr <> ")"
692
699
693-- | Expands the outermost JSON object into a set of key/value pairs.
700-- | Expands the outermost JSON object into a set of key/value pairs.
694jsonEach
701jsonEach
695− :: Expression db params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
702+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
696− -> Query db params
703+ -> Query commons schemas params
697 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
704 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjson]
698jsonEach = unsafeSetOfFunction "json_each"
705jsonEach = unsafeSetOfFunction "json_each"
699
706
700-- | Expands the outermost binary JSON object into a set of key/value pairs.
707-- | Expands the outermost binary JSON object into a set of key/value pairs.
701jsonbEach
708jsonbEach
702− :: Expression db params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
709+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
703− -> Query db params
710+ -> Query commons schemas params
704 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
711 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGjsonb]
705jsonbEach = unsafeSetOfFunction "jsonb_each"
712jsonbEach = unsafeSetOfFunction "jsonb_each"
706
713
707-- | Expands the outermost JSON object into a set of key/value pairs.
714-- | Expands the outermost JSON object into a set of key/value pairs.
708jsonEachAsText
715jsonEachAsText
709− :: Expression db params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
716+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
710− -> Query db params
717+ -> Query commons schemas params
711 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
718 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
712jsonEachAsText = unsafeSetOfFunction "json_each_text"
719jsonEachAsText = unsafeSetOfFunction "json_each_text"
713
720
714-- | Expands the outermost binary JSON object into a set of key/value pairs.
721-- | Expands the outermost binary JSON object into a set of key/value pairs.
715jsonbEachAsText
722jsonbEachAsText
716− :: Expression db params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
723+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
717− -> Query db params
724+ -> Query commons schemas params
718 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
725 '["key" ::: 'NotNull 'PGtext, "value" ::: 'NotNull 'PGtext]
719jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
726jsonbEachAsText = unsafeSetOfFunction "jsonb_each_text"
720
727
721-- | Returns set of keys in the outermost JSON object.
728-- | Returns set of keys in the outermost JSON object.
722jsonObjectKeys
729jsonObjectKeys
723− :: Expression db params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
730+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
724− -> Query db params '["json_object_keys" ::: 'NotNull 'PGtext]
731+ -> Query commons schemas params '["json_object_keys" ::: 'NotNull 'PGtext]
725jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
732jsonObjectKeys = unsafeSetOfFunction "json_object_keys"
726
733
727-- | Returns set of keys in the outermost JSON object.
734-- | Returns set of keys in the outermost JSON object.
728jsonbObjectKeys
735jsonbObjectKeys
729− :: Expression db params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
736+ :: Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
730− -> Query db params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
737+ -> Query commons schemas params '["jsonb_object_keys" ::: 'NotNull 'PGtext]
731jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
738jsonbObjectKeys = unsafeSetOfFunction "jsonb_object_keys"
732
739
733unsafePopulateFunction
740unsafePopulateFunction
734 :: ByteString
741 :: ByteString
735 -> TypeExpression schemas (nullity ('PGcomposite row))
742 -> TypeExpression schemas (nullity ('PGcomposite row))
736− -> Expression (commons :=> schemas) params 'Ungrouped '[] ty
743+ -> Expression commons schemas params 'Ungrouped '[] ty
737− -> Query (commons :=> schemas) params row
744+ -> Query commons schemas params row
738unsafePopulateFunction fun ty expr = UnsafeQuery $
745unsafePopulateFunction fun ty expr = UnsafeQuery $
739 "SELECT * FROM " <> fun <> "("
746 "SELECT * FROM " <> fun <> "("
740 <> "null::" <> renderSQL ty <> ", "
747 <> "null::" <> renderSQL ty <> ", "
@@ -744,24 +751,24 @@ unsafePopulateFunction fun ty expr = UnsafeQuery $
744-- type defined by the given table.
751-- type defined by the given table.
745jsonPopulateRecord
752jsonPopulateRecord
746 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
753 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
747− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
754+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
748− -> Query (commons :=> schemas) params row
755+ -> Query commons schemas params row
749jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
756jsonPopulateRecord = unsafePopulateFunction "json_populate_record"
750
757
751-- | Expands the binary JSON expression to a row whose columns match the record
758-- | Expands the binary JSON expression to a row whose columns match the record
752-- type defined by the given table.
759-- type defined by the given table.
753jsonbPopulateRecord
760jsonbPopulateRecord
754 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
761 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
755− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
762+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
756− -> Query (commons :=> schemas) params row
763+ -> Query commons schemas params row
757jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
764jsonbPopulateRecord = unsafePopulateFunction "jsonb_populate_record"
758
765
759-- | Expands the outermost array of objects in the given JSON expression to a
766-- | Expands the outermost array of objects in the given JSON expression to a
760-- set of rows whose columns match the record type defined by the given table.
767-- set of rows whose columns match the record type defined by the given table.
761jsonPopulateRecordSet
768jsonPopulateRecordSet
762 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
769 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
763− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
770+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
764− -> Query (commons :=> schemas) params row
771+ -> Query commons schemas params row
765jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
772jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
766
773
767-- | Expands the outermost array of objects in the given binary JSON expression
774-- | Expands the outermost array of objects in the given binary JSON expression
@@ -769,55 +776,55 @@ jsonPopulateRecordSet = unsafePopulateFunction "json_populate_record_set"
769-- table.
776-- table.
770jsonbPopulateRecordSet
777jsonbPopulateRecordSet
771 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
778 :: TypeExpression schemas (nullity ('PGcomposite row)) -- ^ row type
772− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
779+ -> Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
773− -> Query (commons :=> schemas) params row
780+ -> Query commons schemas params row
774jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
781jsonbPopulateRecordSet = unsafePopulateFunction "jsonb_populate_record_set"
775
782
776unsafeRecordFunction
783unsafeRecordFunction
777 :: (SListI record, json `In` PGJsonType)
784 :: (SListI record, json `In` PGJsonType)
778 => ByteString
785 => ByteString
779− -> Expression (commons :=> schemas) params 'Ungrouped '[] (nullity json)
786+ -> Expression commons schemas params 'Ungrouped '[] (nullity json)
780 -> NP (Aliased (TypeExpression schemas)) record
787 -> NP (Aliased (TypeExpression schemas)) record
781− -> Query (commons :=> schemas) params record
788+ -> Query commons schemas params record
782unsafeRecordFunction fun expr types = UnsafeQuery $
789unsafeRecordFunction fun expr types = UnsafeQuery $
783 "SELECT * FROM " <> fun <> "("
790 "SELECT * FROM " <> fun <> "("
784 <> renderSQL expr <> ")"
791 <> renderSQL expr <> ")"
785 <+> "AS" <+> "x" <> parenthesized (renderCommaSeparated renderTy types)
792 <+> "AS" <+> "x" <> parenthesized (renderCommaSeparated renderTy types)
786 where
793 where
787− renderTy :: Aliased (TypeExpression db) ty -> ByteString
794+ renderTy :: Aliased (TypeExpression schemas) ty -> ByteString
788 renderTy (ty `As` alias) =
795 renderTy (ty `As` alias) =
789 renderSQL alias <+> renderSQL ty
796 renderSQL alias <+> renderSQL ty
790
797
791-- | Builds an arbitrary record from a JSON object.
798-- | Builds an arbitrary record from a JSON object.
792jsonToRecord
799jsonToRecord
793 :: SListI record
800 :: SListI record
794− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
801+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json object
795 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
802 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
796− -> Query (commons :=> schemas) params record
803+ -> Query commons schemas params record
797jsonToRecord = unsafeRecordFunction "json_to_record"
804jsonToRecord = unsafeRecordFunction "json_to_record"
798
805
799-- | Builds an arbitrary record from a binary JSON object.
806-- | Builds an arbitrary record from a binary JSON object.
800jsonbToRecord
807jsonbToRecord
801 :: SListI record
808 :: SListI record
802− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
809+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb object
803 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
810 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
804− -> Query (commons :=> schemas) params record
811+ -> Query commons schemas params record
805jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
812jsonbToRecord = unsafeRecordFunction "jsonb_to_record"
806
813
807-- | Builds an arbitrary set of records from a JSON array of objects.
814-- | Builds an arbitrary set of records from a JSON array of objects.
808jsonToRecordSet
815jsonToRecordSet
809 :: SListI record
816 :: SListI record
810− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
817+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjson) -- ^ json array
811 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
818 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
812− -> Query (commons :=> schemas) params record
819+ -> Query commons schemas params record
813jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
820jsonToRecordSet = unsafeRecordFunction "json_to_record_set"
814
821
815-- | Builds an arbitrary set of records from a binary JSON array of objects.
822-- | Builds an arbitrary set of records from a binary JSON array of objects.
816jsonbToRecordSet
823jsonbToRecordSet
817 :: SListI record
824 :: SListI record
818− => Expression (commons :=> schemas) params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
825+ => Expression commons schemas params 'Ungrouped '[] (nullity 'PGjsonb) -- ^ jsonb array
819 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
826 -> NP (Aliased (TypeExpression schemas)) record -- ^ record types
820− -> Query (commons :=> schemas) params record
827+ -> Query commons schemas params record
821jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
828jsonbToRecordSet = unsafeRecordFunction "jsonb_to_record_set"
822
829
823{-----------------------------------------
830{-----------------------------------------
@@ -828,38 +835,38 @@ FROM clauses
828A `FromClause` can be a table name, or a derived table such
835A `FromClause` can be a table name, or a derived table such
829as a subquery, a @JOIN@ construct, or complex combinations of these.
836as a subquery, a @JOIN@ construct, or complex combinations of these.
830-}
837-}
831−newtype FromClause db params from
838+newtype FromClause commons schemas params from
832 = UnsafeFromClause { renderFromClause :: ByteString }
839 = UnsafeFromClause { renderFromClause :: ByteString }
833 deriving (GHC.Generic,Show,Eq,Ord,NFData)
840 deriving (GHC.Generic,Show,Eq,Ord,NFData)
834−instance RenderSQL (FromClause db params from) where
841+instance RenderSQL (FromClause commons schemas params from) where
835 renderSQL = renderFromClause
842 renderSQL = renderFromClause
836
843
837-- | A real `table` is a table from the database.
844-- | A real `table` is a table from the database.
838table
845table
839 :: (Has sch schemas schema, Has tab schema ('Table table))
846 :: (Has sch schemas schema, Has tab schema ('Table table))
840 => Aliased (QualifiedAlias sch) (alias ::: tab)
847 => Aliased (QualifiedAlias sch) (alias ::: tab)
841− -> FromClause (commons :=> schemas) params '[alias ::: TableToRow table]
848+ -> FromClause commons schemas params '[alias ::: TableToRow table]
842table (tab `As` alias) = UnsafeFromClause $
849table (tab `As` alias) = UnsafeFromClause $
843 renderSQL tab <+> "AS" <+> renderSQL alias
850 renderSQL tab <+> "AS" <+> renderSQL alias
844
851
845-- | `subquery` derives a table from a `Query`.
852-- | `subquery` derives a table from a `Query`.
846subquery
853subquery
847− :: Aliased (Query db params) query
854+ :: Aliased (Query commons schemas params) query
848− -> FromClause db params '[query]
855+ -> FromClause commons schemas params '[query]
849subquery = UnsafeFromClause . renderAliased (parenthesized . renderQuery)
856subquery = UnsafeFromClause . renderAliased (parenthesized . renderQuery)
850
857
851-- | `view` derives a table from a `View`.
858-- | `view` derives a table from a `View`.
852view
859view
853 :: (Has sch schemas schema, Has vw schema ('View view))
860 :: (Has sch schemas schema, Has vw schema ('View view))
854 => Aliased (QualifiedAlias sch) (alias ::: vw)
861 => Aliased (QualifiedAlias sch) (alias ::: vw)
855− -> FromClause (commons :=> schemas) params '[alias ::: view]
862+ -> FromClause commons schemas params '[alias ::: view]
856view (vw `As` alias) = UnsafeFromClause $
863view (vw `As` alias) = UnsafeFromClause $
857 renderSQL vw <+> "AS" <+> renderSQL alias
864 renderSQL vw <+> "AS" <+> renderSQL alias
858
865
859common
866common
860 :: Has cte commons common
867 :: Has cte commons common
861 => Aliased Alias (alias ::: cte)
868 => Aliased Alias (alias ::: cte)
862− -> FromClause (commons :=> schemas) params '[alias ::: common]
869+ -> FromClause commons schemas params '[alias ::: common]
863common (cte `As` alias) = UnsafeFromClause $
870common (cte `As` alias) = UnsafeFromClause $
864 renderSQL cte <+> "AS" <+> renderSQL alias
871 renderSQL cte <+> "AS" <+> renderSQL alias
865
872
@@ -870,11 +877,11 @@ common (cte `As` alias) = UnsafeFromClause $
870 have @n * m@ rows.
877 have @n * m@ rows.
871-}
878-}
872crossJoin
879crossJoin
873− :: FromClause db params right
880+ :: FromClause commons schemas params right
874 -- ^ right
881 -- ^ right
875− -> FromClause db params left
882+ -> FromClause commons schemas params left
876 -- ^ left
883 -- ^ left
877− -> FromClause db params (Join left right)
884+ -> FromClause commons schemas params (Join left right)
878crossJoin right left = UnsafeFromClause $
885crossJoin right left = UnsafeFromClause $
879 renderSQL left <+> "CROSS JOIN" <+> renderSQL right
886 renderSQL left <+> "CROSS JOIN" <+> renderSQL right
880
887
@@ -882,13 +889,13 @@ crossJoin right left = UnsafeFromClause $
882the @on@ condition.
889the @on@ condition.
883-}
890-}
884innerJoin
891innerJoin
885− :: FromClause db params right
892+ :: FromClause commons schemas params right
886 -- ^ right
893 -- ^ right
887− -> Condition db params 'Ungrouped (Join left right)
894+ -> Condition commons schemas params 'Ungrouped (Join left right)
888 -- ^ @on@ condition
895 -- ^ @on@ condition
889− -> FromClause db params left
896+ -> FromClause commons schemas params left
890 -- ^ left
897 -- ^ left
891− -> FromClause db params (Join left right)
898+ -> FromClause commons schemas params (Join left right)
892innerJoin right on left = UnsafeFromClause $
899innerJoin right on left = UnsafeFromClause $
893 renderSQL left <+> "INNER JOIN" <+> renderSQL right
900 renderSQL left <+> "INNER JOIN" <+> renderSQL right
894 <+> "ON" <+> renderSQL on
901 <+> "ON" <+> renderSQL on
@@ -899,13 +906,13 @@ innerJoin right on left = UnsafeFromClause $
899 Thus, the joined table always has at least one row for each row in @left@.
906 Thus, the joined table always has at least one row for each row in @left@.
900-}
907-}
901leftOuterJoin
908leftOuterJoin
902− :: FromClause db params right
909+ :: FromClause commons schemas params right
903 -- ^ right
910 -- ^ right
904− -> Condition db params 'Ungrouped (Join left right)
911+ -> Condition commons schemas params 'Ungrouped (Join left right)
905 -- ^ @on@ condition
912 -- ^ @on@ condition
906− -> FromClause db params left
913+ -> FromClause commons schemas params left
907 -- ^ left
914 -- ^ left
908− -> FromClause db params (Join left (NullifyFrom right))
915+ -> FromClause commons schemas params (Join left (NullifyFrom right))
909leftOuterJoin right on left = UnsafeFromClause $
916leftOuterJoin right on left = UnsafeFromClause $
910 renderSQL left <+> "LEFT OUTER JOIN" <+> renderSQL right
917 renderSQL left <+> "LEFT OUTER JOIN" <+> renderSQL right
911 <+> "ON" <+> renderSQL on
918 <+> "ON" <+> renderSQL on
@@ -917,13 +924,13 @@ leftOuterJoin right on left = UnsafeFromClause $
917 have a row for each row in @right@.
924 have a row for each row in @right@.
918-}
925-}
919rightOuterJoin
926rightOuterJoin
920− :: FromClause db params right
927+ :: FromClause commons schemas params right
921 -- ^ right
928 -- ^ right
922− -> Condition db params 'Ungrouped (Join left right)
929+ -> Condition commons schemas params 'Ungrouped (Join left right)
923 -- ^ @on@ condition
930 -- ^ @on@ condition
924− -> FromClause db params left
931+ -> FromClause commons schemas params left
925 -- ^ left
932 -- ^ left
926− -> FromClause db params (Join (NullifyFrom left) right)
933+ -> FromClause commons schemas params (Join (NullifyFrom left) right)
927rightOuterJoin right on left = UnsafeFromClause $
934rightOuterJoin right on left = UnsafeFromClause $
928 renderSQL left <+> "RIGHT OUTER JOIN" <+> renderSQL right
935 renderSQL left <+> "RIGHT OUTER JOIN" <+> renderSQL right
929 <+> "ON" <+> renderSQL on
936 <+> "ON" <+> renderSQL on
@@ -936,13 +943,13 @@ rightOuterJoin right on left = UnsafeFromClause $
936 is added.
943 is added.
937-}
944-}
938fullOuterJoin
945fullOuterJoin
939− :: FromClause db params right
946+ :: FromClause commons schemas params right
940 -- ^ right
947 -- ^ right
941− -> Condition db params 'Ungrouped (Join left right)
948+ -> Condition commons schemas params 'Ungrouped (Join left right)
942 -- ^ @on@ condition
949 -- ^ @on@ condition
943− -> FromClause db params left
950+ -> FromClause commons schemas params left
944 -- ^ left
951 -- ^ left
945− -> FromClause db params
952+ -> FromClause commons schemas params
946 (Join (NullifyFrom left) (NullifyFrom right))
953 (Join (NullifyFrom left) (NullifyFrom right))
947fullOuterJoin right on left = UnsafeFromClause $
954fullOuterJoin right on left = UnsafeFromClause $
948 renderSQL left <+> "FULL OUTER JOIN" <+> renderSQL right
955 renderSQL left <+> "FULL OUTER JOIN" <+> renderSQL right
@@ -1011,17 +1018,17 @@ instance RenderSQL (GroupByClause grp from) where
1011-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
1018-- An `Ungrouped` `TableExpression` may only use `NoHaving` while a `Grouped`
1012-- `TableExpression` must use `Having` whose conditions are combined with
1019-- `TableExpression` must use `Having` whose conditions are combined with
1013-- `.&&`.
1020-- `.&&`.
1014−data HavingClause db params grp from where
1021+data HavingClause commons schemas params grp from where
1015− NoHaving :: HavingClause db params 'Ungrouped from
1022+ NoHaving :: HavingClause commons schemas params 'Ungrouped from
1016 Having
1023 Having
1017− :: [Condition db params ('Grouped bys) from]
1024+ :: [Condition commons schemas params ('Grouped bys) from]
1018− -> HavingClause db params ('Grouped bys) from
1025+ -> HavingClause commons schemas params ('Grouped bys) from
1019−deriving instance Show (HavingClause db params grp from)
1026+deriving instance Show (HavingClause commons schemas params grp from)
1020−deriving instance Eq (HavingClause db params grp from)
1027+deriving instance Eq (HavingClause commons schemas params grp from)
1021−deriving instance Ord (HavingClause db params grp from)
1028+deriving instance Ord (HavingClause commons schemas params grp from)
1022
1029
1023-- | Render a `HavingClause`.
1030-- | Render a `HavingClause`.
1024−instance RenderSQL (HavingClause db params grp from) where
1031+instance RenderSQL (HavingClause commons schemas params grp from) where
1025 renderSQL = \case
1032 renderSQL = \case
1026 NoHaving -> ""
1033 NoHaving -> ""
1027 Having [] -> ""
1034 Having [] -> ""
@@ -1040,29 +1047,29 @@ Sorting
1040-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
1047-- `AscNullsLast`, `DescNullsFirst` and `DescNullsLast` options are used to
1041-- determine whether nulls appear before or after non-null values in the sort
1048-- determine whether nulls appear before or after non-null values in the sort
1042-- ordering of a `Null` result column.
1049-- ordering of a `Null` result column.
1043−data SortExpression db params grp from where
1050+data SortExpression commons schemas params grp from where
1044 Asc
1051 Asc
1045− :: Expression db params grp from ('NotNull ty)
1052+ :: Expression commons schemas params grp from ('NotNull ty)
1046− -> SortExpression db params grp from
1053+ -> SortExpression commons schemas params grp from
1047 Desc
1054 Desc
1048− :: Expression db params grp from ('NotNull ty)
1055+ :: Expression commons schemas params grp from ('NotNull ty)
1049− -> SortExpression db params grp from
1056+ -> SortExpression commons schemas params grp from
1050 AscNullsFirst
1057 AscNullsFirst
1051− :: Expression db params grp from ('Null ty)
1058+ :: Expression commons schemas params grp from ('Null ty)
1052− -> SortExpression db params grp from
1059+ -> SortExpression commons schemas params grp from
1053 AscNullsLast
1060 AscNullsLast
1054− :: Expression db params grp from ('Null ty)
1061+ :: Expression commons schemas params grp from ('Null ty)
1055− -> SortExpression db params grp from
1062+ -> SortExpression commons schemas params grp from
1056 DescNullsFirst
1063 DescNullsFirst
1057− :: Expression db params grp from ('Null ty)
1064+ :: Expression commons schemas params grp from ('Null ty)
1058− -> SortExpression db params grp from
1065+ -> SortExpression commons schemas params grp from
1059 DescNullsLast
1066 DescNullsLast
1060− :: Expression db params grp from ('Null ty)
1067+ :: Expression commons schemas params grp from ('Null ty)
1061− -> SortExpression db params grp from
1068+ -> SortExpression commons schemas params grp from
1062−deriving instance Show (SortExpression db params grp from)
1069+deriving instance Show (SortExpression commons schemas params grp from)
1063
1070
1064-- | Render a `SortExpression`.
1071-- | Render a `SortExpression`.
1065−instance RenderSQL (SortExpression db params grp from) where
1072+instance RenderSQL (SortExpression commons schemas params grp from) where
1066 renderSQL = \case
1073 renderSQL = \case
1067 Asc expression -> renderSQL expression <+> "ASC"
1074 Asc expression -> renderSQL expression <+> "ASC"
1068 Desc expression -> renderSQL expression <+> "DESC"
1075 Desc expression -> renderSQL expression <+> "DESC"
@@ -1075,18 +1082,18 @@ instance RenderSQL (SortExpression db params grp from) where
1075
1082
1076unsafeSubqueryExpression
1083unsafeSubqueryExpression
1077 :: ByteString
1084 :: ByteString
1078− -> Expression db params grp from ty
1085+ -> Expression commons schemas params grp from ty
1079− -> Query db params '[alias ::: ty]
1086+ -> Query commons schemas params '[alias ::: ty]
1080− -> Expression db params grp from (nullity 'PGbool)
1087+ -> Expression commons schemas params grp from (nullity 'PGbool)
1081unsafeSubqueryExpression op x q = UnsafeExpression $
1088unsafeSubqueryExpression op x q = UnsafeExpression $
1082 renderSQL x <+> op <+> parenthesized (renderSQL q)
1089 renderSQL x <+> op <+> parenthesized (renderSQL q)
1083
1090
1084unsafeRowSubqueryExpression
1091unsafeRowSubqueryExpression
1085 :: SListI row
1092 :: SListI row
1086 => ByteString
1093 => ByteString
1087− -> NP (Aliased (Expression db params grp from)) row
1094+ -> NP (Aliased (Expression commons schemas params grp from)) row
1088− -> Query db params row
1095+ -> Query commons schemas params row
1089− -> Expression db params grp from (nullity 'PGbool)
1096+ -> Expression commons schemas params grp from (nullity 'PGbool)
1090unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1097unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1091 renderSQL (row xs) <+> op <+> parenthesized (renderSQL q)
1098 renderSQL (row xs) <+> op <+> parenthesized (renderSQL q)
1092
1099
@@ -1099,9 +1106,9 @@ unsafeRowSubqueryExpression op xs q = UnsafeExpression $
1099-- >>> printSQL $ true `in_` values_ (true `as` #foo)
1106-- >>> printSQL $ true `in_` values_ (true `as` #foo)
1100-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1107-- TRUE IN (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1101in_
1108in_
1102− :: Expression db params grp from ty -- ^ expression
1109+ :: Expression commons schemas params grp from ty -- ^ expression
1103− -> Query db params '[alias ::: ty] -- ^ subquery
1110+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1104− -> Expression db params grp from (nullity 'PGbool)
1111+ -> Expression commons schemas params grp from (nullity 'PGbool)
1105in_ = unsafeSubqueryExpression "IN"
1112in_ = unsafeSubqueryExpression "IN"
1106
1113
1107{- | The left-hand side of this form of `rowIn` is a row constructor.
1114{- | 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.
1114The result is `false` if no equal row is found
1121The result is `false` if no equal row is found
1115(including the case where the subquery returns no rows).
1122(including the case where the subquery returns no rows).
1116
1123
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]
1118>>> printSQL $ myRow `rowIn` values_ myRow
1125>>> printSQL $ myRow `rowIn` values_ myRow
1119ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1126ROW(1, FALSE) IN (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1120-}
1127-}
1121rowIn
1128rowIn
1122 :: SListI row
1129 :: SListI row
1123− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1130+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1124− -> Query db params row -- ^ subquery
1131+ -> Query commons schemas params row -- ^ subquery
1125− -> Expression db params grp from (nullity 'PGbool)
1132+ -> Expression commons schemas params grp from (nullity 'PGbool)
1126rowIn = unsafeRowSubqueryExpression "IN"
1133rowIn = unsafeRowSubqueryExpression "IN"
1127
1134
1128-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
1135-- | >>> printSQL $ true `eqAll` values_ (true `as` #foo)
1129-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1136-- TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1130eqAll
1137eqAll
1131− :: Expression db params grp from ty -- ^ expression
1138+ :: Expression commons schemas params grp from ty -- ^ expression
1132− -> Query db params '[alias ::: ty] -- ^ subquery
1139+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1133− -> Expression db params grp from (nullity 'PGbool)
1140+ -> Expression commons schemas params grp from (nullity 'PGbool)
1134eqAll = unsafeSubqueryExpression "= ALL"
1141eqAll = unsafeSubqueryExpression "= ALL"
1135
1142
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]
1137-- >>> printSQL $ myRow `rowEqAll` values_ myRow
1144-- >>> printSQL $ myRow `rowEqAll` values_ myRow
1138-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1145-- ROW(1, FALSE) = ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1139rowEqAll
1146rowEqAll
1140 :: SListI row
1147 :: SListI row
1141− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1148+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1142− -> Query db params row -- ^ subquery
1149+ -> Query commons schemas params row -- ^ subquery
1143− -> Expression db params grp from (nullity 'PGbool)
1150+ -> Expression commons schemas params grp from (nullity 'PGbool)
1144rowEqAll = unsafeRowSubqueryExpression "= ALL"
1151rowEqAll = unsafeRowSubqueryExpression "= ALL"
1145
1152
1146-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
1153-- | >>> printSQL $ true `eqAny` values_ (true `as` #foo)
1147-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1154-- TRUE = ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1148eqAny
1155eqAny
1149− :: Expression db params grp from ty -- ^ expression
1156+ :: Expression commons schemas params grp from ty -- ^ expression
1150− -> Query db params '[alias ::: ty] -- ^ subquery
1157+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1151− -> Expression db params grp from (nullity 'PGbool)
1158+ -> Expression commons schemas params grp from (nullity 'PGbool)
1152eqAny = unsafeSubqueryExpression "= ANY"
1159eqAny = unsafeSubqueryExpression "= ANY"
1153
1160
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]
1155-- >>> printSQL $ myRow `rowEqAny` values_ myRow
1162-- >>> printSQL $ myRow `rowEqAny` values_ myRow
1156-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1163-- ROW(1, FALSE) = ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1157rowEqAny
1164rowEqAny
1158 :: SListI row
1165 :: SListI row
1159− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1166+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1160− -> Query db params row -- ^ subquery
1167+ -> Query commons schemas params row -- ^ subquery
1161− -> Expression db params grp from (nullity 'PGbool)
1168+ -> Expression commons schemas params grp from (nullity 'PGbool)
1162rowEqAny = unsafeRowSubqueryExpression "= ANY"
1169rowEqAny = unsafeRowSubqueryExpression "= ANY"
1163
1170
1164-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
1171-- | >>> printSQL $ true `neqAll` values_ (true `as` #foo)
1165-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1172-- TRUE <> ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1166neqAll
1173neqAll
1167− :: Expression db params grp from ty -- ^ expression
1174+ :: Expression commons schemas params grp from ty -- ^ expression
1168− -> Query db params '[alias ::: ty] -- ^ subquery
1175+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1169− -> Expression db params grp from (nullity 'PGbool)
1176+ -> Expression commons schemas params grp from (nullity 'PGbool)
1170neqAll = unsafeSubqueryExpression "<> ALL"
1177neqAll = unsafeSubqueryExpression "<> ALL"
1171
1178
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]
1173-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
1180-- >>> printSQL $ myRow `rowNeqAll` values_ myRow
1174-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1181-- ROW(1, FALSE) <> ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1175rowNeqAll
1182rowNeqAll
1176 :: SListI row
1183 :: SListI row
1177− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1184+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1178− -> Query db params row -- ^ subquery
1185+ -> Query commons schemas params row -- ^ subquery
1179− -> Expression db params grp from (nullity 'PGbool)
1186+ -> Expression commons schemas params grp from (nullity 'PGbool)
1180rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1187rowNeqAll = unsafeRowSubqueryExpression "<> ALL"
1181
1188
1182-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
1189-- | >>> printSQL $ true `neqAny` values_ (true `as` #foo)
1183-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1190-- TRUE <> ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1184neqAny
1191neqAny
1185− :: Expression db params grp from ty -- ^ expression
1192+ :: Expression commons schemas params grp from ty -- ^ expression
1186− -> Query db params '[alias ::: ty] -- ^ subquery
1193+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1187− -> Expression db params grp from (nullity 'PGbool)
1194+ -> Expression commons schemas params grp from (nullity 'PGbool)
1188neqAny = unsafeSubqueryExpression "<> ANY"
1195neqAny = unsafeSubqueryExpression "<> ANY"
1189
1196
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]
1191-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
1198-- >>> printSQL $ myRow `rowNeqAny` values_ myRow
1192-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1199-- ROW(1, FALSE) <> ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1193rowNeqAny
1200rowNeqAny
1194 :: SListI row
1201 :: SListI row
1195− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1202+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1196− -> Query db params row -- ^ subquery
1203+ -> Query commons schemas params row -- ^ subquery
1197− -> Expression db params grp from (nullity 'PGbool)
1204+ -> Expression commons schemas params grp from (nullity 'PGbool)
1198rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1205rowNeqAny = unsafeRowSubqueryExpression "<> ANY"
1199
1206
1200-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
1207-- | >>> printSQL $ true `allLt` values_ (true `as` #foo)
1201-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1208-- TRUE ALL < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1202allLt
1209allLt
1203− :: Expression db params grp from ty -- ^ expression
1210+ :: Expression commons schemas params grp from ty -- ^ expression
1204− -> Query db params '[alias ::: ty] -- ^ subquery
1211+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1205− -> Expression db params grp from (nullity 'PGbool)
1212+ -> Expression commons schemas params grp from (nullity 'PGbool)
1206allLt = unsafeSubqueryExpression "ALL <"
1213allLt = unsafeSubqueryExpression "ALL <"
1207
1214
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]
1209-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1216-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1210-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1217-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1211rowLtAll
1218rowLtAll
1212 :: SListI row
1219 :: SListI row
1213− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1220+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1214− -> Query db params row -- ^ subquery
1221+ -> Query commons schemas params row -- ^ subquery
1215− -> Expression db params grp from (nullity 'PGbool)
1222+ -> Expression commons schemas params grp from (nullity 'PGbool)
1216rowLtAll = unsafeRowSubqueryExpression "ALL <"
1223rowLtAll = unsafeRowSubqueryExpression "ALL <"
1217
1224
1218-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
1225-- | >>> printSQL $ true `ltAny` values_ (true `as` #foo)
1219-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1226-- TRUE ANY < (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1220ltAny
1227ltAny
1221− :: Expression db params grp from ty -- ^ expression
1228+ :: Expression commons schemas params grp from ty -- ^ expression
1222− -> Query db params '[alias ::: ty] -- ^ subquery
1229+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1223− -> Expression db params grp from (nullity 'PGbool)
1230+ -> Expression commons schemas params grp from (nullity 'PGbool)
1224ltAny = unsafeSubqueryExpression "ANY <"
1231ltAny = unsafeSubqueryExpression "ANY <"
1225
1232
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]
1227-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1234-- >>> printSQL $ myRow `rowLtAll` values_ myRow
1228-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1235-- ROW(1, FALSE) ALL < (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1229rowLtAny
1236rowLtAny
1230 :: SListI row
1237 :: SListI row
1231− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1238+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1232− -> Query db params row -- ^ subquery
1239+ -> Query commons schemas params row -- ^ subquery
1233− -> Expression db params grp from (nullity 'PGbool)
1240+ -> Expression commons schemas params grp from (nullity 'PGbool)
1234rowLtAny = unsafeRowSubqueryExpression "ANY <"
1241rowLtAny = unsafeRowSubqueryExpression "ANY <"
1235
1242
1236-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
1243-- | >>> printSQL $ true `lteAll` values_ (true `as` #foo)
1237-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1244-- TRUE <= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1238lteAll
1245lteAll
1239− :: Expression db params grp from ty -- ^ expression
1246+ :: Expression commons schemas params grp from ty -- ^ expression
1240− -> Query db params '[alias ::: ty] -- ^ subquery
1247+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1241− -> Expression db params grp from (nullity 'PGbool)
1248+ -> Expression commons schemas params grp from (nullity 'PGbool)
1242lteAll = unsafeSubqueryExpression "<= ALL"
1249lteAll = unsafeSubqueryExpression "<= ALL"
1243
1250
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]
1245-- >>> printSQL $ myRow `rowLteAll` values_ myRow
1252-- >>> printSQL $ myRow `rowLteAll` values_ myRow
1246-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1253-- ROW(1, FALSE) <= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1247rowLteAll
1254rowLteAll
1248 :: SListI row
1255 :: SListI row
1249− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1256+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1250− -> Query db params row -- ^ subquery
1257+ -> Query commons schemas params row -- ^ subquery
1251− -> Expression db params grp from (nullity 'PGbool)
1258+ -> Expression commons schemas params grp from (nullity 'PGbool)
1252rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1259rowLteAll = unsafeRowSubqueryExpression "<= ALL"
1253
1260
1254-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
1261-- | >>> printSQL $ true `lteAny` values_ (true `as` #foo)
1255-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1262-- TRUE <= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1256lteAny
1263lteAny
1257− :: Expression db params grp from ty -- ^ expression
1264+ :: Expression commons schemas params grp from ty -- ^ expression
1258− -> Query db params '[alias ::: ty] -- ^ subquery
1265+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1259− -> Expression db params grp from (nullity 'PGbool)
1266+ -> Expression commons schemas params grp from (nullity 'PGbool)
1260lteAny = unsafeSubqueryExpression "<= ANY"
1267lteAny = unsafeSubqueryExpression "<= ANY"
1261
1268
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]
1263-- >>> printSQL $ myRow `rowLteAny` values_ myRow
1270-- >>> printSQL $ myRow `rowLteAny` values_ myRow
1264-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1271-- ROW(1, FALSE) <= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1265rowLteAny
1272rowLteAny
1266 :: SListI row
1273 :: SListI row
1267− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1274+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1268− -> Query db params row -- ^ subquery
1275+ -> Query commons schemas params row -- ^ subquery
1269− -> Expression db params grp from (nullity 'PGbool)
1276+ -> Expression commons schemas params grp from (nullity 'PGbool)
1270rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1277rowLteAny = unsafeRowSubqueryExpression "<= ANY"
1271
1278
1272-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
1279-- | >>> printSQL $ true `gtAll` values_ (true `as` #foo)
1273-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1280-- TRUE > ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1274gtAll
1281gtAll
1275− :: Expression db params grp from ty -- ^ expression
1282+ :: Expression commons schemas params grp from ty -- ^ expression
1276− -> Query db params '[alias ::: ty] -- ^ subquery
1283+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1277− -> Expression db params grp from (nullity 'PGbool)
1284+ -> Expression commons schemas params grp from (nullity 'PGbool)
1278gtAll = unsafeSubqueryExpression "> ALL"
1285gtAll = unsafeSubqueryExpression "> ALL"
1279
1286
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]
1281-- >>> printSQL $ myRow `rowGtAll` values_ myRow
1288-- >>> printSQL $ myRow `rowGtAll` values_ myRow
1282-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1289-- ROW(1, FALSE) > ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1283rowGtAll
1290rowGtAll
1284 :: SListI row
1291 :: SListI row
1285− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1292+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1286− -> Query db params row -- ^ subquery
1293+ -> Query commons schemas params row -- ^ subquery
1287− -> Expression db params grp from (nullity 'PGbool)
1294+ -> Expression commons schemas params grp from (nullity 'PGbool)
1288rowGtAll = unsafeRowSubqueryExpression "> ALL"
1295rowGtAll = unsafeRowSubqueryExpression "> ALL"
1289
1296
1290-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
1297-- | >>> printSQL $ true `gtAny` values_ (true `as` #foo)
1291-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1298-- TRUE > ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1292gtAny
1299gtAny
1293− :: Expression db params grp from ty -- ^ expression
1300+ :: Expression commons schemas params grp from ty -- ^ expression
1294− -> Query db params '[alias ::: ty] -- ^ subquery
1301+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1295− -> Expression db params grp from (nullity 'PGbool)
1302+ -> Expression commons schemas params grp from (nullity 'PGbool)
1296gtAny = unsafeSubqueryExpression "> ANY"
1303gtAny = unsafeSubqueryExpression "> ANY"
1297
1304
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]
1299-- >>> printSQL $ myRow `rowGtAny` values_ myRow
1306-- >>> printSQL $ myRow `rowGtAny` values_ myRow
1300-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1307-- ROW(1, FALSE) > ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1301rowGtAny
1308rowGtAny
1302 :: SListI row
1309 :: SListI row
1303− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1310+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1304− -> Query db params row -- ^ subquery
1311+ -> Query commons schemas params row -- ^ subquery
1305− -> Expression db params grp from (nullity 'PGbool)
1312+ -> Expression commons schemas params grp from (nullity 'PGbool)
1306rowGtAny = unsafeRowSubqueryExpression "> ANY"
1313rowGtAny = unsafeRowSubqueryExpression "> ANY"
1307
1314
1308-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
1315-- | >>> printSQL $ true `gteAll` values_ (true `as` #foo)
1309-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1316-- TRUE >= ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1310gteAll
1317gteAll
1311− :: Expression db params grp from ty -- ^ expression
1318+ :: Expression commons schemas params grp from ty -- ^ expression
1312− -> Query db params '[alias ::: ty] -- ^ subquery
1319+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1313− -> Expression db params grp from (nullity 'PGbool)
1320+ -> Expression commons schemas params grp from (nullity 'PGbool)
1314gteAll = unsafeSubqueryExpression ">= ALL"
1321gteAll = unsafeSubqueryExpression ">= ALL"
1315
1322
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]
1317-- >>> printSQL $ myRow `rowGteAll` values_ myRow
1324-- >>> printSQL $ myRow `rowGteAll` values_ myRow
1318-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1325-- ROW(1, FALSE) >= ALL (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1319rowGteAll
1326rowGteAll
1320 :: SListI row
1327 :: SListI row
1321− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1328+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1322− -> Query db params row -- ^ subquery
1329+ -> Query commons schemas params row -- ^ subquery
1323− -> Expression db params grp from (nullity 'PGbool)
1330+ -> Expression commons schemas params grp from (nullity 'PGbool)
1324rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1331rowGteAll = unsafeRowSubqueryExpression ">= ALL"
1325
1332
1326-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
1333-- | >>> printSQL $ true `gteAny` values_ (true `as` #foo)
1327-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1334-- TRUE >= ANY (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1328gteAny
1335gteAny
1329− :: Expression db params grp from ty -- ^ expression
1336+ :: Expression commons schemas params grp from ty -- ^ expression
1330− -> Query db params '[alias ::: ty] -- ^ subquery
1337+ -> Query commons schemas params '[alias ::: ty] -- ^ subquery
1331− -> Expression db params grp from (nullity 'PGbool)
1338+ -> Expression commons schemas params grp from (nullity 'PGbool)
1332gteAny = unsafeSubqueryExpression ">= ANY"
1339gteAny = unsafeSubqueryExpression ">= ANY"
1333
1340
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]
1335-- >>> printSQL $ myRow `rowGteAny` values_ myRow
1342-- >>> printSQL $ myRow `rowGteAny` values_ myRow
1336-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1343-- ROW(1, FALSE) >= ANY (SELECT * FROM (VALUES (1, FALSE)) AS t ("foo", "bar"))
1337rowGteAny
1344rowGteAny
1338 :: SListI row
1345 :: SListI row
1339− => NP (Aliased (Expression db params grp from)) row -- ^ row constructor
1346+ => NP (Aliased (Expression commons schemas params grp from)) row -- ^ row constructor
1340− -> Query db params row -- ^ subquery
1347+ -> Query commons schemas params row -- ^ subquery
1341− -> Expression db params grp from (nullity 'PGbool)
1348+ -> Expression commons schemas params grp from (nullity 'PGbool)
1342rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1349rowGteAny = unsafeRowSubqueryExpression ">= ANY"
1343
1350
1344-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
1351-- | A `CommonTableExpression` is an auxiliary statement in a `with` clause.
1345data CommonTableExpression statement
1352data CommonTableExpression statement
1353+ (schemas :: SchemasType)
1346 (params :: [NullityType])
1354 (params :: [NullityType])
1347− (db0 :: DBType)
1355+ (commons0 :: FromType)
1348− (db1 :: DBType) where
1356+ (commons1 :: FromType) where
1349 CommonTableExpression
1357 CommonTableExpression
1350− :: Aliased (statement (commons :=> schemas) params) (cte ::: common)
1358+ :: Aliased (statement commons schemas params) (cte ::: common)
1351− -> CommonTableExpression statement params
1359+ -> CommonTableExpression statement schemas params commons (cte ::: common ': commons)
1352− (commons :=> schemas) ((cte ::: common ': commons) :=> schemas)
1353instance
1360instance
1354 ( KnownSymbol cte
1361 ( KnownSymbol cte
1355− , db0 ~ (commons :=> schemas)
1356− , db1 ~ ((cte ::: common ': commons) :=> schemas)
1362+ , commons1 ~ (cte ::: common ': commons)
1357 ) => Aliasable cte
1363 ) => Aliasable cte
1358− (statement db0 params common)
1364+ (statement commons schemas params common)
1359− (CommonTableExpression statement params db0 db1) where
1365+ (CommonTableExpression statement schemas params commons commons1) where
1360 statement `as` cte = CommonTableExpression (statement `as` cte)
1366 statement `as` cte = CommonTableExpression (statement `as` cte)
1361instance
1367instance
1362 ( KnownSymbol cte
1368 ( KnownSymbol cte
1363− , db0 ~ (commons :=> schemas)
1364− , db1 ~ ((cte ::: common ': commons) :=> schemas)
1369+ , commons1 ~ (cte ::: common ': commons)
1365 ) => Aliasable cte
1370 ) => Aliasable cte
1366− (statement db0 params common)
1371+ (statement commons schemas params common)
1367− (AlignedList (CommonTableExpression statement params) db0 db1) where
1372+ (AlignedList (CommonTableExpression statement schemas params) commons commons1) where
1368 statement `as` cte = single (statement `as` cte)
1373 statement `as` cte = single (statement `as` cte)
1369
1374
1370-- | render a `CommonTableExpression`.
1375-- | render a `CommonTableExpression`.
1371renderCommonTableExpression
1376renderCommonTableExpression
1372− :: (forall db ps row. statement db ps row -> ByteString) -- ^ render statement
1377+ :: (forall cs ss ps row. statement cs ss ps row -> ByteString) -- ^ render statement
1373− -> CommonTableExpression statement params db0 db1 -> ByteString
1378+ -> CommonTableExpression statement schemas params commons0 commons1 -> ByteString
1374renderCommonTableExpression renderStatement
1379renderCommonTableExpression renderStatement
1375 (CommonTableExpression (statement `As` alias)) =
1380 (CommonTableExpression (statement `As` alias)) =
1376 renderSQL alias <+> "AS" <+> parenthesized (renderStatement statement)
1381 renderSQL alias <+> "AS" <+> parenthesized (renderStatement statement)
1377
1382
1378-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
1383-- | render a non-empty `AlignedList` of `CommonTableExpression`s.
1379renderCommonTableExpressions
1384renderCommonTableExpressions
1380− :: (forall db ps row. statement db ps row -> ByteString) -- ^ render statement
1385+ :: (forall cs ss ps row. statement cs ss ps row -> ByteString) -- ^ render statement
1381− -> CommonTableExpression statement params db0 db1
1386+ -> CommonTableExpression statement schemas params commons0 commons1
1382− -> AlignedList (CommonTableExpression statement params) db1 db2
1387+ -> AlignedList (CommonTableExpression statement schemas params) commons1 commons2
1383 -> ByteString
1388 -> ByteString
1384renderCommonTableExpressions renderStatement cte ctes =
1389renderCommonTableExpressions renderStatement cte ctes =
1385 renderCommonTableExpression renderStatement cte <> case ctes of
1390 renderCommonTableExpression renderStatement cte <> case ctes of
@@ -1392,11 +1397,11 @@ renderCommonTableExpressions renderStatement cte ctes =
1392-- defining temporary tables that exist just for one query.
1397-- defining temporary tables that exist just for one query.
1393class With statement where
1398class With statement where
1394 with
1399 with
1395− :: AlignedList (CommonTableExpression statement params) db0 db1
1400+ :: AlignedList (CommonTableExpression statement schemas params) commons0 commons1
1396 -- ^ common table expressions
1401 -- ^ common table expressions
1397− -> statement db1 params row
1402+ -> statement commons1 schemas params row
1398 -- ^ larger query
1403 -- ^ larger query
1399− -> statement db0 params row
1404+ -> statement commons0 schemas params row
1400instance With Query where
1405instance With Query where
1401 with Done query = query
1406 with Done query = query
1402 with (cte :>> ctes) query = UnsafeQuery $
1407 with (cte :>> ctes) query = UnsafeQuery $
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs−6
@@ -56,8 +56,6 @@ module Squeal.PostgreSQL.Schema
56 , SchemaType
56 , SchemaType
57 , SchemasType
57 , SchemasType
58 , Public
58 , Public
59− , DBType
60− , DBof
61 -- * Constraints
59 -- * Constraints
62 , (:=>)
60 , (:=>)
63 , ColumnConstraint (..)
61 , ColumnConstraint (..)
@@ -702,10 +700,6 @@ type SchemasType = [(Symbol,SchemaType)]
702type family Public (schema :: SchemaType) :: SchemasType
700type family Public (schema :: SchemaType) :: SchemasType
703 where Public schema = '["public" ::: schema]
701 where Public schema = '["public" ::: schema]
704
702
705−type DBType = (FromType,SchemasType)
706−
707−type family DBof :: SchemasType -> DBType where DBof = '(,) '[]
708−
709-- | `IsPGlabel` looks very much like the `IsLabel` class. Whereas
703-- | `IsPGlabel` looks very much like the `IsLabel` class. Whereas
710-- the overloaded label, `fromLabel` is used for column references,
704-- the overloaded label, `fromLabel` is used for column references,
711-- `label`s are used for enum terms. A `label` is called with
705-- `label`s are used for enum terms. A `label` is called with
squeal-postgresql/test/Specs/ExceptionHandling.hs+1−3
@@ -48,8 +48,6 @@ type Schema =
48
48
49type Schemas = Public Schema
49type Schemas = Public Schema
50
50
51−type DB = DBof Schemas
52−
53data User =
51data User =
54 User { userName :: Text
52 User { userName :: Text
55 , userEmail :: Maybe Text
53 , userEmail :: Maybe Text
@@ -58,7 +56,7 @@ data User =
58instance SOP.Generic User
56instance SOP.Generic User
59instance SOP.HasDatatypeInfo User
57instance SOP.HasDatatypeInfo User
60
58
61−insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
59+insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
62 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
60 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
63insertUser = insertInto #users
61insertUser = insertInto #users
64 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))
62 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))