on dev help sign in
switch in new column constraints
31165deEitan Chatav
squeal-postgresql/exe/Example.hs+10−10
@@ -24,13 +24,13 @@ import qualified GHC.Generics as GHC
24
24
25type Schema =
25type Schema =
26 '[ "users" :::
26 '[ "users" :::
27− '[ "id" ::: 'Optional ('NotNull 'PGint4)
27+ '[ "id" ::: ('[ 'Default] :=> 'NotNull 'PGint4)
28− , "name" ::: 'Required ('NotNull 'PGtext)
28+ , "name" ::: ('[] :=> 'NotNull 'PGtext)
29 ]
29 ]
30 , "emails" :::
30 , "emails" :::
31− '[ "id" ::: 'Optional ('NotNull 'PGint4)
31+ '[ "id" ::: ('[ 'Default] :=> 'NotNull 'PGint4)
32− , "user_id" ::: 'Required ('NotNull 'PGint4)
32+ , "user_id" ::: ('[] :=> 'NotNull 'PGint4)
33− , "email" ::: 'Required ('Null 'PGtext)
33+ , "email" ::: ('[] :=> 'Null 'PGtext)
34 ]
34 ]
35 ]
35 ]
36
36
@@ -53,14 +53,14 @@ teardown :: Definition Schema '[]
53teardown = dropTable #emails >>> dropTable #users
53teardown = dropTable #emails >>> dropTable #users
54
54
55insertUser :: Manipulation Schema
55insertUser :: Manipulation Schema
56− '[ 'Required ('NotNull 'PGtext)]
56+ '[ '[] :=> 'NotNull 'PGtext]
57− '[ "fromOnly" ::: 'Required ('NotNull 'PGint4) ]
57+ '[ "fromOnly" ::: ('[] :=> 'NotNull 'PGint4) ]
58insertUser = insertInto #users
58insertUser = insertInto #users
59 ( Values (def `As` #id :* param @1 `As` #name :* Nil) [] )
59 ( Values (def `As` #id :* param @1 `As` #name :* Nil) [] )
60 OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
60 OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
61
61
62insertEmail :: Manipulation Schema
62insertEmail :: Manipulation Schema
63− '[ 'Required ('NotNull 'PGint4), 'Required ('Null 'PGtext)] '[]
63+ '[ '[] :=> 'NotNull 'PGint4, '[] :=> 'Null 'PGtext] '[]
64insertEmail = insertInto #emails ( Values
64insertEmail = insertInto #emails ( Values
65 ( def `As` #id :*
65 ( def `As` #id :*
66 param @1 `As` #user_id :*
66 param @1 `As` #user_id :*
@@ -68,8 +68,8 @@ insertEmail = insertInto #emails ( Values
68 OnConflictDoNothing (Returning Nil)
68 OnConflictDoNothing (Returning Nil)
69
69
70getUsers :: Query Schema '[]
70getUsers :: Query Schema '[]
71− '[ "userName" ::: 'Required ('NotNull 'PGtext)
71+ '[ "userName" ::: ('[] :=> 'NotNull 'PGtext)
72− , "userEmail" ::: 'Required ('Null 'PGtext) ]
72+ , "userEmail" ::: ('[] :=> 'Null 'PGtext) ]
73getUsers = select
73getUsers = select
74 (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* Nil)
74 (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* Nil)
75 ( from (Table (#users `As` #u)
75 ( from (Table (#users `As` #u)
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+5−5
@@ -118,13 +118,13 @@ instance ToParam Value 'PGjsonb where toParam = K . Encoding.jsonb_ast
118-- of a `Type` to a `ColumnType`, encoding `Maybe`s to `Null`s. You should
118-- of a `Type` to a `ColumnType`, encoding `Maybe`s to `Null`s. You should
119-- not define instances of `ToColumnParam`, just use the provided instances.
119-- not define instances of `ToColumnParam`, just use the provided instances.
120class ToColumnParam (x :: Type) (ty :: ColumnType) where
120class ToColumnParam (x :: Type) (ty :: ColumnType) where
121− -- | >>> toColumnParam @Int16 @('Required ('NotNull 'PGint2)) 0
121+ -- | >>> toColumnParam @Int16 @'( '[], ('NotNull 'PGint2)) 0
122 -- K (Just "\NUL\NUL")
122 -- K (Just "\NUL\NUL")
123 --
123 --
124− -- >>> toColumnParam @(Maybe Int16) @('Required ('Null 'PGint2)) (Just 0)
124+ -- >>> toColumnParam @(Maybe Int16) @'( '[], ('Null 'PGint2)) (Just 0)
125 -- K (Just "\NUL\NUL")
125 -- K (Just "\NUL\NUL")
126 --
126 --
127− -- >>> toColumnParam @(Maybe Int16) @('Required ('Null 'PGint2)) Nothing
127+ -- >>> toColumnParam @(Maybe Int16) @'( '[], ('Null 'PGint2)) Nothing
128 -- K Nothing
128 -- K Nothing
129 toColumnParam :: x -> K (Maybe Strict.ByteString) ty
129 toColumnParam :: x -> K (Maybe Strict.ByteString) ty
130instance ToParam x pg => ToColumnParam x (optionality ('NotNull pg)) where
130instance ToParam x pg => ToColumnParam x (optionality ('NotNull pg)) where
@@ -203,7 +203,7 @@ class FromColumnValue (colty :: (Symbol,ColumnType)) (y :: Type) where
203 -- Just (Id {getId = 1})
203 -- Just (Id {getId = 1})
204 fromColumnValue :: K (Maybe Strict.ByteString) colty -> y
204 fromColumnValue :: K (Maybe Strict.ByteString) colty -> y
205instance FromValue pg y
205instance FromValue pg y
206− => FromColumnValue (column ::: ('Required ('NotNull pg))) y where
206+ => FromColumnValue (column ::: '( '[], ('NotNull pg))) y where
207 fromColumnValue = \case
207 fromColumnValue = \case
208 K Nothing -> error "fromColumnValue: saw NULL when expecting NOT NULL"
208 K Nothing -> error "fromColumnValue: saw NULL when expecting NOT NULL"
209 K (Just bytes) ->
209 K (Just bytes) ->
@@ -214,7 +214,7 @@ instance FromValue pg y
214 in
214 in
215 either err id errOrValue
215 either err id errOrValue
216instance FromValue pg y
216instance FromValue pg y
217− => FromColumnValue (column ::: ('Required ('Null pg))) (Maybe y) where
217+ => FromColumnValue (column ::: '( '[], ('Null pg))) (Maybe y) where
218 fromColumnValue (K nullOrBytes)
218 fromColumnValue (K nullOrBytes)
219 = either err id
219 = either err id
220 . Decoding.valueParser (fromValue @pg @y Proxy)
220 . Decoding.valueParser (fromValue @pg @y Proxy)
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+9−8
@@ -63,6 +63,7 @@ import Control.Category
63import Control.DeepSeq
63import Control.DeepSeq
64import Data.ByteString
64import Data.ByteString
65import Data.Monoid
65import Data.Monoid
66+import Data.Type.Set
66import GHC.TypeLits
67import GHC.TypeLits
67import Prelude hiding ((.), id)
68import Prelude hiding ((.), id)
68
69
@@ -386,10 +387,10 @@ newtype AlterColumns
386-- :}
387-- :}
387-- "ALTER TABLE tab ADD COLUMN col2 text DEFAULT E'foo';"
388-- "ALTER TABLE tab ADD COLUMN col2 text DEFAULT E'foo';"
388addColumnDefault
389addColumnDefault
389− :: KnownSymbol column
390+ :: (KnownSymbol column, 'Default `In` constraints)
390 => Alias column -- ^ column to add
391 => Alias column -- ^ column to add
391− -> TypeExpression ('Optional ty) -- ^ type of the new column
392+ -> TypeExpression '(constraints, ty) -- ^ type of the new column
392− -> AlterColumns columns (Create column ('Optional ty) columns)
393+ -> AlterColumns columns (Create column '(constraints, ty) columns)
393addColumnDefault column ty = UnsafeAlterColumns $
394addColumnDefault column ty = UnsafeAlterColumns $
394 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
395 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
395
396
@@ -410,8 +411,8 @@ addColumnDefault column ty = UnsafeAlterColumns $
410addColumnNull
411addColumnNull
411 :: KnownSymbol column
412 :: KnownSymbol column
412 => Alias column -- ^ column to add
413 => Alias column -- ^ column to add
413− -> TypeExpression ('Required ('Null ty)) -- ^ type of the new column
414+ -> TypeExpression '( '[], ('Null ty)) -- ^ type of the new column
414− -> AlterColumns columns (Create column ('Required ('Null ty)) columns)
415+ -> AlterColumns columns (Create column '( '[], ('Null ty)) columns)
415addColumnNull column ty = UnsafeAlterColumns $
416addColumnNull column ty = UnsafeAlterColumns $
416 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
417 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
417
418
@@ -506,8 +507,8 @@ newtype AlterColumn (ty0 :: ColumnType) (ty1 :: ColumnType) =
506-- :}
507-- :}
507-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
508-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
508setDefault
509setDefault
509− :: Expression '[] 'Ungrouped '[] ('Required ty) -- ^ default value to set
510+ :: Expression '[] 'Ungrouped '[] '( constraints, ty) -- ^ default value to set
510− -> AlterColumn (optionality ty) ('Optional ty)
511+ -> AlterColumn (optionality ty) '( '[ 'Default] `Union` constraints, ty)
511setDefault expression = UnsafeAlterColumn $
512setDefault expression = UnsafeAlterColumn $
512 "SET DEFAULT" <+> renderExpression expression
513 "SET DEFAULT" <+> renderExpression expression
513
514
@@ -522,7 +523,7 @@ setDefault expression = UnsafeAlterColumn $
522-- in renderDefinition definition
523-- in renderDefinition definition
523-- :}
524-- :}
524-- "ALTER TABLE tab ALTER COLUMN col DROP DEFAULT;"
525-- "ALTER TABLE tab ALTER COLUMN col DROP DEFAULT;"
525−dropDefault :: AlterColumn (optionality ty) ('Required ty)
526+dropDefault :: AlterColumn '(constraints, ty) '(DropDefault constraints, ty)
526dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
527dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
527
528
528-- | A `setNotNull` adds a @NOT NULL@ constraint to a column.
529-- | A `setNotNull` adds a @NOT NULL@ constraint to a column.
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+166−163
@@ -196,13 +196,13 @@ supplied externally to a SQL statement.
196separately from the SQL command string, in which case `param`s are used to
196separately from the SQL command string, in which case `param`s are used to
197refer to the out-of-line data values.
197refer to the out-of-line data values.
198-}
198-}
199−class (PGTyped (BaseType ty), KnownNat n)
199+class (PGTyped (PGTypeOf ty), KnownNat n)
200 => HasParameter (n :: Nat) params ty | n params -> ty where
200 => HasParameter (n :: Nat) params ty | n params -> ty where
201 param :: Expression tables grouping params ty
201 param :: Expression tables grouping params ty
202 param = UnsafeExpression $ parenthesized $
202 param = UnsafeExpression $ parenthesized $
203 "$" <> renderNat (Proxy @n) <+> "::"
203 "$" <> renderNat (Proxy @n) <+> "::"
204− <+> renderTypeExpression (pgtype @(BaseType ty))
204+ <+> renderTypeExpression (pgtype @(PGTypeOf ty))
205−instance {-# OVERLAPPING #-} PGTyped (BaseType ty1)
205+instance {-# OVERLAPPING #-} PGTyped (PGTypeOf ty1)
206 => HasParameter 1 (ty1:tys) ty1
206 => HasParameter 1 (ty1:tys) ty1
207instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
207instance {-# OVERLAPPABLE #-} (KnownNat n, HasParameter (n-1) params ty)
208 => HasParameter n (ty' : params) ty
208 => HasParameter n (ty' : params) ty
@@ -221,7 +221,7 @@ class KnownSymbol column => HasColumn column columns ty
221 -> Expression tables 'Ungrouped params ty
221 -> Expression tables 'Ungrouped params ty
222 getColumn column = UnsafeExpression $ renderAlias column
222 getColumn column = UnsafeExpression $ renderAlias column
223instance {-# OVERLAPPING #-} KnownSymbol column
223instance {-# OVERLAPPING #-} KnownSymbol column
224− => HasColumn column ((column ::: optionality ty) ': tys) ('Required ty)
224+ => HasColumn column ((column ::: optionality ty) ': tys) '( '[], ty)
225instance {-# OVERLAPPABLE #-} (KnownSymbol column, HasColumn column table ty)
225instance {-# OVERLAPPABLE #-} (KnownSymbol column, HasColumn column table ty)
226 => HasColumn column (ty' ': table) ty
226 => HasColumn column (ty' ': table) ty
227
227
@@ -297,15 +297,18 @@ instance
297
297
298-- | >>> renderExpression def
298-- | >>> renderExpression def
299-- "DEFAULT"
299-- "DEFAULT"
300+def
301+ :: 'Default `In` constraints
300−def :: Expression '[] 'Ungrouped params ('Optional (nullity ty))
302+ => Expression '[] 'Ungrouped params '(constraints, (nullity ty))
301def = UnsafeExpression "DEFAULT"
303def = UnsafeExpression "DEFAULT"
302
304
303-- | >>> renderExpression $ unDef false
305-- | >>> renderExpression $ unDef false
304-- "FALSE"
306-- "FALSE"
305unDef
307unDef
308+ :: 'Default `In` constraints
306− :: Expression '[] 'Ungrouped params ('Required (nullity ty))
309+ => Expression '[] 'Ungrouped params '( '[], (nullity ty))
307 -- ^ not @DEFAULT@
310 -- ^ not @DEFAULT@
308− -> Expression '[] 'Ungrouped params ('Optional (nullity ty))
311+ -> Expression '[] 'Ungrouped params '(constraints, (nullity ty))
309unDef = UnsafeExpression . renderExpression
312unDef = UnsafeExpression . renderExpression
310
313
311-- | analagous to `Nothing`
314-- | analagous to `Nothing`
@@ -330,11 +333,11 @@ unNull = UnsafeExpression . renderExpression
330-- >>> renderExpression $ coalesce [null_, unNull true] false
333-- >>> renderExpression $ coalesce [null_, unNull true] false
331-- "COALESCE(NULL, TRUE, FALSE)"
334-- "COALESCE(NULL, TRUE, FALSE)"
332coalesce
335coalesce
333− :: [Expression tables grouping params ('Required ('Null ty))]
336+ :: [Expression tables grouping params '( '[], ('Null ty))]
334 -- ^ @NULL@s may be present
337 -- ^ @NULL@s may be present
335− -> Expression tables grouping params ('Required ('NotNull ty))
338+ -> Expression tables grouping params '( '[], ('NotNull ty))
336 -- ^ @NULL@ is absent
339 -- ^ @NULL@ is absent
337− -> Expression tables grouping params ('Required ('NotNull ty))
340+ -> Expression tables grouping params '( '[], ('NotNull ty))
338coalesce nullxs notNullx = UnsafeExpression $
341coalesce nullxs notNullx = UnsafeExpression $
339 "COALESCE" <> parenthesized (commaSeparated
342 "COALESCE" <> parenthesized (commaSeparated
340 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
343 ((renderExpression <$> nullxs) <> [renderExpression notNullx]))
@@ -344,16 +347,16 @@ coalesce nullxs notNullx = UnsafeExpression $
344-- >>> renderExpression $ fromNull true null_
347-- >>> renderExpression $ fromNull true null_
345-- "COALESCE(NULL, TRUE)"
348-- "COALESCE(NULL, TRUE)"
346fromNull
349fromNull
347− :: Expression tables grouping params ('Required ('NotNull ty))
350+ :: Expression tables grouping params '( '[], ('NotNull ty))
348 -- ^ what to convert @NULL@ to
351 -- ^ what to convert @NULL@ to
349− -> Expression tables grouping params ('Required ('Null ty))
352+ -> Expression tables grouping params '( '[], ('Null ty))
350− -> Expression tables grouping params ('Required ('NotNull ty))
353+ -> Expression tables grouping params '( '[], ('NotNull ty))
351fromNull notNullx nullx = coalesce [nullx] notNullx
354fromNull notNullx nullx = coalesce [nullx] notNullx
352
355
353-- | >>> renderExpression $ null_ & isNull
356-- | >>> renderExpression $ null_ & isNull
354-- "NULL IS NULL"
357-- "NULL IS NULL"
355isNull
358isNull
356− :: Expression tables grouping params ('Required ('Null ty))
359+ :: Expression tables grouping params '( '[], ('Null ty))
357 -- ^ possibly @NULL@
360 -- ^ possibly @NULL@
358 -> Condition tables grouping params
361 -> Condition tables grouping params
359isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
362isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
@@ -361,7 +364,7 @@ isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
361-- | >>> renderExpression $ null_ & isn'tNull
364-- | >>> renderExpression $ null_ & isn'tNull
362-- "NULL IS NOT NULL"
365-- "NULL IS NOT NULL"
363isn'tNull
366isn'tNull
364− :: Expression tables grouping params ('Required ('Null ty))
367+ :: Expression tables grouping params '( '[], ('Null ty))
365 -- ^ possibly @NULL@
368 -- ^ possibly @NULL@
366 -> Condition tables grouping params
369 -> Condition tables grouping params
367isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
370isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
@@ -371,13 +374,13 @@ isn'tNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
371-- >>> renderExpression $ matchNull true not_ null_
374-- >>> renderExpression $ matchNull true not_ null_
372-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
375-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
373matchNull
376matchNull
374− :: Expression tables grouping params ('Required nullty)
377+ :: Expression tables grouping params '( '[], nullty)
375 -- ^ what to convert @NULL@ to
378 -- ^ what to convert @NULL@ to
376− -> ( Expression tables grouping params ('Required ('NotNull ty))
379+ -> ( Expression tables grouping params '( '[], ('NotNull ty))
377− -> Expression tables grouping params ('Required nullty) )
380+ -> Expression tables grouping params '( '[], nullty) )
378 -- ^ function to perform when @NULL@ is absent
381 -- ^ function to perform when @NULL@ is absent
379− -> Expression tables grouping params ('Required ('Null ty))
382+ -> Expression tables grouping params '( '[], ('Null ty))
380− -> Expression tables grouping params ('Required nullty)
383+ -> Expression tables grouping params '( '[], nullty)
381matchNull y f x = ifThenElse (isNull x) y
384matchNull y f x = ifThenElse (isNull x) y
382 (f (UnsafeExpression (renderExpression x)))
385 (f (UnsafeExpression (renderExpression x)))
383
386
@@ -388,33 +391,33 @@ matchNull y f x = ifThenElse (isNull x) y
388-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
391-- >>> renderExpression @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
389-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
392-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
390nullIf
393nullIf
391− :: Expression tables grouping params ('Required ('NotNull ty))
394+ :: Expression tables grouping params '( '[], ('NotNull ty))
392 -- ^ @NULL@ is absent
395 -- ^ @NULL@ is absent
393− -> Expression tables grouping params ('Required ('NotNull ty))
396+ -> Expression tables grouping params '( '[], ('NotNull ty))
394 -- ^ @NULL@ is absent
397 -- ^ @NULL@ is absent
395− -> Expression tables grouping params ('Required ('Null ty))
398+ -> Expression tables grouping params '( '[], ('Null ty))
396nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
399nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
397 (renderExpression x <> ", " <> renderExpression y)
400 (renderExpression x <> ", " <> renderExpression y)
398
401
399-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
402-- | >>> renderExpression @_ @_ @'[_] $ greatest currentTimestamp [param @1]
400-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
403-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
401greatest
404greatest
402− :: Expression tables grouping params ('Required nullty)
405+ :: Expression tables grouping params '( '[], nullty)
403 -- ^ needs at least 1 argument
406 -- ^ needs at least 1 argument
404− -> [Expression tables grouping params ('Required nullty)]
407+ -> [Expression tables grouping params '( '[], nullty)]
405 -- ^ or more
408 -- ^ or more
406− -> Expression tables grouping params ('Required nullty)
409+ -> Expression tables grouping params '( '[], nullty)
407greatest x xs = UnsafeExpression $ "GREATEST("
410greatest x xs = UnsafeExpression $ "GREATEST("
408 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
411 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
409
412
410-- | >>> renderExpression $ least currentTimestamp [null_]
413-- | >>> renderExpression $ least currentTimestamp [null_]
411-- "LEAST(CURRENT_TIMESTAMP, NULL)"
414-- "LEAST(CURRENT_TIMESTAMP, NULL)"
412least
415least
413− :: Expression tables grouping params ('Required nullty)
416+ :: Expression tables grouping params '( '[], nullty)
414 -- ^ needs at least 1 argument
417 -- ^ needs at least 1 argument
415− -> [Expression tables grouping params ('Required nullty)]
418+ -> [Expression tables grouping params '( '[], nullty)]
416 -- ^ or more
419 -- ^ or more
417− -> Expression tables grouping params ('Required nullty)
420+ -> Expression tables grouping params '( '[], nullty)
418least x xs = UnsafeExpression $ "LEAST("
421least x xs = UnsafeExpression $ "LEAST("
419 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
422 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
420
423
@@ -423,9 +426,9 @@ least x xs = UnsafeExpression $ "LEAST("
423unsafeBinaryOp
426unsafeBinaryOp
424 :: ByteString
427 :: ByteString
425 -- ^ operator
428 -- ^ operator
426− -> Expression tables grouping params ('Required ty0)
429+ -> Expression tables grouping params '( '[], ty0)
427− -> Expression tables grouping params ('Required ty1)
430+ -> Expression tables grouping params '( '[], ty1)
428− -> Expression tables grouping params ('Required ty2)
431+ -> Expression tables grouping params '( '[], ty2)
429unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
432unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
430 renderExpression x <+> op <+> renderExpression y
433 renderExpression x <+> op <+> renderExpression y
431
434
@@ -434,8 +437,8 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
434unsafeUnaryOp
437unsafeUnaryOp
435 :: ByteString
438 :: ByteString
436 -- ^ operator
439 -- ^ operator
437− -> Expression tables grouping params ('Required ty0)
440+ -> Expression tables grouping params '( '[], ty0)
438− -> Expression tables grouping params ('Required ty1)
441+ -> Expression tables grouping params '( '[], ty1)
439unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
442unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
440 op <+> renderExpression x
443 op <+> renderExpression x
441
444
@@ -444,13 +447,13 @@ unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
444unsafeFunction
447unsafeFunction
445 :: ByteString
448 :: ByteString
446 -- ^ function
449 -- ^ function
447− -> Expression tables grouping params ('Required xty)
450+ -> Expression tables grouping params '( '[], xty)
448− -> Expression tables grouping params ('Required yty)
451+ -> Expression tables grouping params '( '[], yty)
449unsafeFunction fun x = UnsafeExpression $
452unsafeFunction fun x = UnsafeExpression $
450 fun <> parenthesized (renderExpression x)
453 fun <> parenthesized (renderExpression x)
451
454
452instance PGNum ty
455instance PGNum ty
453− => Num (Expression tables grouping params ('Required (nullity ty))) where
456+ => Num (Expression tables grouping params '( '[], (nullity ty))) where
454 (+) = unsafeBinaryOp "+"
457 (+) = unsafeBinaryOp "+"
455 (-) = unsafeBinaryOp "-"
458 (-) = unsafeBinaryOp "-"
456 (*) = unsafeBinaryOp "*"
459 (*) = unsafeBinaryOp "*"
@@ -462,12 +465,12 @@ instance PGNum ty
462 . show
465 . show
463
466
464instance (PGNum ty, PGFloating ty) => Fractional
467instance (PGNum ty, PGFloating ty) => Fractional
465− (Expression tables grouping params ('Required (nullity ty))) where
468+ (Expression tables grouping params '( '[], (nullity ty))) where
466 (/) = unsafeBinaryOp "/"
469 (/) = unsafeBinaryOp "/"
467 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
470 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
468
471
469instance (PGNum ty, PGFloating ty) => Floating
472instance (PGNum ty, PGFloating ty) => Floating
470− (Expression tables grouping params ('Required (nullity ty))) where
473+ (Expression tables grouping params '( '[], (nullity ty))) where
471 pi = UnsafeExpression "pi()"
474 pi = UnsafeExpression "pi()"
472 exp = unsafeFunction "exp"
475 exp = unsafeFunction "exp"
473 log = unsafeFunction "ln"
476 log = unsafeFunction "ln"
@@ -492,11 +495,11 @@ instance (PGNum ty, PGFloating ty) => Floating
492-- "atan2(pi(), 2)"
495-- "atan2(pi(), 2)"
493atan2_
496atan2_
494 :: PGFloating float
497 :: PGFloating float
495− => Expression tables grouping params ('Required (nullity float))
498+ => Expression tables grouping params '( '[], (nullity float))
496 -- ^ numerator
499 -- ^ numerator
497− -> Expression tables grouping params ('Required (nullity float))
500+ -> Expression tables grouping params '( '[], (nullity float))
498 -- ^ denominator
501 -- ^ denominator
499− -> Expression tables grouping params ('Required (nullity float))
502+ -> Expression tables grouping params '( '[], (nullity float))
500atan2_ y x = UnsafeExpression $
503atan2_ y x = UnsafeExpression $
501 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
504 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
502
505
@@ -507,11 +510,11 @@ atan2_ y x = UnsafeExpression $
507-- | >>> renderExpression $ true & cast int4
510-- | >>> renderExpression $ true & cast int4
508-- "(TRUE :: int4)"
511-- "(TRUE :: int4)"
509cast
512cast
510− :: TypeExpression ('Required ('Null ty1))
513+ :: TypeExpression '( '[], ('Null ty1))
511 -- ^ type to cast as
514 -- ^ type to cast as
512− -> Expression tables grouping params ('Required (nullity ty0))
515+ -> Expression tables grouping params '( '[], (nullity ty0))
513 -- ^ value to convert
516 -- ^ value to convert
514− -> Expression tables grouping params ('Required (nullity ty1))
517+ -> Expression tables grouping params '( '[], (nullity ty1))
515cast ty x = UnsafeExpression $ parenthesized $
518cast ty x = UnsafeExpression $ parenthesized $
516 renderExpression x <+> "::" <+> renderTypeExpression ty
519 renderExpression x <+> "::" <+> renderTypeExpression ty
517
520
@@ -521,11 +524,11 @@ cast ty x = UnsafeExpression $ parenthesized $
521-- "(5 / 2)"
524-- "(5 / 2)"
522quot_
525quot_
523 :: PGIntegral int
526 :: PGIntegral int
524− => Expression tables grouping params ('Required (nullity int))
527+ => Expression tables grouping params '( '[], (nullity int))
525 -- ^ numerator
528 -- ^ numerator
526− -> Expression tables grouping params ('Required (nullity int))
529+ -> Expression tables grouping params '( '[], (nullity int))
527 -- ^ denominator
530 -- ^ denominator
528− -> Expression tables grouping params ('Required (nullity int))
531+ -> Expression tables grouping params '( '[], (nullity int))
529quot_ = unsafeBinaryOp "/"
532quot_ = unsafeBinaryOp "/"
530
533
531-- | remainder upon integer division
534-- | remainder upon integer division
@@ -534,38 +537,38 @@ quot_ = unsafeBinaryOp "/"
534-- "(5 % 2)"
537-- "(5 % 2)"
535rem_
538rem_
536 :: PGIntegral int
539 :: PGIntegral int
537− => Expression tables grouping params ('Required (nullity int))
540+ => Expression tables grouping params '( '[], (nullity int))
538 -- ^ numerator
541 -- ^ numerator
539− -> Expression tables grouping params ('Required (nullity int))
542+ -> Expression tables grouping params '( '[], (nullity int))
540 -- ^ denominator
543 -- ^ denominator
541− -> Expression tables grouping params ('Required (nullity int))
544+ -> Expression tables grouping params '( '[], (nullity int))
542rem_ = unsafeBinaryOp "%"
545rem_ = unsafeBinaryOp "%"
543
546
544-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ trunc pi
547-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ trunc pi
545-- "trunc(pi())"
548-- "trunc(pi())"
546trunc
549trunc
547 :: PGFloating frac
550 :: PGFloating frac
548− => Expression tables grouping params ('Required (nullity frac))
551+ => Expression tables grouping params '( '[], (nullity frac))
549 -- ^ fractional number
552 -- ^ fractional number
550− -> Expression tables grouping params ('Required (nullity frac))
553+ -> Expression tables grouping params '( '[], (nullity frac))
551trunc = unsafeFunction "trunc"
554trunc = unsafeFunction "trunc"
552
555
553-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ round_ pi
556-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ round_ pi
554-- "round(pi())"
557-- "round(pi())"
555round_
558round_
556 :: PGFloating frac
559 :: PGFloating frac
557− => Expression tables grouping params ('Required (nullity frac))
560+ => Expression tables grouping params '( '[], (nullity frac))
558 -- ^ fractional number
561 -- ^ fractional number
559− -> Expression tables grouping params ('Required (nullity frac))
562+ -> Expression tables grouping params '( '[], (nullity frac))
560round_ = unsafeFunction "round"
563round_ = unsafeFunction "round"
561
564
562-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ ceiling_ pi
565-- | >>> renderExpression @_ @_ @_ @(_ (_ 'PGfloat4)) $ ceiling_ pi
563-- "ceiling(pi())"
566-- "ceiling(pi())"
564ceiling_
567ceiling_
565 :: PGFloating frac
568 :: PGFloating frac
566− => Expression tables grouping params ('Required (nullity frac))
569+ => Expression tables grouping params '( '[], (nullity frac))
567 -- ^ fractional number
570 -- ^ fractional number
568− -> Expression tables grouping params ('Required (nullity frac))
571+ -> Expression tables grouping params '( '[], (nullity frac))
569ceiling_ = unsafeFunction "ceiling"
572ceiling_ = unsafeFunction "ceiling"
570
573
571-- | A `Condition` is a boolean valued `Expression`. While SQL allows
574-- | A `Condition` is a boolean valued `Expression`. While SQL allows
@@ -573,7 +576,7 @@ ceiling_ = unsafeFunction "ceiling"
573-- forcing one to handle the case of @NULL@ explicitly to produce
576-- forcing one to handle the case of @NULL@ explicitly to produce
574-- a `Condition`.
577-- a `Condition`.
575type Condition tables grouping params =
578type Condition tables grouping params =
576− Expression tables grouping params ('Required ('NotNull 'PGbool))
579+ Expression tables grouping params '( '[], ('NotNull 'PGbool))
577
580
578-- | >>> renderExpression true
581-- | >>> renderExpression true
579-- "TRUE"
582-- "TRUE"
@@ -612,10 +615,10 @@ not_ = unsafeUnaryOp "NOT"
612-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
615-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
613caseWhenThenElse
616caseWhenThenElse
614 :: [ ( Condition tables grouping params
617 :: [ ( Condition tables grouping params
615− , Expression tables grouping params ('Required ty)
618+ , Expression tables grouping params '( '[], ty)
616 ) ]
619 ) ]
617− -> Expression tables grouping params ('Required ty)
620+ -> Expression tables grouping params '( '[], ty)
618− -> Expression tables grouping params ('Required ty)
621+ -> Expression tables grouping params '( '[], ty)
619caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
622caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
620 [ "CASE"
623 [ "CASE"
621 , mconcat
624 , mconcat
@@ -633,9 +636,9 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
633-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
636-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
634ifThenElse
637ifThenElse
635 :: Condition tables grouping params
638 :: Condition tables grouping params
636− -> Expression tables grouping params ('Required ty)
639+ -> Expression tables grouping params '( '[], ty)
637− -> Expression tables grouping params ('Required ty)
640+ -> Expression tables grouping params '( '[], ty)
638− -> Expression tables grouping params ('Required ty)
641+ -> Expression tables grouping params '( '[], ty)
639ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
642ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
640
643
641-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
644-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
@@ -644,85 +647,85 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
644-- >>> renderExpression $ unNull true .== null_
647-- >>> renderExpression $ unNull true .== null_
645-- "(TRUE = NULL)"
648-- "(TRUE = NULL)"
646(.==)
649(.==)
647− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
650+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
648− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
651+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
649− -> Expression tables grouping params ('Required (nullity 'PGbool))
652+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
650(.==) = unsafeBinaryOp "="
653(.==) = unsafeBinaryOp "="
651infix 4 .==
654infix 4 .==
652
655
653-- | >>> renderExpression $ unNull true ./= null_
656-- | >>> renderExpression $ unNull true ./= null_
654-- "(TRUE <> NULL)"
657-- "(TRUE <> NULL)"
655(./=)
658(./=)
656− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
659+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
657− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
660+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
658− -> Expression tables grouping params ('Required (nullity 'PGbool))
661+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
659(./=) = unsafeBinaryOp "<>"
662(./=) = unsafeBinaryOp "<>"
660infix 4 ./=
663infix 4 ./=
661
664
662-- | >>> renderExpression $ unNull true .>= null_
665-- | >>> renderExpression $ unNull true .>= null_
663-- "(TRUE >= NULL)"
666-- "(TRUE >= NULL)"
664(.>=)
667(.>=)
665− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
668+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
666− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
669+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
667− -> Expression tables grouping params ('Required (nullity 'PGbool))
670+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
668(.>=) = unsafeBinaryOp ">="
671(.>=) = unsafeBinaryOp ">="
669infix 4 .>=
672infix 4 .>=
670
673
671-- | >>> renderExpression $ unNull true .< null_
674-- | >>> renderExpression $ unNull true .< null_
672-- "(TRUE < NULL)"
675-- "(TRUE < NULL)"
673(.<)
676(.<)
674− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
677+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
675− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
678+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
676− -> Expression tables grouping params ('Required (nullity 'PGbool))
679+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
677(.<) = unsafeBinaryOp "<"
680(.<) = unsafeBinaryOp "<"
678infix 4 .<
681infix 4 .<
679
682
680-- | >>> renderExpression $ unNull true .<= null_
683-- | >>> renderExpression $ unNull true .<= null_
681-- "(TRUE <= NULL)"
684-- "(TRUE <= NULL)"
682(.<=)
685(.<=)
683− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
686+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
684− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
687+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
685− -> Expression tables grouping params ('Required (nullity 'PGbool))
688+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
686(.<=) = unsafeBinaryOp "<="
689(.<=) = unsafeBinaryOp "<="
687infix 4 .<=
690infix 4 .<=
688
691
689-- | >>> renderExpression $ unNull true .> null_
692-- | >>> renderExpression $ unNull true .> null_
690-- "(TRUE > NULL)"
693-- "(TRUE > NULL)"
691(.>)
694(.>)
692− :: Expression tables grouping params ('Required (nullity ty)) -- ^ lhs
695+ :: Expression tables grouping params '( '[], (nullity ty)) -- ^ lhs
693− -> Expression tables grouping params ('Required (nullity ty)) -- ^ rhs
696+ -> Expression tables grouping params '( '[], (nullity ty)) -- ^ rhs
694− -> Expression tables grouping params ('Required (nullity 'PGbool))
697+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
695(.>) = unsafeBinaryOp ">"
698(.>) = unsafeBinaryOp ">"
696infix 4 .>
699infix 4 .>
697
700
698-- | >>> renderExpression $ currentDate
701-- | >>> renderExpression $ currentDate
699-- "CURRENT_DATE"
702-- "CURRENT_DATE"
700currentDate
703currentDate
701− :: Expression tables grouping params ('Required (nullity 'PGdate))
704+ :: Expression tables grouping params '( '[], (nullity 'PGdate))
702currentDate = UnsafeExpression "CURRENT_DATE"
705currentDate = UnsafeExpression "CURRENT_DATE"
703
706
704-- | >>> renderExpression $ currentTime
707-- | >>> renderExpression $ currentTime
705-- "CURRENT_TIME"
708-- "CURRENT_TIME"
706currentTime
709currentTime
707− :: Expression tables grouping params ('Required (nullity 'PGtimetz))
710+ :: Expression tables grouping params '( '[], (nullity 'PGtimetz))
708currentTime = UnsafeExpression "CURRENT_TIME"
711currentTime = UnsafeExpression "CURRENT_TIME"
709
712
710-- | >>> renderExpression $ currentTimestamp
713-- | >>> renderExpression $ currentTimestamp
711-- "CURRENT_TIMESTAMP"
714-- "CURRENT_TIMESTAMP"
712currentTimestamp
715currentTimestamp
713− :: Expression tables grouping params ('Required (nullity 'PGtimestamptz))
716+ :: Expression tables grouping params '( '[], (nullity 'PGtimestamptz))
714currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
717currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
715
718
716-- | >>> renderExpression $ localTime
719-- | >>> renderExpression $ localTime
717-- "LOCALTIME"
720-- "LOCALTIME"
718localTime
721localTime
719− :: Expression tables grouping params ('Required (nullity 'PGtime))
722+ :: Expression tables grouping params '( '[], (nullity 'PGtime))
720localTime = UnsafeExpression "LOCALTIME"
723localTime = UnsafeExpression "LOCALTIME"
721
724
722-- | >>> renderExpression $ localTimestamp
725-- | >>> renderExpression $ localTimestamp
723-- "LOCALTIMESTAMP"
726-- "LOCALTIMESTAMP"
724localTimestamp
727localTimestamp
725− :: Expression tables grouping params ('Required (nullity 'PGtimestamp))
728+ :: Expression tables grouping params '( '[], (nullity 'PGtimestamp))
726localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
729localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
727
730
728{-----------------------------------------
731{-----------------------------------------
@@ -730,7 +733,7 @@ text
730-----------------------------------------}
733-----------------------------------------}
731
734
732instance IsString
735instance IsString
733− (Expression tables grouping params ('Required (nullity 'PGtext))) where
736+ (Expression tables grouping params '( '[], (nullity 'PGtext))) where
734 fromString str = UnsafeExpression $
737 fromString str = UnsafeExpression $
735 "E\'" <> fromString (escape =<< str) <> "\'"
738 "E\'" <> fromString (escape =<< str) <> "\'"
736 where
739 where
@@ -746,32 +749,32 @@ instance IsString
746 c -> [c]
749 c -> [c]
747
750
748instance Monoid
751instance Monoid
749− (Expression tables grouping params ('Required (nullity 'PGtext))) where
752+ (Expression tables grouping params '( '[], (nullity 'PGtext))) where
750 mempty = fromString ""
753 mempty = fromString ""
751 mappend = unsafeBinaryOp "||"
754 mappend = unsafeBinaryOp "||"
752
755
753-- | >>> renderExpression $ lower "ARRRGGG"
756-- | >>> renderExpression $ lower "ARRRGGG"
754-- "lower(E'ARRRGGG')"
757-- "lower(E'ARRRGGG')"
755lower
758lower
756− :: Expression tables grouping params ('Required (nullity 'PGtext))
759+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
757 -- ^ string to lower case
760 -- ^ string to lower case
758− -> Expression tables grouping params ('Required (nullity 'PGtext))
761+ -> Expression tables grouping params '( '[], (nullity 'PGtext))
759lower = unsafeFunction "lower"
762lower = unsafeFunction "lower"
760
763
761-- | >>> renderExpression $ upper "eeee"
764-- | >>> renderExpression $ upper "eeee"
762-- "upper(E'eeee')"
765-- "upper(E'eeee')"
763upper
766upper
764− :: Expression tables grouping params ('Required (nullity 'PGtext))
767+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
765 -- ^ string to upper case
768 -- ^ string to upper case
766− -> Expression tables grouping params ('Required (nullity 'PGtext))
769+ -> Expression tables grouping params '( '[], (nullity 'PGtext))
767upper = unsafeFunction "upper"
770upper = unsafeFunction "upper"
768
771
769-- | >>> renderExpression $ charLength "four"
772-- | >>> renderExpression $ charLength "four"
770-- "char_length(E'four')"
773-- "char_length(E'four')"
771charLength
774charLength
772− :: Expression tables grouping params ('Required (nullity 'PGtext))
775+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
773 -- ^ string to measure
776 -- ^ string to measure
774− -> Expression tables grouping params ('Required (nullity 'PGint4))
777+ -> Expression tables grouping params '( '[], (nullity 'PGint4))
775charLength = unsafeFunction "char_length"
778charLength = unsafeFunction "char_length"
776
779
777-- | The `like` expression returns true if the @string@ matches
780-- | The `like` expression returns true if the @string@ matches
@@ -784,11 +787,11 @@ charLength = unsafeFunction "char_length"
784-- >>> renderExpression $ "abc" `like` "a%"
787-- >>> renderExpression $ "abc" `like` "a%"
785-- "(E'abc' LIKE E'a%')"
788-- "(E'abc' LIKE E'a%')"
786like
789like
787− :: Expression tables grouping params ('Required (nullity 'PGtext))
790+ :: Expression tables grouping params '( '[], (nullity 'PGtext))
788 -- ^ string
791 -- ^ string
789− -> Expression tables grouping params ('Required (nullity 'PGtext))
792+ -> Expression tables grouping params '( '[], (nullity 'PGtext))
790 -- ^ pattern
793 -- ^ pattern
791− -> Expression tables grouping params ('Required (nullity 'PGbool))
794+ -> Expression tables grouping params '( '[], (nullity 'PGbool))
792like = unsafeBinaryOp "LIKE"
795like = unsafeBinaryOp "LIKE"
793
796
794{-----------------------------------------
797{-----------------------------------------
@@ -798,16 +801,16 @@ aggregation
798-- | escape hatch to define aggregate functions
801-- | escape hatch to define aggregate functions
799unsafeAggregate
802unsafeAggregate
800 :: ByteString -- ^ aggregate function
803 :: ByteString -- ^ aggregate function
801− -> Expression tables 'Ungrouped params ('Required xty)
804+ -> Expression tables 'Ungrouped params '( '[], xty)
802− -> Expression tables ('Grouped bys) params ('Required yty)
805+ -> Expression tables ('Grouped bys) params '( '[], yty)
803unsafeAggregate fun x = UnsafeExpression $ mconcat
806unsafeAggregate fun x = UnsafeExpression $ mconcat
804 [fun, "(", renderExpression x, ")"]
807 [fun, "(", renderExpression x, ")"]
805
808
806-- | escape hatch to define aggregate functions over distinct values
809-- | escape hatch to define aggregate functions over distinct values
807unsafeAggregateDistinct
810unsafeAggregateDistinct
808 :: ByteString -- ^ aggregate function
811 :: ByteString -- ^ aggregate function
809− -> Expression tables 'Ungrouped params ('Required xty)
812+ -> Expression tables 'Ungrouped params '( '[], xty)
810− -> Expression tables ('Grouped bys) params ('Required yty)
813+ -> Expression tables ('Grouped bys) params '( '[], yty)
811unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
814unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
812 [fun, "(DISTINCT ", renderExpression x, ")"]
815 [fun, "(DISTINCT ", renderExpression x, ")"]
813
816
@@ -815,27 +818,27 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
815-- "sum(col)"
818-- "sum(col)"
816sum_
819sum_
817 :: PGNum ty
820 :: PGNum ty
818− => Expression tables 'Ungrouped params ('Required (nullity ty))
821+ => Expression tables 'Ungrouped params '( '[], (nullity ty))
819 -- ^ what to sum
822 -- ^ what to sum
820− -> Expression tables ('Grouped bys) params ('Required (nullity ty))
823+ -> Expression tables ('Grouped bys) params '( '[], (nullity ty))
821sum_ = unsafeAggregate "sum"
824sum_ = unsafeAggregate "sum"
822
825
823-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGnumeric)]] $ sumDistinct #col
826-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGnumeric)]] $ sumDistinct #col
824-- "sum(DISTINCT col)"
827-- "sum(DISTINCT col)"
825sumDistinct
828sumDistinct
826 :: PGNum ty
829 :: PGNum ty
827− => Expression tables 'Ungrouped params ('Required (nullity ty))
830+ => Expression tables 'Ungrouped params '( '[], (nullity ty))
828 -- ^ what to sum
831 -- ^ what to sum
829− -> Expression tables ('Grouped bys) params ('Required (nullity ty))
832+ -> Expression tables ('Grouped bys) params '( '[], (nullity ty))
830sumDistinct = unsafeAggregateDistinct "sum"
833sumDistinct = unsafeAggregateDistinct "sum"
831
834
832-- | A constraint for `PGType`s that you can take averages of and the resulting
835-- | A constraint for `PGType`s that you can take averages of and the resulting
833-- `PGType`.
836-- `PGType`.
834class PGAvg ty avg | ty -> avg where
837class PGAvg ty avg | ty -> avg where
835 avg, avgDistinct
838 avg, avgDistinct
836− :: Expression tables 'Ungrouped params ('Required (nullity ty))
839+ :: Expression tables 'Ungrouped params '( '[], (nullity ty))
837 -- ^ what to average
840 -- ^ what to average
838− -> Expression tables ('Grouped bys) params ('Required (nullity avg))
841+ -> Expression tables ('Grouped bys) params '( '[], (nullity avg))
839 avg = unsafeAggregate "avg"
842 avg = unsafeAggregate "avg"
840 avgDistinct = unsafeAggregateDistinct "avg"
843 avgDistinct = unsafeAggregateDistinct "avg"
841instance PGAvg 'PGint2 'PGnumeric
844instance PGAvg 'PGint2 'PGnumeric
@@ -850,68 +853,68 @@ instance PGAvg 'PGinterval 'PGinterval
850-- "bit_and(col)"
853-- "bit_and(col)"
851bitAnd
854bitAnd
852 :: PGIntegral int
855 :: PGIntegral int
853− => Expression tables 'Ungrouped params ('Required (nullity int))
856+ => Expression tables 'Ungrouped params '( '[], (nullity int))
854 -- ^ what to aggregate
857 -- ^ what to aggregate
855− -> Expression tables ('Grouped bys) params ('Required (nullity int))
858+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
856bitAnd = unsafeAggregate "bit_and"
859bitAnd = unsafeAggregate "bit_and"
857
860
858-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitOr #col
861-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitOr #col
859-- "bit_or(col)"
862-- "bit_or(col)"
860bitOr
863bitOr
861 :: PGIntegral int
864 :: PGIntegral int
862− => Expression tables 'Ungrouped params ('Required (nullity int))
865+ => Expression tables 'Ungrouped params '( '[], (nullity int))
863 -- ^ what to aggregate
866 -- ^ what to aggregate
864− -> Expression tables ('Grouped bys) params ('Required (nullity int))
867+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
865bitOr = unsafeAggregate "bit_or"
868bitOr = unsafeAggregate "bit_or"
866
869
867-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitAndDistinct #col
870-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitAndDistinct #col
868-- "bit_and(DISTINCT col)"
871-- "bit_and(DISTINCT col)"
869bitAndDistinct
872bitAndDistinct
870 :: PGIntegral int
873 :: PGIntegral int
871− => Expression tables 'Ungrouped params ('Required (nullity int))
874+ => Expression tables 'Ungrouped params '( '[], (nullity int))
872 -- ^ what to aggregate
875 -- ^ what to aggregate
873− -> Expression tables ('Grouped bys) params ('Required (nullity int))
876+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
874bitAndDistinct = unsafeAggregateDistinct "bit_and"
877bitAndDistinct = unsafeAggregateDistinct "bit_and"
875
878
876-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitOrDistinct #col
879-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGint4)]] $ bitOrDistinct #col
877-- "bit_or(DISTINCT col)"
880-- "bit_or(DISTINCT col)"
878bitOrDistinct
881bitOrDistinct
879 :: PGIntegral int
882 :: PGIntegral int
880− => Expression tables 'Ungrouped params ('Required (nullity int))
883+ => Expression tables 'Ungrouped params '( '[], (nullity int))
881 -- ^ what to aggregate
884 -- ^ what to aggregate
882− -> Expression tables ('Grouped bys) params ('Required (nullity int))
885+ -> Expression tables ('Grouped bys) params '( '[], (nullity int))
883bitOrDistinct = unsafeAggregateDistinct "bit_or"
886bitOrDistinct = unsafeAggregateDistinct "bit_or"
884
887
885-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolAnd #col
888-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolAnd #col
886-- "bool_and(col)"
889-- "bool_and(col)"
887boolAnd
890boolAnd
888− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
891+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
889 -- ^ what to aggregate
892 -- ^ what to aggregate
890− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
893+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
891boolAnd = unsafeAggregate "bool_and"
894boolAnd = unsafeAggregate "bool_and"
892
895
893-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolOr #col
896-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolOr #col
894-- "bool_or(col)"
897-- "bool_or(col)"
895boolOr
898boolOr
896− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
899+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
897 -- ^ what to aggregate
900 -- ^ what to aggregate
898− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
901+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
899boolOr = unsafeAggregate "bool_or"
902boolOr = unsafeAggregate "bool_or"
900
903
901-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolAndDistinct #col
904-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolAndDistinct #col
902-- "bool_and(DISTINCT col)"
905-- "bool_and(DISTINCT col)"
903boolAndDistinct
906boolAndDistinct
904− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
907+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
905 -- ^ what to aggregate
908 -- ^ what to aggregate
906− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
909+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
907boolAndDistinct = unsafeAggregateDistinct "bool_and"
910boolAndDistinct = unsafeAggregateDistinct "bool_and"
908
911
909-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolOrDistinct #col
912-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ boolOrDistinct #col
910-- "bool_or(DISTINCT col)"
913-- "bool_or(DISTINCT col)"
911boolOrDistinct
914boolOrDistinct
912− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
915+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
913 -- ^ what to aggregate
916 -- ^ what to aggregate
914− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
917+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
915boolOrDistinct = unsafeAggregateDistinct "bool_or"
918boolOrDistinct = unsafeAggregateDistinct "bool_or"
916
919
917-- | A special aggregation that does not require an input
920-- | A special aggregation that does not require an input
@@ -919,23 +922,23 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
919-- >>> renderExpression countStar
922-- >>> renderExpression countStar
920-- "count(*)"
923-- "count(*)"
921countStar
924countStar
922− :: Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
925+ :: Expression tables ('Grouped bys) params '( '[], ('NotNull 'PGint8))
923countStar = UnsafeExpression $ "count(*)"
926countStar = UnsafeExpression $ "count(*)"
924
927
925-- | >>> renderExpression @'[_ ::: '["col" ::: 'Optional _]] $ count #col
928-- | >>> renderExpression @'[_ ::: '["col" ::: 'Optional _]] $ count #col
926-- "count(col)"
929-- "count(col)"
927count
930count
928− :: Expression tables 'Ungrouped params ('Required ty)
931+ :: Expression tables 'Ungrouped params '( '[], ty)
929 -- ^ what to count
932 -- ^ what to count
930− -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
933+ -> Expression tables ('Grouped bys) params '( '[], ('NotNull 'PGint8))
931count = unsafeAggregate "count"
934count = unsafeAggregate "count"
932
935
933-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required _]] $ countDistinct #col
936-- | >>> renderExpression @'[_ ::: '["col" ::: 'Required _]] $ countDistinct #col
934-- "count(DISTINCT col)"
937-- "count(DISTINCT col)"
935countDistinct
938countDistinct
936− :: Expression tables 'Ungrouped params ('Required ty)
939+ :: Expression tables 'Ungrouped params '( '[], ty)
937 -- ^ what to count
940 -- ^ what to count
938− -> Expression tables ('Grouped bys) params ('Required ('NotNull 'PGint8))
941+ -> Expression tables ('Grouped bys) params '( '[], ('NotNull 'PGint8))
939countDistinct = unsafeAggregateDistinct "count"
942countDistinct = unsafeAggregateDistinct "count"
940
943
941-- | synonym for `boolAnd`
944-- | synonym for `boolAnd`
@@ -943,9 +946,9 @@ countDistinct = unsafeAggregateDistinct "count"
943-- >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ every #col
946-- >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ every #col
944-- "every(col)"
947-- "every(col)"
945every
948every
946− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
949+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
947 -- ^ what to aggregate
950 -- ^ what to aggregate
948− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
951+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
949every = unsafeAggregate "every"
952every = unsafeAggregate "every"
950
953
951-- | synonym for `boolAndDistinct`
954-- | synonym for `boolAndDistinct`
@@ -953,16 +956,16 @@ every = unsafeAggregate "every"
953-- >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ everyDistinct #col
956-- >>> renderExpression @'[_ ::: '["col" ::: 'Required (_ 'PGbool)]] $ everyDistinct #col
954-- "every(DISTINCT col)"
957-- "every(DISTINCT col)"
955everyDistinct
958everyDistinct
956− :: Expression tables 'Ungrouped params ('Required (nullity 'PGbool))
959+ :: Expression tables 'Ungrouped params '( '[], (nullity 'PGbool))
957 -- ^ what to aggregate
960 -- ^ what to aggregate
958− -> Expression tables ('Grouped bys) params ('Required (nullity 'PGbool))
961+ -> Expression tables ('Grouped bys) params '( '[], (nullity 'PGbool))
959everyDistinct = unsafeAggregateDistinct "every"
962everyDistinct = unsafeAggregateDistinct "every"
960
963
961-- | minimum and maximum aggregation
964-- | minimum and maximum aggregation
962max_, min_, maxDistinct, minDistinct
965max_, min_, maxDistinct, minDistinct
963− :: Expression tables 'Ungrouped params ('Required (nullity ty))
966+ :: Expression tables 'Ungrouped params '( '[], (nullity ty))
964 -- ^ what to aggregate
967 -- ^ what to aggregate
965− -> Expression tables ('Grouped bys) params ('Required (nullity ty))
968+ -> Expression tables ('Grouped bys) params '( '[], (nullity ty))
966max_ = unsafeAggregate "max"
969max_ = unsafeAggregate "max"
967min_ = unsafeAggregate "min"
970min_ = unsafeAggregate "min"
968maxDistinct = unsafeAggregateDistinct "max"
971maxDistinct = unsafeAggregateDistinct "max"
@@ -1005,97 +1008,97 @@ newtype TypeExpression (ty :: ColumnType)
1005 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1008 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1006
1009
1007-- | logical Boolean (true/false)
1010-- | logical Boolean (true/false)
1008−bool :: TypeExpression ('Required ('Null 'PGbool))
1011+bool :: TypeExpression '( '[], ('Null 'PGbool))
1009bool = UnsafeTypeExpression "bool"
1012bool = UnsafeTypeExpression "bool"
1010-- | signed two-byte integer
1013-- | signed two-byte integer
1011−int2, smallint :: TypeExpression ('Required ('Null 'PGint2))
1014+int2, smallint :: TypeExpression '( '[], ('Null 'PGint2))
1012int2 = UnsafeTypeExpression "int2"
1015int2 = UnsafeTypeExpression "int2"
1013smallint = UnsafeTypeExpression "smallint"
1016smallint = UnsafeTypeExpression "smallint"
1014-- | signed four-byte integer
1017-- | signed four-byte integer
1015−int4, int, integer :: TypeExpression ('Required ('Null 'PGint4))
1018+int4, int, integer :: TypeExpression '( '[], ('Null 'PGint4))
1016int4 = UnsafeTypeExpression "int4"
1019int4 = UnsafeTypeExpression "int4"
1017int = UnsafeTypeExpression "int"
1020int = UnsafeTypeExpression "int"
1018integer = UnsafeTypeExpression "integer"
1021integer = UnsafeTypeExpression "integer"
1019-- | signed eight-byte integer
1022-- | signed eight-byte integer
1020−int8, bigint :: TypeExpression ('Required ('Null 'PGint8))
1023+int8, bigint :: TypeExpression '( '[], ('Null 'PGint8))
1021int8 = UnsafeTypeExpression "int8"
1024int8 = UnsafeTypeExpression "int8"
1022bigint = UnsafeTypeExpression "bigint"
1025bigint = UnsafeTypeExpression "bigint"
1023-- | arbitrary precision numeric type
1026-- | arbitrary precision numeric type
1024−numeric :: TypeExpression ('Required ('Null 'PGnumeric))
1027+numeric :: TypeExpression '( '[], ('Null 'PGnumeric))
1025numeric = UnsafeTypeExpression "numeric"
1028numeric = UnsafeTypeExpression "numeric"
1026-- | single precision floating-point number (4 bytes)
1029-- | single precision floating-point number (4 bytes)
1027−float4, real :: TypeExpression ('Required ('Null 'PGfloat4))
1030+float4, real :: TypeExpression '( '[], ('Null 'PGfloat4))
1028float4 = UnsafeTypeExpression "float4"
1031float4 = UnsafeTypeExpression "float4"
1029real = UnsafeTypeExpression "real"
1032real = UnsafeTypeExpression "real"
1030-- | double precision floating-point number (8 bytes)
1033-- | double precision floating-point number (8 bytes)
1031−float8, doublePrecision :: TypeExpression ('Required ('Null 'PGfloat8))
1034+float8, doublePrecision :: TypeExpression '( '[], ('Null 'PGfloat8))
1032float8 = UnsafeTypeExpression "float8"
1035float8 = UnsafeTypeExpression "float8"
1033doublePrecision = UnsafeTypeExpression "double precision"
1036doublePrecision = UnsafeTypeExpression "double precision"
1034-- | not a true type, but merely a notational convenience for creating
1037-- | not a true type, but merely a notational convenience for creating
1035-- unique identifier columns with type `'PGint2`
1038-- unique identifier columns with type `'PGint2`
1036−serial2, smallserial :: TypeExpression ('Optional ('NotNull 'PGint2))
1039+serial2, smallserial :: TypeExpression '(constraints, ('NotNull 'PGint2))
1037serial2 = UnsafeTypeExpression "serial2"
1040serial2 = UnsafeTypeExpression "serial2"
1038smallserial = UnsafeTypeExpression "smallserial"
1041smallserial = UnsafeTypeExpression "smallserial"
1039-- | not a true type, but merely a notational convenience for creating
1042-- | not a true type, but merely a notational convenience for creating
1040-- unique identifier columns with type `'PGint4`
1043-- unique identifier columns with type `'PGint4`
1041−serial4, serial :: TypeExpression ('Optional ('NotNull 'PGint4))
1044+serial4, serial :: TypeExpression '(constraints, ('NotNull 'PGint4))
1042serial4 = UnsafeTypeExpression "serial4"
1045serial4 = UnsafeTypeExpression "serial4"
1043serial = UnsafeTypeExpression "serial"
1046serial = UnsafeTypeExpression "serial"
1044-- | not a true type, but merely a notational convenience for creating
1047-- | not a true type, but merely a notational convenience for creating
1045-- unique identifier columns with type `'PGint8`
1048-- unique identifier columns with type `'PGint8`
1046−serial8, bigserial :: TypeExpression ('Optional ('NotNull 'PGint8))
1049+serial8, bigserial :: TypeExpression '(constraints, ('NotNull 'PGint8))
1047serial8 = UnsafeTypeExpression "serial8"
1050serial8 = UnsafeTypeExpression "serial8"
1048bigserial = UnsafeTypeExpression "bigserial"
1051bigserial = UnsafeTypeExpression "bigserial"
1049-- | variable-length character string
1052-- | variable-length character string
1050−text :: TypeExpression ('Required ('Null 'PGtext))
1053+text :: TypeExpression '( '[], ('Null 'PGtext))
1051text = UnsafeTypeExpression "text"
1054text = UnsafeTypeExpression "text"
1052-- | fixed-length character string
1055-- | fixed-length character string
1053char, character
1056char, character
1054 :: (KnownNat n, 1 <= n)
1057 :: (KnownNat n, 1 <= n)
1055 => proxy n
1058 => proxy n
1056− -> TypeExpression ('Required ('Null ('PGchar n)))
1059+ -> TypeExpression '( '[], ('Null ('PGchar n)))
1057char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
1060char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
1058character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
1061character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
1059-- | variable-length character string
1062-- | variable-length character string
1060varchar, characterVarying
1063varchar, characterVarying
1061 :: (KnownNat n, 1 <= n)
1064 :: (KnownNat n, 1 <= n)
1062 => proxy n
1065 => proxy n
1063− -> TypeExpression ('Required ('Null ('PGvarchar n)))
1066+ -> TypeExpression '( '[], ('Null ('PGvarchar n)))
1064varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
1067varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
1065characterVarying p = UnsafeTypeExpression $
1068characterVarying p = UnsafeTypeExpression $
1066 "character varying(" <> renderNat p <> ")"
1069 "character varying(" <> renderNat p <> ")"
1067-- | binary data ("byte array")
1070-- | binary data ("byte array")
1068−bytea :: TypeExpression ('Required ('Null 'PGbytea))
1071+bytea :: TypeExpression '( '[], ('Null 'PGbytea))
1069bytea = UnsafeTypeExpression "bytea"
1072bytea = UnsafeTypeExpression "bytea"
1070-- | date and time (no time zone)
1073-- | date and time (no time zone)
1071−timestamp :: TypeExpression ('Required ('Null 'PGtimestamp))
1074+timestamp :: TypeExpression '( '[], ('Null 'PGtimestamp))
1072timestamp = UnsafeTypeExpression "timestamp"
1075timestamp = UnsafeTypeExpression "timestamp"
1073-- | date and time, including time zone
1076-- | date and time, including time zone
1074−timestampWithTimeZone :: TypeExpression ('Required ('Null 'PGtimestamptz))
1077+timestampWithTimeZone :: TypeExpression '( '[], ('Null 'PGtimestamptz))
1075timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1078timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
1076-- | calendar date (year, month, day)
1079-- | calendar date (year, month, day)
1077−date :: TypeExpression ('Required ('Null 'PGdate))
1080+date :: TypeExpression '( '[], ('Null 'PGdate))
1078date = UnsafeTypeExpression "date"
1081date = UnsafeTypeExpression "date"
1079-- | time of day (no time zone)
1082-- | time of day (no time zone)
1080−time :: TypeExpression ('Required ('Null 'PGtime))
1083+time :: TypeExpression '( '[], ('Null 'PGtime))
1081time = UnsafeTypeExpression "time"
1084time = UnsafeTypeExpression "time"
1082-- | time of day, including time zone
1085-- | time of day, including time zone
1083−timeWithTimeZone :: TypeExpression ('Required ('Null 'PGtimetz))
1086+timeWithTimeZone :: TypeExpression '( '[], ('Null 'PGtimetz))
1084timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1087timeWithTimeZone = UnsafeTypeExpression "time with time zone"
1085-- | time span
1088-- | time span
1086−interval :: TypeExpression ('Required ('Null 'PGinterval))
1089+interval :: TypeExpression '( '[], ('Null 'PGinterval))
1087interval = UnsafeTypeExpression "interval"
1090interval = UnsafeTypeExpression "interval"
1088-- | universally unique identifier
1091-- | universally unique identifier
1089−uuid :: TypeExpression ('Required ('Null 'PGuuid))
1092+uuid :: TypeExpression '( '[], ('Null 'PGuuid))
1090uuid = UnsafeTypeExpression "uuid"
1093uuid = UnsafeTypeExpression "uuid"
1091-- | IPv4 or IPv6 host address
1094-- | IPv4 or IPv6 host address
1092−inet :: TypeExpression ('Required ('Null 'PGinet))
1095+inet :: TypeExpression '( '[], ('Null 'PGinet))
1093inet = UnsafeTypeExpression "inet"
1096inet = UnsafeTypeExpression "inet"
1094-- | textual JSON data
1097-- | textual JSON data
1095−json :: TypeExpression ('Required ('Null 'PGjson))
1098+json :: TypeExpression '( '[], ('Null 'PGjson))
1096json = UnsafeTypeExpression "json"
1099json = UnsafeTypeExpression "json"
1097-- | binary JSON data, decomposed
1100-- | binary JSON data, decomposed
1098−jsonb :: TypeExpression ('Required ('Null 'PGjsonb))
1101+jsonb :: TypeExpression '( '[], ('Null 'PGjsonb))
1099jsonb = UnsafeTypeExpression "jsonb"
1102jsonb = UnsafeTypeExpression "jsonb"
1100
1103
1101-- | used in `createTable` commands as a column constraint to ensure
1104-- | used in `createTable` commands as a column constraint to ensure
@@ -1107,15 +1110,15 @@ notNull ty = UnsafeTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
1107
1110
1108-- | used in `createTable` commands as a column constraint to give a default
1111-- | used in `createTable` commands as a column constraint to give a default
1109default_
1112default_
1110− :: Expression '[] 'Ungrouped '[] ('Required ty)
1113+ :: Expression '[] 'Ungrouped '[] '( '[], ty)
1111− -> TypeExpression ('Required ty)
1114+ -> TypeExpression '( '[], ty)
1112− -> TypeExpression ('Optional ty)
1115+ -> TypeExpression '(constraints, ty)
1113default_ x ty = UnsafeTypeExpression $
1116default_ x ty = UnsafeTypeExpression $
1114 renderTypeExpression ty <+> "DEFAULT" <+> renderExpression x
1117 renderTypeExpression ty <+> "DEFAULT" <+> renderExpression x
1115
1118
1116-- | `pgtype` is a demoted version of a `PGType`
1119-- | `pgtype` is a demoted version of a `PGType`
1117class PGTyped (ty :: PGType) where
1120class PGTyped (ty :: PGType) where
1118− pgtype :: TypeExpression ('Required ('Null ty))
1121+ pgtype :: TypeExpression '( '[], ('Null ty))
1119instance PGTyped 'PGbool where pgtype = bool
1122instance PGTyped 'PGbool where pgtype = bool
1120instance PGTyped 'PGint2 where pgtype = int2
1123instance PGTyped 'PGint2 where pgtype = int2
1121instance PGTyped 'PGint4 where pgtype = int4
1124instance PGTyped 'PGint4 where pgtype = int4
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+6−6
@@ -743,22 +743,22 @@ Sorting
743-- ordering of a `Null` result column.
743-- ordering of a `Null` result column.
744data SortExpression tables grouping params where
744data SortExpression tables grouping params where
745 Asc
745 Asc
746− :: Expression tables grouping params ('Required ('NotNull ty))
746+ :: Expression tables grouping params '( '[], ('NotNull ty))
747 -> SortExpression tables grouping params
747 -> SortExpression tables grouping params
748 Desc
748 Desc
749− :: Expression tables grouping params ('Required ('NotNull ty))
749+ :: Expression tables grouping params '( '[], ('NotNull ty))
750 -> SortExpression tables grouping params
750 -> SortExpression tables grouping params
751 AscNullsFirst
751 AscNullsFirst
752− :: Expression tables grouping params ('Required ('Null ty))
752+ :: Expression tables grouping params '( '[], ('Null ty))
753 -> SortExpression tables grouping params
753 -> SortExpression tables grouping params
754 AscNullsLast
754 AscNullsLast
755− :: Expression tables grouping params ('Required ('Null ty))
755+ :: Expression tables grouping params '( '[], ('Null ty))
756 -> SortExpression tables grouping params
756 -> SortExpression tables grouping params
757 DescNullsFirst
757 DescNullsFirst
758− :: Expression tables grouping params ('Required ('Null ty))
758+ :: Expression tables grouping params '( '[], ('Null ty))
759 -> SortExpression tables grouping params
759 -> SortExpression tables grouping params
760 DescNullsLast
760 DescNullsLast
761− :: Expression tables grouping params ('Required ('Null ty))
761+ :: Expression tables grouping params '( '[], ('Null ty))
762 -> SortExpression tables grouping params
762 -> SortExpression tables grouping params
763deriving instance Show (SortExpression tables grouping params)
763deriving instance Show (SortExpression tables grouping params)
764
764
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+19−13
@@ -34,7 +34,7 @@ module Squeal.PostgreSQL.Schema
34 ( -- * Kinds
34 ( -- * Kinds
35 PGType (..)
35 PGType (..)
36 , NullityType (..)
36 , NullityType (..)
37− , ColumnType (..)
37+ , ColumnType
38 , ColumnsType
38 , ColumnsType
39 , TablesType
39 , TablesType
40 , Grouping (..)
40 , Grouping (..)
@@ -53,7 +53,7 @@ module Squeal.PostgreSQL.Schema
53 -- * Type Families
53 -- * Type Families
54 , In
54 , In
55 , HasUnique
55 , HasUnique
56− , BaseType
56+ , PGTypeOf
57 , SameTypes
57 , SameTypes
58 , AllNotNull
58 , AllNotNull
59 , NotAllNull
59 , NotAllNull
@@ -71,6 +71,8 @@ module Squeal.PostgreSQL.Schema
71 -- * PostgreSQL Constraints
71 -- * PostgreSQL Constraints
72 , (:=>)
72 , (:=>)
73 , ColumnConstraint (..)
73 , ColumnConstraint (..)
74+ , DropDefault
75+ , DropDefaultList
74 ) where
76 ) where
75
77
76import Control.DeepSeq
78import Control.DeepSeq
@@ -122,11 +124,7 @@ data NullityType
122-- is to use `Squeal.PostgreSQL.Expression.def`,
124-- is to use `Squeal.PostgreSQL.Expression.def`,
123-- `Squeal.PostgreSQL.Expression.unDef` or
125-- `Squeal.PostgreSQL.Expression.unDef` or
124-- `Squeal.PostgreSQL.Expression.param`.
126-- `Squeal.PostgreSQL.Expression.param`.
125−data ColumnType
127+type ColumnType = ([ColumnConstraint],NullityType)
126− = Optional NullityType
127− -- ^ @DEFAULT@ is allowed
128− | Required NullityType
129− -- ^ @DEFAULT@ is not allowed
130
128
131-- | `ColumnsType` is a kind synonym for a row of `ColumnType`s.
129-- | `ColumnsType` is a kind synonym for a row of `ColumnType`s.
132type ColumnsType = [(Symbol,ColumnType)]
130type ColumnsType = [(Symbol,ColumnType)]
@@ -226,9 +224,9 @@ type family In x xs :: Constraint where
226-- of @alias ::: x@.
224-- of @alias ::: x@.
227type HasUnique alias xs x = xs ~ '[alias ::: x]
225type HasUnique alias xs x = xs ~ '[alias ::: x]
228
226
229−-- | `BaseType` forgets about @NULL@ and @DEFAULT@
227+-- | `PGTypeOf` forgets about @NULL@ and any column constraints.
230−type family BaseType (ty :: ColumnType) :: PGType where
228+type family PGTypeOf (ty :: ColumnType) :: PGType where
231− BaseType (optionality (nullity pg)) = pg
229+ PGTypeOf '(constraints, nullity pg) = pg
232
230
233-- | `SameTypes` is a constraint that proves two `ColumnsType`s have the same
231-- | `SameTypes` is a constraint that proves two `ColumnsType`s have the same
234-- length and the same `ColumnType`s.
232-- length and the same `ColumnType`s.
@@ -242,14 +240,14 @@ type family SameTypes
242-- | `AllNotNull` is a constraint that proves a `ColumnsType` has no @NULL@s.
240-- | `AllNotNull` is a constraint that proves a `ColumnsType` has no @NULL@s.
243type family AllNotNull (columns :: ColumnsType) :: Constraint where
241type family AllNotNull (columns :: ColumnsType) :: Constraint where
244 AllNotNull '[] = ()
242 AllNotNull '[] = ()
245− AllNotNull ((column ::: (optionality ('NotNull ty))) ': columns)
243+ AllNotNull ((column ::: '(constraints, ('NotNull ty))) ': columns)
246 = AllNotNull columns
244 = AllNotNull columns
247
245
248-- | `NotAllNull` is a constraint that proves a `ColumnsType` has some
246-- | `NotAllNull` is a constraint that proves a `ColumnsType` has some
249-- @NOT NULL@.
247-- @NOT NULL@.
250type family NotAllNull columns :: Constraint where
248type family NotAllNull columns :: Constraint where
251− NotAllNull ((column ::: (optionality ('NotNull ty))) ': columns) = ()
249+ NotAllNull ((column ::: '(constraints, ('NotNull ty))) ': columns) = ()
252− NotAllNull ((column ::: (optionality ('Null ty))) ': columns)
250+ NotAllNull ((column ::: '(constraints, ('Null ty))) ': columns)
253 = NotAllNull columns
251 = NotAllNull columns
254
252
255-- | `NullifyType` is an idempotent that nullifies a `ColumnType`.
253-- | `NullifyType` is an idempotent that nullifies a `ColumnType`.
@@ -333,3 +331,11 @@ data ColumnConstraint
333 = Default
331 = Default
334 | Unique
332 | Unique
335 | References Symbol Symbol
333 | References Symbol Symbol
334+
335+type DropDefault constraints = AsSet (DropDefaultList constraints)
336+
337+type family DropDefaultList constraints where
338+ DropDefaultList '[] = '[]
339+ DropDefaultList ( 'Default ': constraints) = constraints
340+ DropDefaultList (constraint ': constraints) =
341+ constraint ': DropDefaultList constraints