on master help sign in
Rename all the null things
commitf1e287ea9f5b431103657160c4e8e8372c973c21 authorShane O'Brien <shane.obrien@circuithub.com> dateWed 7 Apr 2021, 22:35 (6 years ago) parent593e21b
43 files changed+270−310
rel8.cabal+1−1 src/Rel8.hs+5−5 src/Rel8/Aggregate.hs+1−1 src/Rel8/Expr.hs+11−14 src/Rel8/Expr/Aggregate.hs+1−1 src/Rel8/Expr/Array.hs+2−2 src/Rel8/Expr/Eq.hs+15−16 src/Rel8/Expr/Function.hs+1−1 src/Rel8/Expr/Null.hs+14−14 src/Rel8/Expr/Num.hs+1−1 src/Rel8/Expr/Opaleye.hs+1−1 src/Rel8/Expr/Ord.hs+25−27 src/Rel8/Expr/Serialize.hs+11−15 src/Rel8/Query/Null.hs+3−3 src/Rel8/Schema/Context/Identity.hs+8−11 src/Rel8/Schema/Context/Nullify.hs+27−31 src/Rel8/Schema/HTable/Nullify.hs+7−10 src/Rel8/Schema/HTable/Type.hs+2−2 src/Rel8/Schema/HTable/Vectorize.hs+9−13 src/Rel8/Schema/Insert.hs+8−8 src/Rel8/Schema/Name.hs+1−1 src/Rel8/Schema/Nullability.hs → src/Rel8/Schema/Null.hs+30−30 src/Rel8/Schema/Spec.hs+4−4 src/Rel8/Schema/Spec/ConstrainDBType.hs+9−13 src/Rel8/Table.hs+1−1 src/Rel8/Table/Eq.hs+1−1 src/Rel8/Table/List.hs+8−8 src/Rel8/Table/Maybe.hs+4−8 src/Rel8/Table/NonEmpty.hs+8−8 src/Rel8/Table/Ord.hs+1−1 src/Rel8/Table/Order.hs+9−9 src/Rel8/Table/Recontextualize.hs+1−1 src/Rel8/Table/Serialize.hs+4−4 src/Rel8/Table/Tag.hs+1−1 src/Rel8/Table/Undefined.hs+4−4 src/Rel8/Type.hs+3−7 src/Rel8/Type/Array.hs+12−12 src/Rel8/Type/Array1D.hs+10−14 src/Rel8/Type/Eq.hs+1−1 src/Rel8/Type/Monoid.hs+2−2 src/Rel8/Type/Ord.hs+1−1 src/Rel8/Type/Semigroup.hs+1−1 tests/Main.hs+1−1
rel8.cabal+1−1
@@ -113,7 +113,7 @@ library
113113 Rel8.Schema.Insert
114114 Rel8.Schema.Kind
115115 Rel8.Schema.Name
116− Rel8.Schema.Nullability
116+ Rel8.Schema.Null
117117 Rel8.Schema.Spec
118118 Rel8.Schema.Spec.ConstrainDBType
119119 Rel8.Schema.Spec.ConstrainType
src/Rel8.hs+5−5
@@ -101,9 +101,9 @@ module Rel8
101101 , nullable
102102 , isNull
103103 , isNonNull
104− , mapNullable
105− , liftOpNullable
106− , catNullable
104+ , mapNull
105+ , liftOpNull
106+ , catNull
107107 , coalesce
108108
109109 -- ** Boolean operations
@@ -226,7 +226,7 @@ module Rel8
226226 -- TODO
227227 -- These need organizing, but are reachable from Rel8's documentation so we
228228 -- do need to export and document them.
229− , HasNullability
229+ , Nullable
230230 , NotNull
231231 , HTable
232232 , Labelable
@@ -272,7 +272,7 @@ import Rel8.Schema.Field (Field)
272272import Rel8.Schema.Generic
273273import Rel8.Schema.HTable
274274import Rel8.Schema.Name
275−import Rel8.Schema.Nullability
275+import Rel8.Schema.Null hiding ( nullable )
276276import Rel8.Schema.Table
277277import Rel8.Statement.Delete
278278import Rel8.Statement.Insert
src/Rel8/Aggregate.hs+1−1
@@ -36,7 +36,7 @@ import Rel8.Schema.Context ( Interpretation(..) )
3636import Rel8.Schema.Context.Label ( Labelable(..) )
3737import Rel8.Schema.HTable ( hfield, htabulate, htabulateA, hspecs )
3838import Rel8.Schema.Name ( Name )
39−import Rel8.Schema.Nullability ( Sql )
39+import Rel8.Schema.Null ( Sql )
4040import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
4141import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
4242import Rel8.Table.Recontextualize ( Recontextualize )
src/Rel8/Expr.hs+11−14
@@ -27,7 +27,7 @@ import Prelude hiding ( null )
2727import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2828
2929-- rel8
30−import Rel8.Expr.Null ( liftOpNullable, nullify )
30+import Rel8.Expr.Null ( liftOpNull, nullify )
3131import Rel8.Expr.Opaleye
3232 ( castExpr
3333 , fromPrimExpr
@@ -38,10 +38,7 @@ import Rel8.Expr.Serialize ( litExpr )
3838import Rel8.Schema.Context ( Interpretation, Col )
3939import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
4040import Rel8.Schema.HTable.Type ( HType( HType ) )
41−import Rel8.Schema.Nullability
42− ( Nullability( Nullable, NonNullable )
43− , Sql, nullabilization
44− )
41+import Rel8.Schema.Null ( Nullity( Null, NotNull ), Sql, nullable )
4542import Rel8.Schema.Spec ( Spec( Spec ) )
4643import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
4744import Rel8.Table.Recontextualize ( Recontextualize )
@@ -59,23 +56,23 @@ newtype Expr a = Expr Opaleye.PrimExpr
5956
6057
6158instance Sql DBSemigroup a => Semigroup (Expr a) where
62− (<>) = case nullabilization @a of
63− Nullable -> liftOpNullable (<>.)
64− NonNullable -> (<>.)
59+ (<>) = case nullable @a of
60+ Null -> liftOpNull (<>.)
61+ NotNull -> (<>.)
6562 {-# INLINABLE (<>) #-}
6663
6764
6865instance Sql DBMonoid a => Monoid (Expr a) where
69− mempty = case nullabilization @a of
70− Nullable -> nullify memptyExpr
71− NonNullable -> memptyExpr
66+ mempty = case nullable @a of
67+ Null -> nullify memptyExpr
68+ NotNull -> memptyExpr
7269 {-# INLINABLE mempty #-}
7370
7471
7572instance (Sql IsString a, Sql DBType a) => IsString (Expr a) where
76− fromString = litExpr . case nullabilization @a of
77− Nullable -> Just . fromString
78− NonNullable -> fromString
73+ fromString = litExpr . case nullable @a of
74+ Null -> Just . fromString
75+ NotNull -> fromString
7976
8077
8178instance Sql DBNum a => Num (Expr a) where
src/Rel8/Expr/Aggregate.hs+1−1
@@ -36,7 +36,7 @@ import Rel8.Expr.Opaleye
3636 )
3737import Rel8.Expr.Null ( null )
3838import Rel8.Expr.Serialize ( litExpr )
39−import Rel8.Schema.Nullability ( Sql )
39+import Rel8.Schema.Null ( Sql )
4040import Rel8.Type.Array ( fromPrimArray )
4141import Rel8.Type.Eq ( DBEq )
4242import Rel8.Type.Num ( DBNum )
src/Rel8/Expr/Array.hs+2−2
@@ -27,7 +27,7 @@ import Rel8.Expr.Opaleye
2727import Rel8.Type ( DBType, typeInformation )
2828import Rel8.Type.Array ( array, zipPrimArraysWith )
2929import Rel8.Type.Information ( TypeInformation(..) )
30−import Rel8.Schema.Nullability ( Unnullify, Nullability, Sql )
30+import Rel8.Schema.Null ( Unnullify, Nullity, Sql )
3131
3232
3333sappend :: Expr [a] -> Expr [a] -> Expr [a]
@@ -38,7 +38,7 @@ sappend1 :: Expr (NonEmpty a) -> Expr (NonEmpty a) -> Expr (NonEmpty a)
3838sappend1 = zipPrimExprsWith (zipPrimArraysWith (Opaleye.BinExpr (Opaleye.:||)))
3939
4040
41−sempty :: Nullability a -> TypeInformation (Unnullify a) -> Expr [a]
41+sempty :: Nullity a -> TypeInformation (Unnullify a) -> Expr [a]
4242sempty _ info = fromPrimExpr $ array info []
4343
4444
src/Rel8/Expr/Eq.hs+15−16
@@ -24,12 +24,9 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2424-- rel8
2525import Rel8.Expr ( Expr )
2626import Rel8.Expr.Bool ( (&&.), (||.), false, or_, coalesce )
27−import Rel8.Expr.Null ( isNull, unsafeLiftOpNullable )
27+import Rel8.Expr.Null ( isNull, unsafeLiftOpNull )
2828import Rel8.Expr.Opaleye ( fromPrimExpr, toPrimExpr, zipPrimExprsWith )
29−import Rel8.Schema.Nullability
30− ( Nullability( NonNullable, Nullable )
31− , Sql, nullabilization
32− )
29+import Rel8.Schema.Null ( Nullity( NotNull, Null ), Sql, nullable )
3330import Rel8.Type.Eq ( DBEq )
3431
3532
@@ -48,10 +45,11 @@ ne = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:<>))
4845-- This operator matches Haskell's '==' operator. For an operator identical to
4946-- SQL @=@, see '==?'.
5047(==.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool
51−(==.) = case nullabilization @a of
52− Nullable -> \ma mb -> isNull ma &&. isNull mb ||. ma ==? mb
53− NonNullable -> eq
48+(==.) = case nullable @a of
49+ Null -> \ma mb -> isNull ma &&. isNull mb ||. ma ==? mb
50+ NotNull -> eq
5451infix 4 ==.
52+{-# INLINABLE (==.) #-}
5553
5654
5755-- | Test if two expressions are different (not equal).
@@ -61,10 +59,11 @@ infix 4 ==.
6159-- which would return @null@. This operator is closer to Haskell's '=='
6260-- operator. For an operator identical to SQL @=@, see '/=?'.
6361(/=.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool
64−(/=.) = case nullabilization @a of
65− Nullable -> \ma mb -> isNull ma `ne` isNull mb ||. ma /=? mb
66− NonNullable -> ne
62+(/=.) = case nullable @a of
63+ Null -> \ma mb -> isNull ma `ne` isNull mb ||. ma /=? mb
64+ NotNull -> ne
6765infix 4 /=.
66+{-# INLINABLE (/=.) #-}
6867
6968
7069-- | Test if two expressions are equal. This operator is usually the best
@@ -74,7 +73,7 @@ infix 4 /=.
7473-- This corresponds to the SQL @=@ operator, though it will always return a
7574-- 'Bool'.
7675(==?) :: DBEq a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
77−a ==? b = coalesce $ unsafeLiftOpNullable eq a b
76+a ==? b = coalesce $ unsafeLiftOpNull eq a b
7877infix 4 ==?
7978
8079
@@ -83,7 +82,7 @@ infix 4 ==?
8382-- This corresponds to the SQL @<>@ operator, though it will always return a
8483-- 'Bool'.
8584(/=?) :: DBEq a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
86−a /=? b = coalesce $ unsafeLiftOpNullable ne a b
85+a /=? b = coalesce $ unsafeLiftOpNull ne a b
8786infix 4 /=?
8887
8988
@@ -91,9 +90,9 @@ infix 4 /=?
9190-- '==.' and '||.'.
9291in_ :: forall a f. (Sql DBEq a, Foldable f)
9392 => Expr a -> f (Expr a) -> Expr Bool
94−in_ a (toList -> as) = case nullabilization @a of
95− Nullable -> or_ $ map (a ==.) as
96− NonNullable -> case nonEmpty as of
93+in_ a (toList -> as) = case nullable @a of
94+ Null -> or_ $ map (a ==.) as
95+ NotNull -> case nonEmpty as of
9796 Nothing -> false
9897 Just xs ->
9998 fromPrimExpr $
src/Rel8/Expr/Function.hs+1−1
@@ -25,7 +25,7 @@ import Rel8.Expr.Opaleye
2525 ( castExpr
2626 , fromPrimExpr, toPrimExpr, zipPrimExprsWith
2727 )
28−import Rel8.Schema.Nullability ( Sql )
28+import Rel8.Schema.Null ( Sql )
2929import Rel8.Type ( DBType )
3030
3131
src/Rel8/Expr/Null.hs+14−14
@@ -8,8 +8,8 @@ module Rel8.Expr.Null
88 ( null, snull, nullable, nullableOf
99 , isNull, isNonNull
1010 , nullify, unsafeUnnullify
11− , mapNullable, liftOpNullable
12− , unsafeMapNullable, unsafeLiftOpNullable
11+ , mapNull, liftOpNull
12+ , unsafeMapNull, unsafeLiftOpNull
1313 )
1414where
1515
@@ -23,7 +23,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2323import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
2424import Rel8.Expr.Bool ( (||.), boolExpr )
2525import Rel8.Expr.Opaleye ( scastExpr, mapPrimExpr )
26−import Rel8.Schema.Nullability ( NotNull )
26+import Rel8.Schema.Null ( NotNull )
2727import Rel8.Type ( DBType, typeInformation )
2828import Rel8.Type.Information ( TypeInformation )
2929
@@ -59,24 +59,24 @@ isNonNull = mapPrimExpr (Opaleye.UnExpr Opaleye.OpIsNotNull)
5959
6060
6161-- | Lift an operation on non-@null@ values to an operation on possibly @null@
62−-- values. When given @null@, @mapNullable f@ returns @null@.
62+-- values. When given @null@, @mapNull f@ returns @null@.
6363--
6464-- This is like 'fmap' for 'Maybe'.
65−mapNullable :: DBType b
65+mapNull :: DBType b
6666 => (Expr a -> Expr b) -> Expr (Maybe a) -> Expr (Maybe b)
67−mapNullable f ma = boolExpr (unsafeMapNullable f ma) null (isNull ma)
67+mapNull f ma = boolExpr (unsafeMapNull f ma) null (isNull ma)
6868
6969
7070-- | Lift a binary operation on non-@null@ expressions to an equivalent binary
7171-- operator on possibly @null@ expressions. If either of the final arguments
72−-- are @null@, @liftOpNullable@ returns @null@.
72+-- are @null@, @liftOpNull@ returns @null@.
7373--
7474-- This is like 'liftA2' for 'Maybe'.
75−liftOpNullable :: DBType c
75+liftOpNull :: DBType c
7676 => (Expr a -> Expr b -> Expr c)
7777 -> Expr (Maybe a) -> Expr (Maybe b) -> Expr (Maybe c)
78−liftOpNullable f ma mb =
79− boolExpr (unsafeLiftOpNullable f ma mb) null
78+liftOpNull f ma mb =
79+ boolExpr (unsafeLiftOpNull f ma mb) null
8080 (isNull ma ||. isNull mb)
8181
8282
@@ -89,13 +89,13 @@ null :: DBType a => Expr (Maybe a)
8989null = snull typeInformation
9090
9191
92−unsafeMapNullable :: NotNull b
92+unsafeMapNull :: NotNull b
9393 => (Expr a -> Expr b) -> Expr (Maybe a) -> Expr (Maybe b)
94−unsafeMapNullable f ma = nullify (f (unsafeUnnullify ma))
94+unsafeMapNull f ma = nullify (f (unsafeUnnullify ma))
9595
9696
97−unsafeLiftOpNullable :: NotNull c
97+unsafeLiftOpNull :: NotNull c
9898 => (Expr a -> Expr b -> Expr c)
9999 -> Expr (Maybe a) -> Expr (Maybe b) -> Expr (Maybe c)
100−unsafeLiftOpNullable f ma mb =
100+unsafeLiftOpNull f ma mb =
101101 nullify (f (unsafeUnnullify ma) (unsafeUnnullify mb))
src/Rel8/Expr/Num.hs+1−1
@@ -15,7 +15,7 @@ import Prelude ()
1515import Rel8.Expr ( Expr( Expr ) )
1616import Rel8.Expr.Function ( function )
1717import Rel8.Expr.Opaleye ( castExpr )
18−import Rel8.Schema.Nullability ( Homonullable, Sql )
18+import Rel8.Schema.Null ( Homonullable, Sql )
1919import Rel8.Type.Num ( DBFractional, DBIntegral, DBNum )
2020
2121
src/Rel8/Expr/Opaleye.hs+1−1
@@ -23,7 +23,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2323
2424-- rel8
2525import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
26−import Rel8.Schema.Nullability ( Unnullify, Sql )
26+import Rel8.Schema.Null ( Unnullify, Sql )
2727import Rel8.Type ( DBType, typeInformation )
2828import Rel8.Type.Information ( TypeInformation(..) )
2929
src/Rel8/Expr/Ord.hs+25−27
@@ -22,12 +22,10 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2222-- rel8
2323import Rel8.Expr ( Expr( Expr ) )
2424import Rel8.Expr.Bool ( (&&.), (||.), coalesce )
25−import Rel8.Expr.Null ( isNull, isNonNull, nullable, unsafeLiftOpNullable )
25+import Rel8.Expr.Null ( isNull, isNonNull, nullable, unsafeLiftOpNull )
2626import Rel8.Expr.Opaleye ( zipPrimExprsWith )
27−import Rel8.Schema.Nullability
28− ( Nullability( NonNullable, Nullable )
29− , Sql, nullabilization
30− )
27+import Rel8.Schema.Null ( Nullity( Null, NotNull ), Sql )
28+import qualified Rel8.Schema.Null as Schema ( nullable )
3129import Rel8.Type.Ord ( DBOrd )
3230
3331
@@ -51,9 +49,9 @@ ge = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:>=))
5149-- as @null@ will sort below any other value. For a version of @<@ that exactly
5250-- matches SQL, see '(<?)'.
5351(<.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
54−(<.) = case nullabilization @a of
55− Nullable -> \ma mb -> isNull ma &&. isNonNull mb ||. ma <? mb
56− NonNullable -> lt
52+(<.) = case Schema.nullable @a of
53+ Null -> \ma mb -> isNull ma &&. isNonNull mb ||. ma <? mb
54+ NotNull -> lt
5755infix 4 <.
5856
5957
@@ -61,9 +59,9 @@ infix 4 <.
6159-- as @null@ will sort below any other value. For a version of @<=@ that exactly
6260-- matches SQL, see '(<=?)'.
6361(<=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
64−(<=.) = case nullabilization @a of
65− Nullable -> \ma mb -> isNull ma ||. ma <=? mb
66− NonNullable -> le
62+(<=.) = case Schema.nullable @a of
63+ Null -> \ma mb -> isNull ma ||. ma <=? mb
64+ NotNull -> le
6765infix 4 <=.
6866
6967
@@ -71,9 +69,9 @@ infix 4 <=.
7169-- as @null@ will sort below any other value. For a version of @>@ that exactly
7270-- matches SQL, see '(>?)'.
7371(>.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
74−(>.) = case nullabilization @a of
75− Nullable -> \ma mb -> isNonNull ma &&. isNull mb ||. ma >? mb
76− NonNullable -> gt
72+(>.) = case Schema.nullable @a of
73+ Null -> \ma mb -> isNonNull ma &&. isNull mb ||. ma >? mb
74+ NotNull -> gt
7775infix 4 >.
7876
7977
@@ -81,37 +79,37 @@ infix 4 >.
8179-- as @null@ will sort below any other value. For a version of @>=@ that
8280-- exactly matches SQL, see '(>=?)'.
8381(>=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
84−(>=.) = case nullabilization @a of
85− Nullable -> \ma mb -> isNull mb ||. ma >=? mb
86− NonNullable -> ge
82+(>=.) = case Schema.nullable @a of
83+ Null -> \ma mb -> isNull mb ||. ma >=? mb
84+ NotNull -> ge
8785infix 4 >=.
8886
8987
9088-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
9189-- are @null@.
9290(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
93−a <? b = coalesce $ unsafeLiftOpNullable lt a b
91+a <? b = coalesce $ unsafeLiftOpNull lt a b
9492infix 4 <?
9593
9694
9795-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
9896-- are @null@.
9997(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
100−a <=? b = coalesce $ unsafeLiftOpNullable le a b
98+a <=? b = coalesce $ unsafeLiftOpNull le a b
10199infix 4 <=?
102100
103101
104102-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
105103-- are @null@.
106104(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
107−a >? b = coalesce $ unsafeLiftOpNullable gt a b
105+a >? b = coalesce $ unsafeLiftOpNull gt a b
108106infix 4 >?
109107
110108
111109-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
112110-- are @null@.
113111(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
114−a >=? b = coalesce $ unsafeLiftOpNullable ge a b
112+a >=? b = coalesce $ unsafeLiftOpNull ge a b
115113infix 4 >=?
116114
117115
@@ -120,9 +118,9 @@ infix 4 >=?
120118--
121119-- Corresponds to the SQL @least()@ function.
122120leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
123−leastExpr ma mb = case nullabilization @a of
124− Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
125− NonNullable -> least_ ma mb
121+leastExpr ma mb = case Schema.nullable @a of
122+ Null -> nullable ma (\a -> nullable mb (least_ a) mb) ma
123+ NotNull -> least_ ma mb
126124 where
127125 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
128126
@@ -132,8 +130,8 @@ leastExpr ma mb = case nullabilization @a of
132130--
133131-- Corresponds to the SQL @greatest()@ function.
134132greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
135−greatestExpr ma mb = case nullabilization @a of
136− Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
137− NonNullable -> greatest_ ma mb
133+greatestExpr ma mb = case Schema.nullable @a of
134+ Null -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
135+ NotNull -> greatest_ ma mb
138136 where
139137 greatest_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "GREATEST" [a, b])
src/Rel8/Expr/Serialize.hs+11−15
@@ -21,11 +21,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2121-- rel8
2222import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
2323import Rel8.Expr.Opaleye ( scastExpr )
24−import Rel8.Schema.Nullability
25− ( Unnullify
26− , Nullability( Nullable, NonNullable )
27− , Sql, nullabilization
28− )
24+import Rel8.Schema.Null ( Unnullify, Nullity( Null, NotNull ), Sql, nullable )
2925import Rel8.Type ( DBType, typeInformation )
3026import Rel8.Type.Information ( TypeInformation(..) )
3127
@@ -35,19 +31,19 @@ import Rel8.Type.Information ( TypeInformation(..) )
3531-- Note that you can usually use 'Rel8.lit', but @litExpr@ can solve problems
3632-- of inference in polymorphic code.
3733litExpr :: Sql DBType a => a -> Expr a
38−litExpr = slitExpr nullabilization typeInformation
34+litExpr = slitExpr nullable typeInformation
3935
4036
41−slitExpr :: Nullability a -> TypeInformation (Unnullify a) -> a -> Expr a
42−slitExpr nullability info@TypeInformation {encode} =
37+slitExpr :: Nullity a -> TypeInformation (Unnullify a) -> a -> Expr a
38+slitExpr nullity info@TypeInformation {encode} =
4339 scastExpr info . Expr . encoder
4440 where
45− encoder = case nullability of
46− Nullable -> maybe (Opaleye.ConstExpr Opaleye.NullLit) encode
47− NonNullable -> encode
41+ encoder = case nullity of
42+ Null -> maybe (Opaleye.ConstExpr Opaleye.NullLit) encode
43+ NotNull -> encode
4844
4945
50−sparseValue :: Nullability a -> TypeInformation (Unnullify a) -> Hasql.Row a
51−sparseValue nullability TypeInformation {decode} = case nullability of
52− Nullable -> Hasql.column $ Hasql.nullable decode
53− NonNullable -> Hasql.column $ Hasql.nonNullable decode
46+sparseValue :: Nullity a -> TypeInformation (Unnullify a) -> Hasql.Row a
47+sparseValue nullity TypeInformation {decode} = case nullity of
48+ Null -> Hasql.column $ Hasql.nullable decode
49+ NotNull -> Hasql.column $ Hasql.nonNullable decode
src/Rel8/Query/Null.hs+3−3
@@ -1,5 +1,5 @@
11module Rel8.Query.Null
2− ( catNullable
2+ ( catNull
33 )
44where
55
@@ -17,7 +17,7 @@ import Rel8.Query.Filter ( where_ )
1717-- @null@s.
1818--
1919-- Corresponds to 'Data.Maybe.catMaybes'.
20−catNullable :: Expr (Maybe a) -> Query (Expr a)
21−catNullable a = do
20+catNull :: Expr (Maybe a) -> Query (Expr a)
21+catNull a = do
2222 where_ $ isNonNull a
2323 pure $ unsafeUnnullify a
src/Rel8/Schema/Context/Identity.hs+8−11
@@ -29,10 +29,7 @@ import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
2929import Rel8.Schema.HTable.Nullify ( hnulls, hnullify, hunnullify )
3030import Rel8.Schema.HTable.These ( HTheseTable(..) )
3131import Rel8.Schema.HTable.Vectorize ( hvectorize, hunvectorize )
32−import Rel8.Schema.Nullability
33− ( Nullify
34− , Nullability( Nullable, NonNullable )
35− )
32+import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ) )
3633import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
3734import Rel8.Type.Tag ( EitherTag( IsLeft, IsRight ), MaybeTag( IsJust ) )
3835
@@ -164,19 +161,19 @@ nullifier :: ()
164161 => SSpec ('Spec labels necessity a)
165162 -> Col Identity ('Spec labels necessity a)
166163 -> Col Identity ('Spec labels necessity (Nullify a))
167−nullifier SSpec {nullability} (Result a) = Result $ case nullability of
168− Nullable -> a
169− NonNullable -> Just a
164+nullifier SSpec {nullity} (Result a) = Result $ case nullity of
165+ Null -> a
166+ NotNull -> Just a
170167
171168
172169unnullifier :: ()
173170 => SSpec ('Spec labels necessity a)
174171 -> Col Identity ('Spec labels necessity (Nullify a))
175172 -> Maybe (Col Identity ('Spec labels necessity a))
176−unnullifier SSpec {nullability} (Result a) =
177− case nullability of
178− Nullable -> pure $ Result a
179− NonNullable -> Result <$> a
173+unnullifier SSpec {nullity} (Result a) =
174+ case nullity of
175+ Null -> pure $ Result a
176+ NotNull -> Result <$> a
180177
181178
182179vectorizer :: Functor f
src/Rel8/Schema/Context/Nullify.hs+27−31
@@ -37,16 +37,12 @@ import Rel8.Kind.Necessity ( Necessity( Required ) )
3737import Rel8.Schema.Context ( Interpretation )
3838import qualified Rel8.Schema.Kind as K
3939import Rel8.Schema.Name ( Name( Name ), Col(..) )
40−import Rel8.Schema.Nullability
41− ( Nullify
42− , Nullability( Nullable, NonNullable )
43− , Sql
44− )
40+import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ), Sql )
4541import Rel8.Schema.Dict ( Dict( Dict ) )
4642import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
4743import Rel8.Schema.Spec.ConstrainDBType
4844 ( ConstrainDBType
49− , dbTypeDict, dbTypeNullability, fromNullabilityDict
45+ , dbTypeDict, dbTypeNullity, fromNullityDict
5046 )
5147import Rel8.Table.Tag ( Tag(..), Taggable, fromAggregate, fromExpr, fromName )
5248
@@ -91,15 +87,15 @@ instance Nullifiable Aggregate where
9187
9288 decodeTag (Aggregation aggregate) = fromAggregate aggregate
9389
94− nullifier Tag {expr} test SSpec {nullability} (Aggregation aggregate) =
90+ nullifier Tag {expr} test SSpec {nullity} (Aggregation aggregate) =
9591 Aggregation $
96− mapInputs (toPrimExpr . runTag nullability condition . fromPrimExpr) $
97− runTag nullability condition <$> aggregate
92+ mapInputs (toPrimExpr . runTag nullity condition . fromPrimExpr) $
93+ runTag nullity condition <$> aggregate
9894 where
9995 condition = test expr
10096
101− unnullifier SSpec {nullability} (Aggregation aggregate) =
102− Aggregation $ unnull nullability <$> aggregate
97+ unnullifier SSpec {nullity} (Aggregation aggregate) =
98+ Aggregation $ unnull nullity <$> aggregate
10399
104100 {-# INLINABLE encodeTag #-}
105101 {-# INLINABLE decodeTag #-}
@@ -110,9 +106,9 @@ instance Nullifiable Aggregate where
110106instance Nullifiable Expr where
111107 encodeTag Tag {expr} = DB expr
112108 decodeTag (DB a) = fromExpr a
113− nullifier Tag {expr} test SSpec {nullability} (DB a) =
114− DB $ runTag nullability (test expr) a
115− unnullifier SSpec {nullability} (DB a) = DB $ unnull nullability a
109+ nullifier Tag {expr} test SSpec {nullity} (DB a) =
110+ DB $ runTag nullity (test expr) a
111+ unnullifier SSpec {nullity} (DB a) = DB $ unnull nullity a
116112
117113 {-# INLINABLE encodeTag #-}
118114 {-# INLINABLE decodeTag #-}
@@ -132,18 +128,18 @@ instance Nullifiable Name where
132128 {-# INLINABLE unnullifier #-}
133129
134130
135−runTag :: Nullability a -> Expr Bool -> Expr a -> Expr (Nullify a)
136−runTag nullability tag a = case nullability of
137− Nullable -> boolExpr null a tag
138− NonNullable -> boolExpr null (nullify a) tag
131+runTag :: Nullity a -> Expr Bool -> Expr a -> Expr (Nullify a)
132+runTag nullity tag a = case nullity of
133+ Null -> boolExpr null a tag
134+ NotNull -> boolExpr null (nullify a) tag
139135 where
140136 null = fromPrimExpr $ Opaleye.ConstExpr Opaleye.NullLit
141137
142138
143−unnull :: Nullability a -> Expr (Nullify a) -> Expr a
144−unnull nullability a = case nullability of
145− Nullable -> a
146− NonNullable -> unsafeUnnullify a
139+unnull :: Nullity a -> Expr (Nullify a) -> Expr a
140+unnull nullity a = case nullity of
141+ Null -> a
142+ NotNull -> unsafeUnnullify a
147143
148144
149145type HNullifiable :: K.HContext -> Constraint
@@ -187,15 +183,15 @@ instance HNullifiable (Dict (ConstrainDBType constraint)) where
187183 hdecodeTag = mempty
188184
189185 hnullifier _ _ SSpec {} dict = case dbTypeDict dict of
190− Dict -> case dbTypeNullability dict of
191− Nullable -> Dict
192− NonNullable -> Dict
193−
194− hunnullifier SSpec {nullability} dict = case dbTypeDict dict of
195− Dict -> case nullability of
196− Nullable -> Dict
197− NonNullable -> case dbTypeNullability dict of
198− Nullable -> fromNullabilityDict nullability Dict
186+ Dict -> case dbTypeNullity dict of
187+ Null -> Dict
188+ NotNull -> Dict
189+
190+ hunnullifier SSpec {nullity} dict = case dbTypeDict dict of
191+ Dict -> case nullity of
192+ Null -> Dict
193+ NotNull -> case dbTypeNullity dict of
194+ Null -> fromNullityDict nullity Dict
199195
200196
201197type DefaultConstrainTag :: Type -> Constraint
src/Rel8/Schema/HTable/Nullify.hs+7−10
@@ -26,13 +26,10 @@ where
2626import Prelude hiding ( null )
2727
2828-- rel8
29−import Rel8.Schema.HTable
30− ( HTable
31− , hfield, htabulate, htabulateA, hspecs
32− )
29+import Rel8.Schema.HTable ( HTable, hfield, htabulate, htabulateA, hspecs )
3330import qualified Rel8.Schema.Kind as K
34−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
35−import qualified Rel8.Schema.Nullability as Type ( Nullify )
31+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
32+import qualified Rel8.Schema.Null as Type ( Nullify )
3633import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
3734
3835-- semigroupoids
@@ -59,13 +56,13 @@ type instance Eval (Nullify ('Spec labels necessity a)) =
5956
6057instance MapSpec Nullify where
6158 mapInfo = \case
62− SSpec{labels, necessity, info, nullability} -> SSpec
59+ SSpec{labels, necessity, info, nullity} -> SSpec
6360 { labels
6461 , necessity
6562 , info
66− , nullability = case nullability of
67− Nullable -> Nullable
68− NonNullable -> Nullable
63+ , nullity = case nullity of
64+ Null -> Null
65+ NotNull -> Null
6966 }
7067
7168
src/Rel8/Schema/HTable/Type.hs+2−2
@@ -23,7 +23,7 @@ import Rel8.Schema.HTable
2323 , hfield, htabulate, htraverse, hdicts, hspecs
2424 )
2525import qualified Rel8.Schema.Kind as K
26−import Rel8.Schema.Nullability ( Sql, nullabilization )
26+import Rel8.Schema.Null ( Sql, nullable )
2727import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
2828import Rel8.Type ( DBType, typeInformation )
2929
@@ -51,7 +51,7 @@ instance Sql DBType a => HTable (HType a) where
5151 { labels = SLabel Proxy
5252 , necessity = SRequired
5353 , info = typeInformation
54− , nullability = nullabilization
54+ , nullity = nullable
5555 }
5656
5757 {-# INLINABLE hfield #-}
src/Rel8/Schema/HTable/Vectorize.hs+9−13
@@ -40,11 +40,7 @@ import Rel8.Schema.HTable
4040 ( HTable
4141 , hfield, htabulate, htabulateA, hspecs
4242 )
43−import Rel8.Schema.Nullability
44− ( Unnullify
45− , NotNull
46− , Nullability( NonNullable )
47− )
43+import Rel8.Schema.Null ( Unnullify, NotNull, Nullity( NotNull ) )
4844import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
4945import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
5046import Rel8.Type.Information ( TypeInformation )
@@ -59,7 +55,7 @@ import GHC.Generics (Generic)
5955class Vector list where
6056 listNotNull :: proxy a -> Dict NotNull (list a)
6157 vectorTypeInformation :: ()
62− => Nullability a
58+ => Nullity a
6359 -> TypeInformation (Unnullify a)
6460 -> TypeInformation (list a)
6561
@@ -88,10 +84,10 @@ type instance Eval (Vectorize list ('Spec labels necessity a)) = 'Spec labels ne
8884
8985instance Vector list => MapSpec (Vectorize list) where
9086 mapInfo = \case
91− SSpec {..} -> case listNotNull @list nullability of
87+ SSpec {..} -> case listNotNull @list nullity of
9288 Dict -> SSpec
93− { nullability = NonNullable
94− , info = vectorTypeInformation nullability info
89+ { nullity = NotNull
90+ , info = vectorTypeInformation nullity info
9591 , ..
9692 }
9793
@@ -125,7 +121,7 @@ hunvectorize unvectorizer (HVectorize table) =
125121
126122happend :: (HTable t, Vector list) =>
127123 ( forall labels necessity a. ()
128− => Nullability a
124+ => Nullity a
129125 -> TypeInformation (Unnullify a)
130126 -> context ('Spec labels necessity (list a))
131127 -> context ('Spec labels necessity (list a))
@@ -137,18 +133,18 @@ happend :: (HTable t, Vector list) =>
137133happend append (HVectorize as) (HVectorize bs) = HVectorize $
138134 htabulate $ \field@(HMapTableField j) -> case (hfield as field, hfield bs field) of
139135 (a, b) -> case hfield hspecs j of
140− SSpec {nullability, info} -> append nullability info a b
136+ SSpec {nullity, info} -> append nullity info a b
141137
142138
143139hempty :: HTable t =>
144140 ( forall labels necessity a. ()
145− => Nullability a
141+ => Nullity a
146142 -> TypeInformation (Unnullify a)
147143 -> context ('Spec labels necessity [a])
148144 )
149145 -> HVectorize [] t context
150146hempty empty = HVectorize $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
151− SSpec {nullability, info} -> empty nullability info
147+ SSpec {nullity, info} -> empty nullity info
152148
153149
154150instance HLabelable g => HLabelable (Precompose (Vectorize list) g) where
src/Rel8/Schema/Insert.hs+8−8
@@ -38,8 +38,8 @@ import Rel8.Schema.Context.Nullify
3838import Rel8.Schema.HTable.Type ( HType(HType) )
3939import qualified Rel8.Schema.Kind as K
4040import Rel8.Schema.Name ( Name, Selects )
41−import Rel8.Schema.Nullability ( Sql )
42−import Rel8.Schema.Spec ( SSpec(SSpec, nullability), Spec(Spec) )
41+import Rel8.Schema.Null ( Sql )
42+import Rel8.Schema.Spec ( SSpec(SSpec, nullity), Spec(Spec) )
4343import Rel8.Schema.Table ( TableSchema )
4444import Rel8.Statement.Returning ( Returning )
4545import Rel8.Table ( Table(..) )
@@ -135,17 +135,17 @@ instance Nullifiable Insert where
135135 encodeTag = RequiredInsert . expr
136136 decodeTag (RequiredInsert a) = fromExpr a
137137
138− nullifier Tag {expr} test SSpec {nullability} = \case
138+ nullifier Tag {expr} test SSpec {nullity} = \case
139139 RequiredInsert a ->
140− RequiredInsert $ runTag nullability condition a
140+ RequiredInsert $ runTag nullity condition a
141141 OptionalInsert ma ->
142− OptionalInsert $ runTag nullability condition <$> ma
142+ OptionalInsert $ runTag nullity condition <$> ma
143143 where
144144 condition = test expr
145145
146− unnullifier SSpec {nullability} = \case
147− RequiredInsert a -> RequiredInsert $ unnull nullability a
148− OptionalInsert ma -> OptionalInsert $ unnull nullability <$> ma
146+ unnullifier SSpec {nullity} = \case
147+ RequiredInsert a -> RequiredInsert $ unnull nullity a
148+ OptionalInsert ma -> OptionalInsert $ unnull nullity <$> ma
149149
150150 {-# INLINABLE encodeTag #-}
151151 {-# INLINABLE decodeTag #-}
src/Rel8/Schema/Name.hs+1−1
@@ -29,7 +29,7 @@ import Rel8.Schema.Context ( Interpretation, Col )
2929import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
3030import Rel8.Schema.HTable.Type ( HType( HType ) )
3131import qualified Rel8.Schema.Kind as K
32−import Rel8.Schema.Nullability ( Sql )
32+import Rel8.Schema.Null ( Sql )
3333import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
3434import Rel8.Table.Recontextualize ( Recontextualize )
3535import Rel8.Type ( DBType )
src/Rel8/Schema/Nullability.hs → src/Rel8/Schema/Null.hsrenamed+30−30
@@ -10,12 +10,12 @@
1010{-# language UndecidableInstances #-}
1111{-# language UndecidableSuperClasses #-}
1212
13−module Rel8.Schema.Nullability
13+module Rel8.Schema.Null
1414 ( Nullify, Unnullify
1515 , NotNull
1616 , Homonullable
17− , Nullability( Nullable, NonNullable )
18− , HasNullability, nullabilization
17+ , Nullity( Null, NotNull )
18+ , Nullable, nullable
1919 , Sql, fromSql, mapSql, toSql
2020 )
2121where
@@ -56,8 +56,8 @@ type Nullify a = Maybe (Unnullify a)
5656
5757-- | @nullify a@ means @a@ cannot take @null@ as a value.
5858type NotNull :: Type -> Constraint
59−class (HasNullability a, IsMaybe a ~ 'False) => NotNull a
60−instance (HasNullability a, IsMaybe a ~ 'False) => NotNull a
59+class (Nullable a, IsMaybe a ~ 'False) => NotNull a
60+instance (Nullable a, IsMaybe a ~ 'False) => NotNull a
6161
6262
6363-- | @Homonullable a b@ means that both @a@ and @b@ can be @null@, or neither
@@ -67,39 +67,39 @@ class IsMaybe a ~ IsMaybe b => Homonullable a b
6767instance IsMaybe a ~ IsMaybe b => Homonullable a b
6868
6969
70−type Nullability :: Type -> Type
71−data Nullability a where
72− NonNullable :: NotNull a => Nullability a
73− Nullable :: NotNull a => Nullability (Maybe a)
70+type Nullity :: Type -> Type
71+data Nullity a where
72+ NotNull :: NotNull a => Nullity a
73+ Null :: NotNull a => Nullity (Maybe a)
7474
7575
76−type HasNullability' :: Bool -> Type -> Constraint
76+type Nullable' :: Bool -> Type -> Constraint
7777class
7878 ( IsMaybe a ~ isMaybe
7979 , IsMaybe (Unnullify a) ~ 'False
8080 , Nullify' isMaybe (Unnullify a) ~ a
81− ) => HasNullability' isMaybe a
81+ ) => Nullable' isMaybe a
8282 where
83− nullabilization' :: Nullability a
83+ nullable' :: Nullity a
8484
8585
86−instance IsMaybe a ~ 'False => HasNullability' 'False a where
87− nullabilization' = NonNullable
86+instance IsMaybe a ~ 'False => Nullable' 'False a where
87+ nullable' = NotNull
8888
8989
90−instance IsMaybe a ~ 'False => HasNullability' 'True (Maybe a) where
91− nullabilization' = Nullable
90+instance IsMaybe a ~ 'False => Nullable' 'True (Maybe a) where
91+ nullable' = Null
9292
9393
94−-- | @HasNullability a@ means that @rel8@ is able to check if the type @a@ is a
94+-- | @Nullable a@ means that @rel8@ is able to check if the type @a@ is a
9595-- type that can take @null@ values or not.
96−type HasNullability :: Type -> Constraint
97−class HasNullability' (IsMaybe a) a => HasNullability a
98−instance HasNullability' (IsMaybe a) a => HasNullability a
96+type Nullable :: Type -> Constraint
97+class Nullable' (IsMaybe a) a => Nullable a
98+instance Nullable' (IsMaybe a) a => Nullable a
9999
100100
101−nullabilization :: HasNullability a => Nullability a
102−nullabilization = nullabilization'
101+nullable :: Nullable a => Nullity a
102+nullable = nullable'
103103
104104
105105-- | The @Sql@ type class describes both null and not null database values,
@@ -109,12 +109,12 @@ nullabilization = nullabilization'
109109-- supports equality, and @a@ can either be exactly an @a@, or it could also be
110110-- @Maybe a@.
111111type Sql :: (Type -> Constraint) -> Type -> Constraint
112−class (constraint (Unnullify a), HasNullability a) => Sql constraint a
113−instance (constraint (Unnullify a), HasNullability a) => Sql constraint a
112+class (constraint (Unnullify a), Nullable a) => Sql constraint a
113+instance (constraint (Unnullify a), Nullable a) => Sql constraint a
114114
115115
116−fromSql :: Dict (Sql constraint) a -> (Nullability a, Dict constraint (Unnullify a))
117−fromSql Dict = (nullabilization, Dict)
116+fromSql :: Dict (Sql constraint) a -> (Nullity a, Dict constraint (Unnullify a))
117+fromSql Dict = (nullable, Dict)
118118{-# INLINABLE fromSql #-}
119119
120120
@@ -122,10 +122,10 @@ mapSql :: ()
122122 => (forall x. Dict constraint x -> Dict constraint' x)
123123 -> Dict (Sql constraint) a -> Dict (Sql constraint') a
124124mapSql f dict = case fromSql dict of
125− (nullability, dict') -> toSql nullability (f dict')
125+ (nullity, dict') -> toSql nullity (f dict')
126126
127127
128−toSql :: Nullability a -> Dict constraint (Unnullify a) -> Dict (Sql constraint) a
129−toSql NonNullable Dict = Dict
130−toSql Nullable Dict = Dict
128+toSql :: Nullity a -> Dict constraint (Unnullify a) -> Dict (Sql constraint) a
129+toSql NotNull Dict = Dict
130+toSql Null Dict = Dict
131131{-# INLINABLE toSql #-}
src/Rel8/Schema/Spec.hs+4−4
@@ -6,7 +6,7 @@
66
77module Rel8.Schema.Spec
88 ( Spec( Spec )
9− , SSpec( SSpec, labels, necessity, info, nullability )
9+ , SSpec( SSpec, labels, necessity, info, nullity )
1010 , KnownSpec( specSing )
1111 , KContext, HKTable
1212 , KTable
@@ -24,7 +24,7 @@ import Rel8.Kind.Necessity
2424 , SNecessity
2525 , KnownNecessity, necessitySing
2626 )
27−import Rel8.Schema.Nullability ( Nullability, Sql, Unnullify, nullabilization )
27+import Rel8.Schema.Null ( Nullity, Sql, Unnullify, nullable )
2828import Rel8.Type ( DBType, typeInformation )
2929import Rel8.Type.Information ( TypeInformation )
3030
@@ -39,7 +39,7 @@ data SSpec spec where
3939 { labels :: SLabels labels
4040 , necessity :: SNecessity necessity
4141 , info :: TypeInformation (Unnullify a)
42− , nullability :: Nullability a
42+ , nullity :: Nullity a
4343 }
4444 -> SSpec ('Spec labels necessity a)
4545
@@ -60,7 +60,7 @@ instance
6060 { labels = labelsSing
6161 , necessity = necessitySing
6262 , info = typeInformation
63− , nullability = nullabilization
63+ , nullity = nullable
6464 }
6565
6666
src/Rel8/Schema/Spec/ConstrainDBType.hs+9−13
@@ -9,9 +9,9 @@
99
1010module Rel8.Schema.Spec.ConstrainDBType
1111 ( ConstrainDBType
12− , dbTypeNullability
12+ , dbTypeNullity
1313 , dbTypeDict
14− , fromNullabilityDict
14+ , fromNullityDict
1515 )
1616where
1717
@@ -21,11 +21,7 @@ import Prelude
2121
2222-- rel8
2323import Rel8.Schema.Dict ( Dict( Dict ) )
24−import Rel8.Schema.Nullability
25− ( Unnullify
26− , Nullability
27− , Sql, nullabilization, toSql
28− )
24+import Rel8.Schema.Null ( Unnullify, Nullity, Sql, nullable, toSql )
2925import Rel8.Schema.Spec ( Spec( Spec ) )
3026
3127
@@ -43,14 +39,14 @@ instance
4339 => ConstrainDBType constraint spec
4440
4541
46−dbTypeNullability :: Dict (ConstrainDBType c) ('Spec l n a) -> Nullability a
47−dbTypeNullability = step2 . step1
42+dbTypeNullity :: Dict (ConstrainDBType c) ('Spec l n a) -> Nullity a
43+dbTypeNullity = step2 . step1
4844 where
4945 step1 :: Dict (ConstrainDBType c) ('Spec l n a) -> Dict (Sql c) a
5046 step1 Dict = Dict
5147
52− step2 :: Dict (Sql c) a -> Nullability a
53− step2 Dict = nullabilization
48+ step2 :: Dict (Sql c) a -> Nullity a
49+ step2 Dict = nullable
5450
5551
5652dbTypeDict :: Dict (ConstrainDBType c) ('Spec l n a) -> Dict c (Unnullify a)
@@ -63,8 +59,8 @@ dbTypeDict = step2 . step1
6359 step2 Dict = Dict
6460
6561
66−fromNullabilityDict :: Nullability a -> Dict c (Unnullify a) -> Dict (ConstrainDBType c) ('Spec l n a)
67−fromNullabilityDict nullability = step2 . toSql nullability
62+fromNullityDict :: Nullity a -> Dict c (Unnullify a) -> Dict (ConstrainDBType c) ('Spec l n a)
63+fromNullityDict nullity = step2 . toSql nullity
6864 where
6965 step2 :: Dict (Sql c) a -> Dict (ConstrainDBType c) ('Spec l n a)
7066 step2 Dict = Dict
src/Rel8/Table.hs+1−1
@@ -31,7 +31,7 @@ import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
3131import Rel8.Schema.HTable.Trio ( HTrio(..) )
3232import Rel8.Schema.HTable.Type ( HType( HType ) )
3333import qualified Rel8.Schema.Kind as K
34−import Rel8.Schema.Nullability ( Sql )
34+import Rel8.Schema.Null ( Sql )
3535import Rel8.Schema.Spec ( KnownSpec )
3636import Rel8.Type ( DBType )
3737
src/Rel8/Table/Eq.hs+1−1
@@ -40,10 +40,10 @@ import Rel8.Schema.HTable.Pair ( HPair(..) )
4040import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
4141import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
4242import Rel8.Schema.HTable.Trio ( HTrio(..) )
43+import Rel8.Schema.Null ( Sql )
4344import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
4445import Rel8.Table ( Table, Columns, toColumns )
4546import Rel8.Type.Eq ( DBEq )
46−import Rel8.Schema.Nullability ( Sql )
4747
4848
4949-- | The class of 'Table's that can be compared for equality. Equality on
src/Rel8/Table/List.hs+8−8
@@ -25,9 +25,9 @@ import Rel8.Expr.Array ( sappend, sempty, slistOf )
2525import Rel8.Schema.Dict ( Dict( Dict ) )
2626import Rel8.Schema.HTable.List ( HListTable )
2727import Rel8.Schema.HTable.Vectorize ( happend, hempty, hvectorize )
28−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
28+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
2929import Rel8.Schema.Spec ( SSpec(..) )
30−import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
30+import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullity )
3131import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
3232import Rel8.Table.Alternative
3333 ( AltTable, (<|>:)
@@ -60,9 +60,9 @@ instance EqTable a => EqTable (ListTable a) where
6060 eqTable =
6161 hvectorize
6262 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
63− Dict -> case dbTypeNullability dict of
64− Nullable -> Dict
65− NonNullable -> Dict)
63+ Dict -> case dbTypeNullity dict of
64+ Null -> Dict
65+ NotNull -> Dict)
6666 (Identity (eqTable @a))
6767
6868
@@ -70,9 +70,9 @@ instance OrdTable a => OrdTable (ListTable a) where
7070 ordTable =
7171 hvectorize
7272 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
73− Dict -> case dbTypeNullability dict of
74− Nullable -> Dict
75− NonNullable -> Dict)
73+ Dict -> case dbTypeNullity dict of
74+ Null -> Dict
75+ NotNull -> Dict)
7676 (Identity (ordTable @a))
7777
7878
src/Rel8/Table/Maybe.hs+4−8
@@ -43,11 +43,7 @@ import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
4343import Rel8.Schema.HTable.Maybe ( HMaybeTable(..), HMaybeNullifiable )
4444import Rel8.Schema.HTable.Nullify ( hnullify, hunnullify )
4545import Rel8.Schema.Name ( Name )
46−import Rel8.Schema.Nullability
47− ( Nullify
48− , Nullability( Nullable, NonNullable )
49− , Sql, nullabilization
50− )
46+import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ), Sql, nullable )
5147import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
5248import Rel8.Table.Alternative
5349 ( AltTable, (<|>:)
@@ -214,9 +210,9 @@ justTable = MaybeTable (fromExpr mempty)
214210-- @null@.
215211($?) :: forall a b. Sql DBType b
216212 => (a -> Expr b) -> MaybeTable a -> Expr (Nullify b)
217−f $? ma@(MaybeTable _ a) = case nullabilization @b of
218− Nullable -> boolExpr (f a) null (isNothingTable ma)
219− NonNullable -> boolExpr (nullify (f a)) null (isNothingTable ma)
213+f $? ma@(MaybeTable _ a) = case nullable @b of
214+ Null -> boolExpr (f a) null (isNothingTable ma)
215+ NotNull -> boolExpr (nullify (f a)) null (isNothingTable ma)
220216infixl 4 $?
221217
222218
src/Rel8/Table/NonEmpty.hs+8−8
@@ -27,9 +27,9 @@ import Rel8.Expr.Array ( sappend1, snonEmptyOf )
2727import Rel8.Schema.Dict ( Dict( Dict ) )
2828import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
2929import Rel8.Schema.HTable.Vectorize ( happend, hvectorize )
30−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
30+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
3131import Rel8.Schema.Spec ( SSpec(..) )
32−import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
32+import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullity )
3333import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
3434import Rel8.Table.Alternative ( AltTable, (<|>:) )
3535import Rel8.Table.Eq ( EqTable, eqTable )
@@ -60,9 +60,9 @@ instance EqTable a => EqTable (NonEmptyTable a) where
6060 eqTable =
6161 hvectorize
6262 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
63− Dict -> case dbTypeNullability dict of
64− Nullable -> Dict
65− NonNullable -> Dict)
63+ Dict -> case dbTypeNullity dict of
64+ Null -> Dict
65+ NotNull -> Dict)
6666 (Identity (eqTable @a))
6767
6868
@@ -70,9 +70,9 @@ instance OrdTable a => OrdTable (NonEmptyTable a) where
7070 ordTable =
7171 hvectorize
7272 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
73− Dict -> case dbTypeNullability dict of
74− Nullable -> Dict
75− NonNullable -> Dict)
73+ Dict -> case dbTypeNullity dict of
74+ Null -> Dict
75+ NotNull -> Dict)
7676 (Identity (ordTable @a))
7777
7878
src/Rel8/Table/Ord.hs+1−1
@@ -37,13 +37,13 @@ import Rel8.Schema.HTable.Pair ( HPair(..) )
3737import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
3838import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
3939import Rel8.Schema.HTable.Trio ( HTrio(..) )
40+import Rel8.Schema.Null (Sql)
4041import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
4142import Rel8.Table ( Table, Columns, toColumns )
4243import Rel8.Table.Bool ( bool )
4344import Rel8.Table.Eq ( EqTable )
4445import Rel8.Type.Eq ( DBEq )
4546import Rel8.Type.Ord ( DBOrd )
46−import Rel8.Schema.Nullability (Sql)
4747
4848
4949-- | The class of 'Table's that can be ordered. Ordering on tables is defined
src/Rel8/Table/Order.hs+9−9
@@ -20,10 +20,10 @@ import Rel8.Expr.Order ( asc, desc, nullsFirst, nullsLast )
2020import Rel8.Order ( Order )
2121import Rel8.Schema.Dict ( Dict( Dict ) )
2222import Rel8.Schema.HTable (htabulateA, hfield, hspecs)
23−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
23+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
2424import Rel8.Schema.Spec ( SSpec( SSpec ) )
25−import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
26−import Rel8.Table
25+import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullity )
26+import Rel8.Table ( Columns, toColumns )
2727import Rel8.Table.Ord
2828
2929
@@ -35,9 +35,9 @@ ascTable = contramap toColumns $ getConst $
3535 SSpec {} -> case hfield (ordTable @a) field of
3636 dict@Dict -> case dbTypeDict dict of
3737 Dict -> Const $ unDB . (`hfield` field) >$<
38− case dbTypeNullability dict of
39− Nullable -> nullsFirst asc
40− NonNullable -> asc
38+ case dbTypeNullity dict of
39+ Null -> nullsFirst asc
40+ NotNull -> asc
4141
4242
4343-- | Construct an 'Order' for a 'Table' by sorting all columns into descending
@@ -48,6 +48,6 @@ descTable = contramap toColumns $ getConst $
4848 SSpec {} -> case hfield (ordTable @a) field of
4949 dict@Dict -> case dbTypeDict dict of
5050 Dict -> Const $ unDB . (`hfield` field) >$<
51− case dbTypeNullability dict of
52− Nullable -> nullsLast desc
53− NonNullable -> desc
51+ case dbTypeNullity dict of
52+ Null -> nullsLast desc
53+ NotNull -> desc
src/Rel8/Table/Recontextualize.hs+1−1
@@ -21,7 +21,7 @@ import Rel8.Schema.Context ( Col )
2121import Rel8.Schema.Context.Label ( Labelable )
2222import Rel8.Schema.HTable ( HTable )
2323import qualified Rel8.Schema.Kind as K
24−import Rel8.Schema.Nullability ( Sql )
24+import Rel8.Schema.Null ( Sql )
2525import Rel8.Table ( Table, Congruent )
2626import Rel8.Type ( DBType )
2727
src/Rel8/Table/Serialize.hs+4−4
@@ -46,7 +46,7 @@ import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
4646import Rel8.Schema.HTable.Pair ( HPair(..) )
4747import Rel8.Schema.HTable.Trio ( HTrio(..) )
4848import Rel8.Schema.HTable.Type ( HType(..) )
49−import Rel8.Schema.Nullability ( NotNull, Sql )
49+import Rel8.Schema.Null ( NotNull, Sql )
5050import Rel8.Schema.Spec ( SSpec(..), KnownSpec )
5151import Rel8.Table ( Table, Columns, fromColumns, toColumns )
5252import Rel8.Table.Either ( EitherTable )
@@ -338,11 +338,11 @@ litTable = lit
338338litHTable :: HTable t => t (Col Identity) -> t (Col Expr)
339339litHTable as = htabulate $ \field ->
340340 case hfield hspecs field of
341− SSpec {nullability, info} -> case hfield as field of
342− Result value -> DB (slitExpr nullability info value)
341+ SSpec {nullity, info} -> case hfield as field of
342+ Result value -> DB (slitExpr nullity info value)
343343
344344
345345parseHTable :: HTable t => Hasql.Row (t (Col Identity))
346346parseHTable = unwrapApplicative $ htabulateA $ \field ->
347347 WrapApplicative $ case hfield hspecs field of
348− SSpec {nullability, info} -> Result <$> sparseValue nullability info
348+ SSpec {nullity, info} -> Result <$> sparseValue nullity info
src/Rel8/Table/Tag.hs+1−1
@@ -31,7 +31,7 @@ import Rel8.Expr ( Expr )
3131import Rel8.Expr.Opaleye ( fromPrimExpr )
3232import Rel8.Schema.Dict ( Dict( Dict ) )
3333import Rel8.Schema.Name ( Name( Name ) )
34−import Rel8.Schema.Nullability ( Sql, mapSql )
34+import Rel8.Schema.Null ( Sql, mapSql )
3535import Rel8.Type.Monoid ( DBMonoid )
3636import Rel8.Type.Semigroup ( DBSemigroup )
3737
src/Rel8/Table/Undefined.hs+4−4
@@ -14,13 +14,13 @@ import Prelude hiding ( undefined )
1414import Rel8.Expr ( Expr, Col(..) )
1515import Rel8.Expr.Null ( snull, unsafeUnnullify )
1616import Rel8.Schema.HTable ( htabulate, hfield, hspecs )
17−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
17+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
1818import Rel8.Schema.Spec ( SSpec(..) )
1919import Rel8.Table ( Table, fromColumns )
2020
2121
2222undefined :: Table Expr a => a
2323undefined = fromColumns $ htabulate $ \field -> case hfield hspecs field of
24− SSpec {nullability, info} -> case nullability of
25− Nullable -> DB (snull info)
26− NonNullable -> DB (unsafeUnnullify (snull info))
24+ SSpec {nullity, info} -> case nullity of
25+ Null -> DB (snull info)
26+ NotNull -> DB (unsafeUnnullify (snull info))
src/Rel8/Type.hs+3−7
@@ -35,11 +35,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
3535import qualified Opaleye.Internal.HaskellDB.Sql.Default as Opaleye ( quote )
3636
3737-- rel8
38−import Rel8.Schema.Nullability
39− ( NotNull
40− , nullabilization
41− , Sql
42− )
38+import Rel8.Schema.Null ( NotNull, Sql, nullable )
4339import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
4440import Rel8.Type.Information ( TypeInformation(..), mapTypeInformation )
4541
@@ -275,8 +271,8 @@ instance DBType Value where
275271
276272
277273instance Sql DBType a => DBType [a] where
278− typeInformation = listTypeInformation nullabilization typeInformation
274+ typeInformation = listTypeInformation nullable typeInformation
279275
280276
281277instance Sql DBType a => DBType (NonEmpty a) where
282− typeInformation = nonEmptyTypeInformation nullabilization typeInformation
278+ typeInformation = nonEmptyTypeInformation nullable typeInformation
src/Rel8/Type/Array.hs+12−12
@@ -22,7 +22,7 @@ import qualified Hasql.Decoders as Hasql
2222import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2323
2424-- rel8
25−import Rel8.Schema.Nullability ( Unnullify, Nullability( Nullable, NonNullable ) )
25+import Rel8.Schema.Null ( Unnullify, Nullity( Null, NotNull ) )
2626import Rel8.Type.Information ( TypeInformation(..), parseTypeInformation )
2727
2828
@@ -35,18 +35,18 @@ array TypeInformation {typeName} =
3535
3636
3737listTypeInformation :: ()
38− => Nullability a
38+ => Nullity a
3939 -> TypeInformation (Unnullify a)
4040 -> TypeInformation [a]
41−listTypeInformation nullability info =
41+listTypeInformation nullity info =
4242 case info of
4343 TypeInformation{ encode, decode } -> TypeInformation
44− { decode = row $ case nullability of
45− Nullable -> Hasql.listArray (Hasql.nullable decode)
46− NonNullable -> Hasql.listArray (Hasql.nonNullable decode)
47− , encode = case nullability of
48− Nullable -> array info . fmap (maybe null encode)
49− NonNullable -> array info . fmap encode
44+ { decode = row $ case nullity of
45+ Null -> Hasql.listArray (Hasql.nullable decode)
46+ NotNull -> Hasql.listArray (Hasql.nonNullable decode)
47+ , encode = case nullity of
48+ Null -> array info . fmap (maybe null encode)
49+ NotNull -> array info . fmap encode
5050 , typeName = "record"
5151 }
5252 where
@@ -55,11 +55,11 @@ listTypeInformation nullability info =
5555
5656
5757nonEmptyTypeInformation :: ()
58− => Nullability a
58+ => Nullity a
5959 -> TypeInformation (Unnullify a)
6060 -> TypeInformation (NonEmpty a)
61−nonEmptyTypeInformation nullability =
62− parseTypeInformation parse toList . listTypeInformation nullability
61+nonEmptyTypeInformation nullity =
62+ parseTypeInformation parse toList . listTypeInformation nullity
6363 where
6464 parse = maybe (Left message) Right . nonEmpty
6565 message = "failed to decode NonEmptyList: got empty list"
src/Rel8/Type/Array1D.hs+10−14
@@ -42,11 +42,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
4242-- rel8
4343import Rel8.Expr.Opaleye ( zipPrimExprsWith )
4444import Rel8.Expr.Serialize ( litExpr )
45−import Rel8.Schema.Nullability
46− ( Unnullify
47− , Nullability( Nullable, NonNullable )
48− , Sql, nullabilization
49− )
45+import Rel8.Schema.Null ( Unnullify, Nullity( Null, NotNull ), Sql, nullable )
5046import Rel8.Type ( DBType, typeInformation )
5147import Rel8.Type.Eq ( DBEq )
5248import Rel8.Type.Information ( TypeInformation(..) )
@@ -94,18 +90,18 @@ type family IsArray1D a where
9490
9591
9692array1DTypeInformation :: IsArray1D (Unnullify a) ~ 'False
97− => Nullability a
93+ => Nullity a
9894 -> TypeInformation (Unnullify a)
9995 -> TypeInformation (Array1D a)
100−array1DTypeInformation nullability info =
96+array1DTypeInformation nullity info =
10197 case info of
10298 TypeInformation{ encode, decode, typeName } -> TypeInformation
103− { decode = case nullability of
104− Nullable -> Array1D <$> Hasql.listArray (Hasql.nullable decode)
105− NonNullable -> Array1D <$> Hasql.listArray (Hasql.nonNullable decode)
106− , encode = case nullability of
107− Nullable -> Opaleye.ArrayExpr . fmap (maybe null encode) . getArray1D
108− NonNullable -> Opaleye.ArrayExpr . fmap encode . getArray1D
99+ { decode = case nullity of
100+ Null -> Array1D <$> Hasql.listArray (Hasql.nullable decode)
101+ NotNull -> Array1D <$> Hasql.listArray (Hasql.nonNullable decode)
102+ , encode = case nullity of
103+ Null -> Opaleye.ArrayExpr . fmap (maybe null encode) . getArray1D
104+ NotNull -> Opaleye.ArrayExpr . fmap encode . getArray1D
109105 , typeName = typeName <> "[]"
110106 }
111107 where
@@ -113,7 +109,7 @@ array1DTypeInformation nullability info =
113109
114110
115111instance (Sql DBType a, IsArray1D (Unnullify a) ~ 'False) => DBType (Array1D a) where
116− typeInformation = array1DTypeInformation nullabilization typeInformation
112+ typeInformation = array1DTypeInformation nullable typeInformation
117113
118114
119115instance (Sql DBEq a, IsArray1D (Unnullify a) ~ 'False) => DBEq (Array1D a)
src/Rel8/Type/Eq.hs+1−1
@@ -27,7 +27,7 @@ import qualified Data.ByteString.Lazy as Lazy ( ByteString )
2727import Data.CaseInsensitive ( CI )
2828
2929-- rel8
30−import Rel8.Schema.Nullability ( Sql )
30+import Rel8.Schema.Null ( Sql )
3131import Rel8.Type ( DBType )
3232
3333-- scientific
src/Rel8/Type/Monoid.hs+2−2
@@ -27,7 +27,7 @@ import Data.CaseInsensitive ( CI )
2727import {-# SOURCE #-} Rel8.Expr ( Expr )
2828import Rel8.Expr.Array ( sempty )
2929import Rel8.Expr.Serialize ( litExpr )
30−import Rel8.Schema.Nullability ( Sql, nullabilization )
30+import Rel8.Schema.Null ( Sql, nullable )
3131import Rel8.Type ( DBType, typeInformation )
3232import Rel8.Type.Semigroup ( DBSemigroup )
3333
@@ -48,7 +48,7 @@ class DBSemigroup a => DBMonoid a where
4848
4949
5050instance Sql DBType a => DBMonoid [a] where
51− memptyExpr = sempty nullabilization typeInformation
51+ memptyExpr = sempty nullable typeInformation
5252
5353
5454instance DBMonoid CalendarDiffTime where
src/Rel8/Type/Ord.hs+1−1
@@ -25,7 +25,7 @@ import qualified Data.ByteString.Lazy as Lazy ( ByteString )
2525import Data.CaseInsensitive ( CI )
2626
2727-- rel8
28−import Rel8.Schema.Nullability ( Sql )
28+import Rel8.Schema.Null ( Sql )
2929import Rel8.Type.Eq ( DBEq )
3030
3131-- scientific
src/Rel8/Type/Semigroup.hs+1−1
@@ -29,7 +29,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
2929-- rel8
3030import {-# SOURCE #-} Rel8.Expr ( Expr )
3131import Rel8.Expr.Opaleye ( zipPrimExprsWith )
32−import Rel8.Schema.Nullability ( Sql )
32+import Rel8.Schema.Null ( Sql )
3333import Rel8.Type ( DBType )
3434
3535-- text
tests/Main.hs+1−1
@@ -516,7 +516,7 @@ testCatMaybe = databasePropertyTest "catMaybe" \transaction -> evalM do
516516
517517 transaction \connection -> do
518518 selected <- evalM $ liftIO $ Rel8.select connection do
519− Rel8.catNullable =<< Rel8.values (map Rel8.lit rows)
519+ Rel8.catNull =<< Rel8.values (map Rel8.lit rows)
520520
521521 sort selected === sort (catMaybes rows)
522522