on master help sign in
Rename all the null things
f1e287eShane O'Brien
rel8.cabal+1−1
@@ -113,7 +113,7 @@ library
113 Rel8.Schema.Insert
113 Rel8.Schema.Insert
114 Rel8.Schema.Kind
114 Rel8.Schema.Kind
115 Rel8.Schema.Name
115 Rel8.Schema.Name
116− Rel8.Schema.Nullability
116+ Rel8.Schema.Null
117 Rel8.Schema.Spec
117 Rel8.Schema.Spec
118 Rel8.Schema.Spec.ConstrainDBType
118 Rel8.Schema.Spec.ConstrainDBType
119 Rel8.Schema.Spec.ConstrainType
119 Rel8.Schema.Spec.ConstrainType
src/Rel8.hs+5−5
@@ -101,9 +101,9 @@ module Rel8
101 , nullable
101 , nullable
102 , isNull
102 , isNull
103 , isNonNull
103 , isNonNull
104− , mapNullable
104+ , mapNull
105− , liftOpNullable
105+ , liftOpNull
106− , catNullable
106+ , catNull
107 , coalesce
107 , coalesce
108
108
109 -- ** Boolean operations
109 -- ** Boolean operations
@@ -226,7 +226,7 @@ module Rel8
226 -- TODO
226 -- TODO
227 -- These need organizing, but are reachable from Rel8's documentation so we
227 -- These need organizing, but are reachable from Rel8's documentation so we
228 -- do need to export and document them.
228 -- do need to export and document them.
229− , HasNullability
229+ , Nullable
230 , NotNull
230 , NotNull
231 , HTable
231 , HTable
232 , Labelable
232 , Labelable
@@ -272,7 +272,7 @@ import Rel8.Schema.Field (Field)
272import Rel8.Schema.Generic
272import Rel8.Schema.Generic
273import Rel8.Schema.HTable
273import Rel8.Schema.HTable
274import Rel8.Schema.Name
274import Rel8.Schema.Name
275−import Rel8.Schema.Nullability
275+import Rel8.Schema.Null hiding ( nullable )
276import Rel8.Schema.Table
276import Rel8.Schema.Table
277import Rel8.Statement.Delete
277import Rel8.Statement.Delete
278import Rel8.Statement.Insert
278import Rel8.Statement.Insert
src/Rel8/Aggregate.hs+1−1
@@ -36,7 +36,7 @@ import Rel8.Schema.Context ( Interpretation(..) )
36import Rel8.Schema.Context.Label ( Labelable(..) )
36import Rel8.Schema.Context.Label ( Labelable(..) )
37import Rel8.Schema.HTable ( hfield, htabulate, htabulateA, hspecs )
37import Rel8.Schema.HTable ( hfield, htabulate, htabulateA, hspecs )
38import Rel8.Schema.Name ( Name )
38import Rel8.Schema.Name ( Name )
39−import Rel8.Schema.Nullability ( Sql )
39+import Rel8.Schema.Null ( Sql )
40import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
40import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
41import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
41import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
42import Rel8.Table.Recontextualize ( Recontextualize )
42import Rel8.Table.Recontextualize ( Recontextualize )
src/Rel8/Expr.hs+11−14
@@ -27,7 +27,7 @@ import Prelude hiding ( null )
27import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
27import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
28
28
29-- rel8
29-- rel8
30−import Rel8.Expr.Null ( liftOpNullable, nullify )
30+import Rel8.Expr.Null ( liftOpNull, nullify )
31import Rel8.Expr.Opaleye
31import Rel8.Expr.Opaleye
32 ( castExpr
32 ( castExpr
33 , fromPrimExpr
33 , fromPrimExpr
@@ -38,10 +38,7 @@ import Rel8.Expr.Serialize ( litExpr )
38import Rel8.Schema.Context ( Interpretation, Col )
38import Rel8.Schema.Context ( Interpretation, Col )
39import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
39import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
40import Rel8.Schema.HTable.Type ( HType( HType ) )
40import Rel8.Schema.HTable.Type ( HType( HType ) )
41−import Rel8.Schema.Nullability
41+import Rel8.Schema.Null ( Nullity( Null, NotNull ), Sql, nullable )
42− ( Nullability( Nullable, NonNullable )
43− , Sql, nullabilization
44− )
45import Rel8.Schema.Spec ( Spec( Spec ) )
42import Rel8.Schema.Spec ( Spec( Spec ) )
46import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
43import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
47import Rel8.Table.Recontextualize ( Recontextualize )
44import Rel8.Table.Recontextualize ( Recontextualize )
@@ -59,23 +56,23 @@ newtype Expr a = Expr Opaleye.PrimExpr
59
56
60
57
61instance Sql DBSemigroup a => Semigroup (Expr a) where
58instance Sql DBSemigroup a => Semigroup (Expr a) where
62− (<>) = case nullabilization @a of
59+ (<>) = case nullable @a of
63− Nullable -> liftOpNullable (<>.)
60+ Null -> liftOpNull (<>.)
64− NonNullable -> (<>.)
61+ NotNull -> (<>.)
65 {-# INLINABLE (<>) #-}
62 {-# INLINABLE (<>) #-}
66
63
67
64
68instance Sql DBMonoid a => Monoid (Expr a) where
65instance Sql DBMonoid a => Monoid (Expr a) where
69− mempty = case nullabilization @a of
66+ mempty = case nullable @a of
70− Nullable -> nullify memptyExpr
67+ Null -> nullify memptyExpr
71− NonNullable -> memptyExpr
68+ NotNull -> memptyExpr
72 {-# INLINABLE mempty #-}
69 {-# INLINABLE mempty #-}
73
70
74
71
75instance (Sql IsString a, Sql DBType a) => IsString (Expr a) where
72instance (Sql IsString a, Sql DBType a) => IsString (Expr a) where
76− fromString = litExpr . case nullabilization @a of
73+ fromString = litExpr . case nullable @a of
77− Nullable -> Just . fromString
74+ Null -> Just . fromString
78− NonNullable -> fromString
75+ NotNull -> fromString
79
76
80
77
81instance Sql DBNum a => Num (Expr a) where
78instance Sql DBNum a => Num (Expr a) where
src/Rel8/Expr/Aggregate.hs+1−1
@@ -36,7 +36,7 @@ import Rel8.Expr.Opaleye
36 )
36 )
37import Rel8.Expr.Null ( null )
37import Rel8.Expr.Null ( null )
38import Rel8.Expr.Serialize ( litExpr )
38import Rel8.Expr.Serialize ( litExpr )
39−import Rel8.Schema.Nullability ( Sql )
39+import Rel8.Schema.Null ( Sql )
40import Rel8.Type.Array ( fromPrimArray )
40import Rel8.Type.Array ( fromPrimArray )
41import Rel8.Type.Eq ( DBEq )
41import Rel8.Type.Eq ( DBEq )
42import Rel8.Type.Num ( DBNum )
42import Rel8.Type.Num ( DBNum )
src/Rel8/Expr/Array.hs+2−2
@@ -27,7 +27,7 @@ import Rel8.Expr.Opaleye
27import Rel8.Type ( DBType, typeInformation )
27import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type.Array ( array, zipPrimArraysWith )
28import Rel8.Type.Array ( array, zipPrimArraysWith )
29import Rel8.Type.Information ( TypeInformation(..) )
29import Rel8.Type.Information ( TypeInformation(..) )
30−import Rel8.Schema.Nullability ( Unnullify, Nullability, Sql )
30+import Rel8.Schema.Null ( Unnullify, Nullity, Sql )
31
31
32
32
33sappend :: Expr [a] -> Expr [a] -> Expr [a]
33sappend :: Expr [a] -> Expr [a] -> Expr [a]
@@ -38,7 +38,7 @@ sappend1 :: Expr (NonEmpty a) -> Expr (NonEmpty a) -> Expr (NonEmpty a)
38sappend1 = zipPrimExprsWith (zipPrimArraysWith (Opaleye.BinExpr (Opaleye.:||)))
38sappend1 = zipPrimExprsWith (zipPrimArraysWith (Opaleye.BinExpr (Opaleye.:||)))
39
39
40
40
41−sempty :: Nullability a -> TypeInformation (Unnullify a) -> Expr [a]
41+sempty :: Nullity a -> TypeInformation (Unnullify a) -> Expr [a]
42sempty _ info = fromPrimExpr $ array info []
42sempty _ info = fromPrimExpr $ array info []
43
43
44
44
src/Rel8/Expr/Eq.hs+15−16
@@ -24,12 +24,9 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
24-- rel8
24-- rel8
25import Rel8.Expr ( Expr )
25import Rel8.Expr ( Expr )
26import Rel8.Expr.Bool ( (&&.), (||.), false, or_, coalesce )
26import Rel8.Expr.Bool ( (&&.), (||.), false, or_, coalesce )
27−import Rel8.Expr.Null ( isNull, unsafeLiftOpNullable )
27+import Rel8.Expr.Null ( isNull, unsafeLiftOpNull )
28import Rel8.Expr.Opaleye ( fromPrimExpr, toPrimExpr, zipPrimExprsWith )
28import Rel8.Expr.Opaleye ( fromPrimExpr, toPrimExpr, zipPrimExprsWith )
29−import Rel8.Schema.Nullability
29+import Rel8.Schema.Null ( Nullity( NotNull, Null ), Sql, nullable )
30− ( Nullability( NonNullable, Nullable )
31− , Sql, nullabilization
32− )
33import Rel8.Type.Eq ( DBEq )
30import Rel8.Type.Eq ( DBEq )
34
31
35
32
@@ -48,10 +45,11 @@ ne = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:<>))
48-- This operator matches Haskell's '==' operator. For an operator identical to
45-- This operator matches Haskell's '==' operator. For an operator identical to
49-- SQL @=@, see '==?'.
46-- SQL @=@, see '==?'.
50(==.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool
47(==.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool
51−(==.) = case nullabilization @a of
48+(==.) = case nullable @a of
52− Nullable -> \ma mb -> isNull ma &&. isNull mb ||. ma ==? mb
49+ Null -> \ma mb -> isNull ma &&. isNull mb ||. ma ==? mb
53− NonNullable -> eq
50+ NotNull -> eq
54infix 4 ==.
51infix 4 ==.
52+{-# INLINABLE (==.) #-}
55
53
56
54
57-- | Test if two expressions are different (not equal).
55-- | Test if two expressions are different (not equal).
@@ -61,10 +59,11 @@ infix 4 ==.
61-- which would return @null@. This operator is closer to Haskell's '=='
59-- which would return @null@. This operator is closer to Haskell's '=='
62-- operator. For an operator identical to SQL @=@, see '/=?'.
60-- operator. For an operator identical to SQL @=@, see '/=?'.
63(/=.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool
61(/=.) :: forall a. Sql DBEq a => Expr a -> Expr a -> Expr Bool
64−(/=.) = case nullabilization @a of
62+(/=.) = case nullable @a of
65− Nullable -> \ma mb -> isNull ma `ne` isNull mb ||. ma /=? mb
63+ Null -> \ma mb -> isNull ma `ne` isNull mb ||. ma /=? mb
66− NonNullable -> ne
64+ NotNull -> ne
67infix 4 /=.
65infix 4 /=.
66+{-# INLINABLE (/=.) #-}
68
67
69
68
70-- | Test if two expressions are equal. This operator is usually the best
69-- | Test if two expressions are equal. This operator is usually the best
@@ -74,7 +73,7 @@ infix 4 /=.
74-- This corresponds to the SQL @=@ operator, though it will always return a
73-- This corresponds to the SQL @=@ operator, though it will always return a
75-- 'Bool'.
74-- 'Bool'.
76(==?) :: DBEq a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
75(==?) :: 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
78infix 4 ==?
77infix 4 ==?
79
78
80
79
@@ -83,7 +82,7 @@ infix 4 ==?
83-- This corresponds to the SQL @<>@ operator, though it will always return a
82-- This corresponds to the SQL @<>@ operator, though it will always return a
84-- 'Bool'.
83-- 'Bool'.
85(/=?) :: DBEq a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
84(/=?) :: 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
87infix 4 /=?
86infix 4 /=?
88
87
89
88
@@ -91,9 +90,9 @@ infix 4 /=?
91-- '==.' and '||.'.
90-- '==.' and '||.'.
92in_ :: forall a f. (Sql DBEq a, Foldable f)
91in_ :: forall a f. (Sql DBEq a, Foldable f)
93 => Expr a -> f (Expr a) -> Expr Bool
92 => Expr a -> f (Expr a) -> Expr Bool
94−in_ a (toList -> as) = case nullabilization @a of
93+in_ a (toList -> as) = case nullable @a of
95− Nullable -> or_ $ map (a ==.) as
94+ Null -> or_ $ map (a ==.) as
96− NonNullable -> case nonEmpty as of
95+ NotNull -> case nonEmpty as of
97 Nothing -> false
96 Nothing -> false
98 Just xs ->
97 Just xs ->
99 fromPrimExpr $
98 fromPrimExpr $
src/Rel8/Expr/Function.hs+1−1
@@ -25,7 +25,7 @@ import Rel8.Expr.Opaleye
25 ( castExpr
25 ( castExpr
26 , fromPrimExpr, toPrimExpr, zipPrimExprsWith
26 , fromPrimExpr, toPrimExpr, zipPrimExprsWith
27 )
27 )
28−import Rel8.Schema.Nullability ( Sql )
28+import Rel8.Schema.Null ( Sql )
29import Rel8.Type ( DBType )
29import Rel8.Type ( DBType )
30
30
31
31
src/Rel8/Expr/Null.hs+14−14
@@ -8,8 +8,8 @@ module Rel8.Expr.Null
8 ( null, snull, nullable, nullableOf
8 ( null, snull, nullable, nullableOf
9 , isNull, isNonNull
9 , isNull, isNonNull
10 , nullify, unsafeUnnullify
10 , nullify, unsafeUnnullify
11− , mapNullable, liftOpNullable
11+ , mapNull, liftOpNull
12− , unsafeMapNullable, unsafeLiftOpNullable
12+ , unsafeMapNull, unsafeLiftOpNull
13 )
13 )
14where
14where
15
15
@@ -23,7 +23,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
23import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
23import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
24import Rel8.Expr.Bool ( (||.), boolExpr )
24import Rel8.Expr.Bool ( (||.), boolExpr )
25import Rel8.Expr.Opaleye ( scastExpr, mapPrimExpr )
25import Rel8.Expr.Opaleye ( scastExpr, mapPrimExpr )
26−import Rel8.Schema.Nullability ( NotNull )
26+import Rel8.Schema.Null ( NotNull )
27import Rel8.Type ( DBType, typeInformation )
27import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type.Information ( TypeInformation )
28import Rel8.Type.Information ( TypeInformation )
29
29
@@ -59,24 +59,24 @@ isNonNull = mapPrimExpr (Opaleye.UnExpr Opaleye.OpIsNotNull)
59
59
60
60
61-- | Lift an operation on non-@null@ values to an operation on possibly @null@
61-- | 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@.
63--
63--
64-- This is like 'fmap' for 'Maybe'.
64-- This is like 'fmap' for 'Maybe'.
65−mapNullable :: DBType b
65+mapNull :: DBType b
66 => (Expr a -> Expr b) -> Expr (Maybe a) -> Expr (Maybe b)
66 => (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)
68
68
69
69
70-- | Lift a binary operation on non-@null@ expressions to an equivalent binary
70-- | Lift a binary operation on non-@null@ expressions to an equivalent binary
71-- operator on possibly @null@ expressions. If either of the final arguments
71-- operator on possibly @null@ expressions. If either of the final arguments
72−-- are @null@, @liftOpNullable@ returns @null@.
72+-- are @null@, @liftOpNull@ returns @null@.
73--
73--
74-- This is like 'liftA2' for 'Maybe'.
74-- This is like 'liftA2' for 'Maybe'.
75−liftOpNullable :: DBType c
75+liftOpNull :: DBType c
76 => (Expr a -> Expr b -> Expr c)
76 => (Expr a -> Expr b -> Expr c)
77 -> Expr (Maybe a) -> Expr (Maybe b) -> Expr (Maybe c)
77 -> Expr (Maybe a) -> Expr (Maybe b) -> Expr (Maybe c)
78−liftOpNullable f ma mb =
78+liftOpNull f ma mb =
79− boolExpr (unsafeLiftOpNullable f ma mb) null
79+ boolExpr (unsafeLiftOpNull f ma mb) null
80 (isNull ma ||. isNull mb)
80 (isNull ma ||. isNull mb)
81
81
82
82
@@ -89,13 +89,13 @@ null :: DBType a => Expr (Maybe a)
89null = snull typeInformation
89null = snull typeInformation
90
90
91
91
92−unsafeMapNullable :: NotNull b
92+unsafeMapNull :: NotNull b
93 => (Expr a -> Expr b) -> Expr (Maybe a) -> Expr (Maybe b)
93 => (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))
95
95
96
96
97−unsafeLiftOpNullable :: NotNull c
97+unsafeLiftOpNull :: NotNull c
98 => (Expr a -> Expr b -> Expr c)
98 => (Expr a -> Expr b -> Expr c)
99 -> Expr (Maybe a) -> Expr (Maybe b) -> Expr (Maybe c)
99 -> Expr (Maybe a) -> Expr (Maybe b) -> Expr (Maybe c)
100−unsafeLiftOpNullable f ma mb =
100+unsafeLiftOpNull f ma mb =
101 nullify (f (unsafeUnnullify ma) (unsafeUnnullify mb))
101 nullify (f (unsafeUnnullify ma) (unsafeUnnullify mb))
src/Rel8/Expr/Num.hs+1−1
@@ -15,7 +15,7 @@ import Prelude ()
15import Rel8.Expr ( Expr( Expr ) )
15import Rel8.Expr ( Expr( Expr ) )
16import Rel8.Expr.Function ( function )
16import Rel8.Expr.Function ( function )
17import Rel8.Expr.Opaleye ( castExpr )
17import Rel8.Expr.Opaleye ( castExpr )
18−import Rel8.Schema.Nullability ( Homonullable, Sql )
18+import Rel8.Schema.Null ( Homonullable, Sql )
19import Rel8.Type.Num ( DBFractional, DBIntegral, DBNum )
19import Rel8.Type.Num ( DBFractional, DBIntegral, DBNum )
20
20
21
21
src/Rel8/Expr/Opaleye.hs+1−1
@@ -23,7 +23,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
23
23
24-- rel8
24-- rel8
25import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
25import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
26−import Rel8.Schema.Nullability ( Unnullify, Sql )
26+import Rel8.Schema.Null ( Unnullify, Sql )
27import Rel8.Type ( DBType, typeInformation )
27import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type.Information ( TypeInformation(..) )
28import Rel8.Type.Information ( TypeInformation(..) )
29
29
src/Rel8/Expr/Ord.hs+25−27
@@ -22,12 +22,10 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
22-- rel8
22-- rel8
23import Rel8.Expr ( Expr( Expr ) )
23import Rel8.Expr ( Expr( Expr ) )
24import Rel8.Expr.Bool ( (&&.), (||.), coalesce )
24import Rel8.Expr.Bool ( (&&.), (||.), coalesce )
25−import Rel8.Expr.Null ( isNull, isNonNull, nullable, unsafeLiftOpNullable )
25+import Rel8.Expr.Null ( isNull, isNonNull, nullable, unsafeLiftOpNull )
26import Rel8.Expr.Opaleye ( zipPrimExprsWith )
26import Rel8.Expr.Opaleye ( zipPrimExprsWith )
27−import Rel8.Schema.Nullability
27+import Rel8.Schema.Null ( Nullity( Null, NotNull ), Sql )
28− ( Nullability( NonNullable, Nullable )
28+import qualified Rel8.Schema.Null as Schema ( nullable )
29− , Sql, nullabilization
30− )
31import Rel8.Type.Ord ( DBOrd )
29import Rel8.Type.Ord ( DBOrd )
32
30
33
31
@@ -51,9 +49,9 @@ ge = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:>=))
51-- as @null@ will sort below any other value. For a version of @<@ that exactly
49-- as @null@ will sort below any other value. For a version of @<@ that exactly
52-- matches SQL, see '(<?)'.
50-- matches SQL, see '(<?)'.
53(<.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
51(<.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
54−(<.) = case nullabilization @a of
52+(<.) = case Schema.nullable @a of
55− Nullable -> \ma mb -> isNull ma &&. isNonNull mb ||. ma <? mb
53+ Null -> \ma mb -> isNull ma &&. isNonNull mb ||. ma <? mb
56− NonNullable -> lt
54+ NotNull -> lt
57infix 4 <.
55infix 4 <.
58
56
59
57
@@ -61,9 +59,9 @@ infix 4 <.
61-- as @null@ will sort below any other value. For a version of @<=@ that exactly
59-- as @null@ will sort below any other value. For a version of @<=@ that exactly
62-- matches SQL, see '(<=?)'.
60-- matches SQL, see '(<=?)'.
63(<=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
61(<=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
64−(<=.) = case nullabilization @a of
62+(<=.) = case Schema.nullable @a of
65− Nullable -> \ma mb -> isNull ma ||. ma <=? mb
63+ Null -> \ma mb -> isNull ma ||. ma <=? mb
66− NonNullable -> le
64+ NotNull -> le
67infix 4 <=.
65infix 4 <=.
68
66
69
67
@@ -71,9 +69,9 @@ infix 4 <=.
71-- as @null@ will sort below any other value. For a version of @>@ that exactly
69-- as @null@ will sort below any other value. For a version of @>@ that exactly
72-- matches SQL, see '(>?)'.
70-- matches SQL, see '(>?)'.
73(>.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
71(>.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
74−(>.) = case nullabilization @a of
72+(>.) = case Schema.nullable @a of
75− Nullable -> \ma mb -> isNonNull ma &&. isNull mb ||. ma >? mb
73+ Null -> \ma mb -> isNonNull ma &&. isNull mb ||. ma >? mb
76− NonNullable -> gt
74+ NotNull -> gt
77infix 4 >.
75infix 4 >.
78
76
79
77
@@ -81,37 +79,37 @@ infix 4 >.
81-- as @null@ will sort below any other value. For a version of @>=@ that
79-- as @null@ will sort below any other value. For a version of @>=@ that
82-- exactly matches SQL, see '(>=?)'.
80-- exactly matches SQL, see '(>=?)'.
83(>=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
81(>=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
84−(>=.) = case nullabilization @a of
82+(>=.) = case Schema.nullable @a of
85− Nullable -> \ma mb -> isNull mb ||. ma >=? mb
83+ Null -> \ma mb -> isNull mb ||. ma >=? mb
86− NonNullable -> ge
84+ NotNull -> ge
87infix 4 >=.
85infix 4 >=.
88
86
89
87
90-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
88-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
91-- are @null@.
89-- are @null@.
92(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
90(<?) :: 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
94infix 4 <?
92infix 4 <?
95
93
96
94
97-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
95-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
98-- are @null@.
96-- are @null@.
99(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
97(<=?) :: 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
101infix 4 <=?
99infix 4 <=?
102
100
103
101
104-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
102-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
105-- are @null@.
103-- are @null@.
106(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
104(>?) :: 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
108infix 4 >?
106infix 4 >?
109
107
110
108
111-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
109-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
112-- are @null@.
110-- are @null@.
113(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
111(>=?) :: 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
115infix 4 >=?
113infix 4 >=?
116
114
117
115
@@ -120,9 +118,9 @@ infix 4 >=?
120--
118--
121-- Corresponds to the SQL @least()@ function.
119-- Corresponds to the SQL @least()@ function.
122leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
120leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
123−leastExpr ma mb = case nullabilization @a of
121+leastExpr ma mb = case Schema.nullable @a of
124− Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
122+ Null -> nullable ma (\a -> nullable mb (least_ a) mb) ma
125− NonNullable -> least_ ma mb
123+ NotNull -> least_ ma mb
126 where
124 where
127 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
125 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
128
126
@@ -132,8 +130,8 @@ leastExpr ma mb = case nullabilization @a of
132--
130--
133-- Corresponds to the SQL @greatest()@ function.
131-- Corresponds to the SQL @greatest()@ function.
134greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
132greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
135−greatestExpr ma mb = case nullabilization @a of
133+greatestExpr ma mb = case Schema.nullable @a of
136− Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
134+ Null -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
137− NonNullable -> greatest_ ma mb
135+ NotNull -> greatest_ ma mb
138 where
136 where
139 greatest_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "GREATEST" [a, b])
137 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
21-- rel8
21-- rel8
22import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
22import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
23import Rel8.Expr.Opaleye ( scastExpr )
23import Rel8.Expr.Opaleye ( scastExpr )
24−import Rel8.Schema.Nullability
24+import Rel8.Schema.Null ( Unnullify, Nullity( Null, NotNull ), Sql, nullable )
25− ( Unnullify
26− , Nullability( Nullable, NonNullable )
27− , Sql, nullabilization
28− )
29import Rel8.Type ( DBType, typeInformation )
25import Rel8.Type ( DBType, typeInformation )
30import Rel8.Type.Information ( TypeInformation(..) )
26import Rel8.Type.Information ( TypeInformation(..) )
31
27
@@ -35,19 +31,19 @@ import Rel8.Type.Information ( TypeInformation(..) )
35-- Note that you can usually use 'Rel8.lit', but @litExpr@ can solve problems
31-- Note that you can usually use 'Rel8.lit', but @litExpr@ can solve problems
36-- of inference in polymorphic code.
32-- of inference in polymorphic code.
37litExpr :: Sql DBType a => a -> Expr a
33litExpr :: Sql DBType a => a -> Expr a
38−litExpr = slitExpr nullabilization typeInformation
34+litExpr = slitExpr nullable typeInformation
39
35
40
36
41−slitExpr :: Nullability a -> TypeInformation (Unnullify a) -> a -> Expr a
37+slitExpr :: Nullity a -> TypeInformation (Unnullify a) -> a -> Expr a
42−slitExpr nullability info@TypeInformation {encode} =
38+slitExpr nullity info@TypeInformation {encode} =
43 scastExpr info . Expr . encoder
39 scastExpr info . Expr . encoder
44 where
40 where
45− encoder = case nullability of
41+ encoder = case nullity of
46− Nullable -> maybe (Opaleye.ConstExpr Opaleye.NullLit) encode
42+ Null -> maybe (Opaleye.ConstExpr Opaleye.NullLit) encode
47− NonNullable -> encode
43+ NotNull -> encode
48
44
49
45
50−sparseValue :: Nullability a -> TypeInformation (Unnullify a) -> Hasql.Row a
46+sparseValue :: Nullity a -> TypeInformation (Unnullify a) -> Hasql.Row a
51−sparseValue nullability TypeInformation {decode} = case nullability of
47+sparseValue nullity TypeInformation {decode} = case nullity of
52− Nullable -> Hasql.column $ Hasql.nullable decode
48+ Null -> Hasql.column $ Hasql.nullable decode
53− NonNullable -> Hasql.column $ Hasql.nonNullable decode
49+ NotNull -> Hasql.column $ Hasql.nonNullable decode
src/Rel8/Query/Null.hs+3−3
@@ -1,5 +1,5 @@
1module Rel8.Query.Null
1module Rel8.Query.Null
2− ( catNullable
2+ ( catNull
3 )
3 )
4where
4where
5
5
@@ -17,7 +17,7 @@ import Rel8.Query.Filter ( where_ )
17-- @null@s.
17-- @null@s.
18--
18--
19-- Corresponds to 'Data.Maybe.catMaybes'.
19-- Corresponds to 'Data.Maybe.catMaybes'.
20−catNullable :: Expr (Maybe a) -> Query (Expr a)
20+catNull :: Expr (Maybe a) -> Query (Expr a)
21−catNullable a = do
21+catNull a = do
22 where_ $ isNonNull a
22 where_ $ isNonNull a
23 pure $ unsafeUnnullify a
23 pure $ unsafeUnnullify a
src/Rel8/Schema/Context/Identity.hs+8−11
@@ -29,10 +29,7 @@ import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
29import Rel8.Schema.HTable.Nullify ( hnulls, hnullify, hunnullify )
29import Rel8.Schema.HTable.Nullify ( hnulls, hnullify, hunnullify )
30import Rel8.Schema.HTable.These ( HTheseTable(..) )
30import Rel8.Schema.HTable.These ( HTheseTable(..) )
31import Rel8.Schema.HTable.Vectorize ( hvectorize, hunvectorize )
31import Rel8.Schema.HTable.Vectorize ( hvectorize, hunvectorize )
32−import Rel8.Schema.Nullability
32+import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ) )
33− ( Nullify
34− , Nullability( Nullable, NonNullable )
35− )
36import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
33import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
37import Rel8.Type.Tag ( EitherTag( IsLeft, IsRight ), MaybeTag( IsJust ) )
34import Rel8.Type.Tag ( EitherTag( IsLeft, IsRight ), MaybeTag( IsJust ) )
38
35
@@ -164,19 +161,19 @@ nullifier :: ()
164 => SSpec ('Spec labels necessity a)
161 => SSpec ('Spec labels necessity a)
165 -> Col Identity ('Spec labels necessity a)
162 -> Col Identity ('Spec labels necessity a)
166 -> Col Identity ('Spec labels necessity (Nullify a))
163 -> Col Identity ('Spec labels necessity (Nullify a))
167−nullifier SSpec {nullability} (Result a) = Result $ case nullability of
164+nullifier SSpec {nullity} (Result a) = Result $ case nullity of
168− Nullable -> a
165+ Null -> a
169− NonNullable -> Just a
166+ NotNull -> Just a
170
167
171
168
172unnullifier :: ()
169unnullifier :: ()
173 => SSpec ('Spec labels necessity a)
170 => SSpec ('Spec labels necessity a)
174 -> Col Identity ('Spec labels necessity (Nullify a))
171 -> Col Identity ('Spec labels necessity (Nullify a))
175 -> Maybe (Col Identity ('Spec labels necessity a))
172 -> Maybe (Col Identity ('Spec labels necessity a))
176−unnullifier SSpec {nullability} (Result a) =
173+unnullifier SSpec {nullity} (Result a) =
177− case nullability of
174+ case nullity of
178− Nullable -> pure $ Result a
175+ Null -> pure $ Result a
179− NonNullable -> Result <$> a
176+ NotNull -> Result <$> a
180
177
181
178
182vectorizer :: Functor f
179vectorizer :: Functor f
src/Rel8/Schema/Context/Nullify.hs+27−31
@@ -37,16 +37,12 @@ import Rel8.Kind.Necessity ( Necessity( Required ) )
37import Rel8.Schema.Context ( Interpretation )
37import Rel8.Schema.Context ( Interpretation )
38import qualified Rel8.Schema.Kind as K
38import qualified Rel8.Schema.Kind as K
39import Rel8.Schema.Name ( Name( Name ), Col(..) )
39import Rel8.Schema.Name ( Name( Name ), Col(..) )
40−import Rel8.Schema.Nullability
40+import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ), Sql )
41− ( Nullify
42− , Nullability( Nullable, NonNullable )
43− , Sql
44− )
45import Rel8.Schema.Dict ( Dict( Dict ) )
41import Rel8.Schema.Dict ( Dict( Dict ) )
46import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
42import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
47import Rel8.Schema.Spec.ConstrainDBType
43import Rel8.Schema.Spec.ConstrainDBType
48 ( ConstrainDBType
44 ( ConstrainDBType
49− , dbTypeDict, dbTypeNullability, fromNullabilityDict
45+ , dbTypeDict, dbTypeNullity, fromNullityDict
50 )
46 )
51import Rel8.Table.Tag ( Tag(..), Taggable, fromAggregate, fromExpr, fromName )
47import Rel8.Table.Tag ( Tag(..), Taggable, fromAggregate, fromExpr, fromName )
52
48
@@ -91,15 +87,15 @@ instance Nullifiable Aggregate where
91
87
92 decodeTag (Aggregation aggregate) = fromAggregate aggregate
88 decodeTag (Aggregation aggregate) = fromAggregate aggregate
93
89
94− nullifier Tag {expr} test SSpec {nullability} (Aggregation aggregate) =
90+ nullifier Tag {expr} test SSpec {nullity} (Aggregation aggregate) =
95 Aggregation $
91 Aggregation $
96− mapInputs (toPrimExpr . runTag nullability condition . fromPrimExpr) $
92+ mapInputs (toPrimExpr . runTag nullity condition . fromPrimExpr) $
97− runTag nullability condition <$> aggregate
93+ runTag nullity condition <$> aggregate
98 where
94 where
99 condition = test expr
95 condition = test expr
100
96
101− unnullifier SSpec {nullability} (Aggregation aggregate) =
97+ unnullifier SSpec {nullity} (Aggregation aggregate) =
102− Aggregation $ unnull nullability <$> aggregate
98+ Aggregation $ unnull nullity <$> aggregate
103
99
104 {-# INLINABLE encodeTag #-}
100 {-# INLINABLE encodeTag #-}
105 {-# INLINABLE decodeTag #-}
101 {-# INLINABLE decodeTag #-}
@@ -110,9 +106,9 @@ instance Nullifiable Aggregate where
110instance Nullifiable Expr where
106instance Nullifiable Expr where
111 encodeTag Tag {expr} = DB expr
107 encodeTag Tag {expr} = DB expr
112 decodeTag (DB a) = fromExpr a
108 decodeTag (DB a) = fromExpr a
113− nullifier Tag {expr} test SSpec {nullability} (DB a) =
109+ nullifier Tag {expr} test SSpec {nullity} (DB a) =
114− DB $ runTag nullability (test expr) a
110+ DB $ runTag nullity (test expr) a
115− unnullifier SSpec {nullability} (DB a) = DB $ unnull nullability a
111+ unnullifier SSpec {nullity} (DB a) = DB $ unnull nullity a
116
112
117 {-# INLINABLE encodeTag #-}
113 {-# INLINABLE encodeTag #-}
118 {-# INLINABLE decodeTag #-}
114 {-# INLINABLE decodeTag #-}
@@ -132,18 +128,18 @@ instance Nullifiable Name where
132 {-# INLINABLE unnullifier #-}
128 {-# INLINABLE unnullifier #-}
133
129
134
130
135−runTag :: Nullability a -> Expr Bool -> Expr a -> Expr (Nullify a)
131+runTag :: Nullity a -> Expr Bool -> Expr a -> Expr (Nullify a)
136−runTag nullability tag a = case nullability of
132+runTag nullity tag a = case nullity of
137− Nullable -> boolExpr null a tag
133+ Null -> boolExpr null a tag
138− NonNullable -> boolExpr null (nullify a) tag
134+ NotNull -> boolExpr null (nullify a) tag
139 where
135 where
140 null = fromPrimExpr $ Opaleye.ConstExpr Opaleye.NullLit
136 null = fromPrimExpr $ Opaleye.ConstExpr Opaleye.NullLit
141
137
142
138
143−unnull :: Nullability a -> Expr (Nullify a) -> Expr a
139+unnull :: Nullity a -> Expr (Nullify a) -> Expr a
144−unnull nullability a = case nullability of
140+unnull nullity a = case nullity of
145− Nullable -> a
141+ Null -> a
146− NonNullable -> unsafeUnnullify a
142+ NotNull -> unsafeUnnullify a
147
143
148
144
149type HNullifiable :: K.HContext -> Constraint
145type HNullifiable :: K.HContext -> Constraint
@@ -187,15 +183,15 @@ instance HNullifiable (Dict (ConstrainDBType constraint)) where
187 hdecodeTag = mempty
183 hdecodeTag = mempty
188
184
189 hnullifier _ _ SSpec {} dict = case dbTypeDict dict of
185 hnullifier _ _ SSpec {} dict = case dbTypeDict dict of
190− Dict -> case dbTypeNullability dict of
186+ Dict -> case dbTypeNullity dict of
191− Nullable -> Dict
187+ Null -> Dict
192− NonNullable -> Dict
188+ NotNull -> Dict
193−
189+
194− hunnullifier SSpec {nullability} dict = case dbTypeDict dict of
190+ hunnullifier SSpec {nullity} dict = case dbTypeDict dict of
195− Dict -> case nullability of
191+ Dict -> case nullity of
196− Nullable -> Dict
192+ Null -> Dict
197− NonNullable -> case dbTypeNullability dict of
193+ NotNull -> case dbTypeNullity dict of
198− Nullable -> fromNullabilityDict nullability Dict
194+ Null -> fromNullityDict nullity Dict
199
195
200
196
201type DefaultConstrainTag :: Type -> Constraint
197type DefaultConstrainTag :: Type -> Constraint
src/Rel8/Schema/HTable/Nullify.hs+7−10
@@ -26,13 +26,10 @@ where
26import Prelude hiding ( null )
26import Prelude hiding ( null )
27
27
28-- rel8
28-- rel8
29−import Rel8.Schema.HTable
30− ( HTable
31− , hfield, htabulate, htabulateA, hspecs
29+import Rel8.Schema.HTable ( HTable, hfield, htabulate, htabulateA, hspecs )
32− )
33import qualified Rel8.Schema.Kind as K
30import qualified Rel8.Schema.Kind as K
34−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
31+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
35−import qualified Rel8.Schema.Nullability as Type ( Nullify )
32+import qualified Rel8.Schema.Null as Type ( Nullify )
36import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
33import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
37
34
38-- semigroupoids
35-- semigroupoids
@@ -59,13 +56,13 @@ type instance Eval (Nullify ('Spec labels necessity a)) =
59
56
60instance MapSpec Nullify where
57instance MapSpec Nullify where
61 mapInfo = \case
58 mapInfo = \case
62− SSpec{labels, necessity, info, nullability} -> SSpec
59+ SSpec{labels, necessity, info, nullity} -> SSpec
63 { labels
60 { labels
64 , necessity
61 , necessity
65 , info
62 , info
66− , nullability = case nullability of
63+ , nullity = case nullity of
67− Nullable -> Nullable
64+ Null -> Null
68− NonNullable -> Nullable
65+ NotNull -> Null
69 }
66 }
70
67
71
68
src/Rel8/Schema/HTable/Type.hs+2−2
@@ -23,7 +23,7 @@ import Rel8.Schema.HTable
23 , hfield, htabulate, htraverse, hdicts, hspecs
23 , hfield, htabulate, htraverse, hdicts, hspecs
24 )
24 )
25import qualified Rel8.Schema.Kind as K
25import qualified Rel8.Schema.Kind as K
26−import Rel8.Schema.Nullability ( Sql, nullabilization )
26+import Rel8.Schema.Null ( Sql, nullable )
27import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
27import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
28import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type ( DBType, typeInformation )
29
29
@@ -51,7 +51,7 @@ instance Sql DBType a => HTable (HType a) where
51 { labels = SLabel Proxy
51 { labels = SLabel Proxy
52 , necessity = SRequired
52 , necessity = SRequired
53 , info = typeInformation
53 , info = typeInformation
54− , nullability = nullabilization
54+ , nullity = nullable
55 }
55 }
56
56
57 {-# INLINABLE hfield #-}
57 {-# INLINABLE hfield #-}
src/Rel8/Schema/HTable/Vectorize.hs+9−13
@@ -40,11 +40,7 @@ import Rel8.Schema.HTable
40 ( HTable
40 ( HTable
41 , hfield, htabulate, htabulateA, hspecs
41 , hfield, htabulate, htabulateA, hspecs
42 )
42 )
43−import Rel8.Schema.Nullability
43+import Rel8.Schema.Null ( Unnullify, NotNull, Nullity( NotNull ) )
44− ( Unnullify
45− , NotNull
46− , Nullability( NonNullable )
47− )
48import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
44import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
49import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
45import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
50import Rel8.Type.Information ( TypeInformation )
46import Rel8.Type.Information ( TypeInformation )
@@ -59,7 +55,7 @@ import GHC.Generics (Generic)
59class Vector list where
55class Vector list where
60 listNotNull :: proxy a -> Dict NotNull (list a)
56 listNotNull :: proxy a -> Dict NotNull (list a)
61 vectorTypeInformation :: ()
57 vectorTypeInformation :: ()
62− => Nullability a
58+ => Nullity a
63 -> TypeInformation (Unnullify a)
59 -> TypeInformation (Unnullify a)
64 -> TypeInformation (list a)
60 -> TypeInformation (list a)
65
61
@@ -88,10 +84,10 @@ type instance Eval (Vectorize list ('Spec labels necessity a)) = 'Spec labels ne
88
84
89instance Vector list => MapSpec (Vectorize list) where
85instance Vector list => MapSpec (Vectorize list) where
90 mapInfo = \case
86 mapInfo = \case
91− SSpec {..} -> case listNotNull @list nullability of
87+ SSpec {..} -> case listNotNull @list nullity of
92 Dict -> SSpec
88 Dict -> SSpec
93− { nullability = NonNullable
89+ { nullity = NotNull
94− , info = vectorTypeInformation nullability info
90+ , info = vectorTypeInformation nullity info
95 , ..
91 , ..
96 }
92 }
97
93
@@ -125,7 +121,7 @@ hunvectorize unvectorizer (HVectorize table) =
125
121
126happend :: (HTable t, Vector list) =>
122happend :: (HTable t, Vector list) =>
127 ( forall labels necessity a. ()
123 ( forall labels necessity a. ()
128− => Nullability a
124+ => Nullity a
129 -> TypeInformation (Unnullify a)
125 -> TypeInformation (Unnullify a)
130 -> context ('Spec labels necessity (list a))
126 -> context ('Spec labels necessity (list a))
131 -> context ('Spec labels necessity (list a))
127 -> context ('Spec labels necessity (list a))
@@ -137,18 +133,18 @@ happend :: (HTable t, Vector list) =>
137happend append (HVectorize as) (HVectorize bs) = HVectorize $
133happend append (HVectorize as) (HVectorize bs) = HVectorize $
138 htabulate $ \field@(HMapTableField j) -> case (hfield as field, hfield bs field) of
134 htabulate $ \field@(HMapTableField j) -> case (hfield as field, hfield bs field) of
139 (a, b) -> case hfield hspecs j of
135 (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
141
137
142
138
143hempty :: HTable t =>
139hempty :: HTable t =>
144 ( forall labels necessity a. ()
140 ( forall labels necessity a. ()
145− => Nullability a
141+ => Nullity a
146 -> TypeInformation (Unnullify a)
142 -> TypeInformation (Unnullify a)
147 -> context ('Spec labels necessity [a])
143 -> context ('Spec labels necessity [a])
148 )
144 )
149 -> HVectorize [] t context
145 -> HVectorize [] t context
150hempty empty = HVectorize $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
146hempty empty = HVectorize $ htabulate $ \(HMapTableField field) -> case hfield hspecs field of
151− SSpec {nullability, info} -> empty nullability info
147+ SSpec {nullity, info} -> empty nullity info
152
148
153
149
154instance HLabelable g => HLabelable (Precompose (Vectorize list) g) where
150instance HLabelable g => HLabelable (Precompose (Vectorize list) g) where
src/Rel8/Schema/Insert.hs+8−8
@@ -38,8 +38,8 @@ import Rel8.Schema.Context.Nullify
38import Rel8.Schema.HTable.Type ( HType(HType) )
38import Rel8.Schema.HTable.Type ( HType(HType) )
39import qualified Rel8.Schema.Kind as K
39import qualified Rel8.Schema.Kind as K
40import Rel8.Schema.Name ( Name, Selects )
40import Rel8.Schema.Name ( Name, Selects )
41−import Rel8.Schema.Nullability ( Sql )
41+import Rel8.Schema.Null ( Sql )
42−import Rel8.Schema.Spec ( SSpec(SSpec, nullability), Spec(Spec) )
42+import Rel8.Schema.Spec ( SSpec(SSpec, nullity), Spec(Spec) )
43import Rel8.Schema.Table ( TableSchema )
43import Rel8.Schema.Table ( TableSchema )
44import Rel8.Statement.Returning ( Returning )
44import Rel8.Statement.Returning ( Returning )
45import Rel8.Table ( Table(..) )
45import Rel8.Table ( Table(..) )
@@ -135,17 +135,17 @@ instance Nullifiable Insert where
135 encodeTag = RequiredInsert . expr
135 encodeTag = RequiredInsert . expr
136 decodeTag (RequiredInsert a) = fromExpr a
136 decodeTag (RequiredInsert a) = fromExpr a
137
137
138− nullifier Tag {expr} test SSpec {nullability} = \case
138+ nullifier Tag {expr} test SSpec {nullity} = \case
139 RequiredInsert a ->
139 RequiredInsert a ->
140− RequiredInsert $ runTag nullability condition a
140+ RequiredInsert $ runTag nullity condition a
141 OptionalInsert ma ->
141 OptionalInsert ma ->
142− OptionalInsert $ runTag nullability condition <$> ma
142+ OptionalInsert $ runTag nullity condition <$> ma
143 where
143 where
144 condition = test expr
144 condition = test expr
145
145
146− unnullifier SSpec {nullability} = \case
146+ unnullifier SSpec {nullity} = \case
147− RequiredInsert a -> RequiredInsert $ unnull nullability a
147+ RequiredInsert a -> RequiredInsert $ unnull nullity a
148− OptionalInsert ma -> OptionalInsert $ unnull nullability <$> ma
148+ OptionalInsert ma -> OptionalInsert $ unnull nullity <$> ma
149
149
150 {-# INLINABLE encodeTag #-}
150 {-# INLINABLE encodeTag #-}
151 {-# INLINABLE decodeTag #-}
151 {-# INLINABLE decodeTag #-}
src/Rel8/Schema/Name.hs+1−1
@@ -29,7 +29,7 @@ import Rel8.Schema.Context ( Interpretation, Col )
29import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
29import Rel8.Schema.Context.Label ( Labelable, labeler, unlabeler )
30import Rel8.Schema.HTable.Type ( HType( HType ) )
30import Rel8.Schema.HTable.Type ( HType( HType ) )
31import qualified Rel8.Schema.Kind as K
31import qualified Rel8.Schema.Kind as K
32−import Rel8.Schema.Nullability ( Sql )
32+import Rel8.Schema.Null ( Sql )
33import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
33import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
34import Rel8.Table.Recontextualize ( Recontextualize )
34import Rel8.Table.Recontextualize ( Recontextualize )
35import Rel8.Type ( DBType )
35import Rel8.Type ( DBType )
src/Rel8/Schema/Nullability.hs → src/Rel8/Schema/Null.hsrenamed+30−30
@@ -10,12 +10,12 @@
10{-# language UndecidableInstances #-}
10{-# language UndecidableInstances #-}
11{-# language UndecidableSuperClasses #-}
11{-# language UndecidableSuperClasses #-}
12
12
13−module Rel8.Schema.Nullability
13+module Rel8.Schema.Null
14 ( Nullify, Unnullify
14 ( Nullify, Unnullify
15 , NotNull
15 , NotNull
16 , Homonullable
16 , Homonullable
17− , Nullability( Nullable, NonNullable )
17+ , Nullity( Null, NotNull )
18− , HasNullability, nullabilization
18+ , Nullable, nullable
19 , Sql, fromSql, mapSql, toSql
19 , Sql, fromSql, mapSql, toSql
20 )
20 )
21where
21where
@@ -56,8 +56,8 @@ type Nullify a = Maybe (Unnullify a)
56
56
57-- | @nullify a@ means @a@ cannot take @null@ as a value.
57-- | @nullify a@ means @a@ cannot take @null@ as a value.
58type NotNull :: Type -> Constraint
58type NotNull :: Type -> Constraint
59−class (HasNullability a, IsMaybe a ~ 'False) => NotNull a
59+class (Nullable a, IsMaybe a ~ 'False) => NotNull a
60−instance (HasNullability a, IsMaybe a ~ 'False) => NotNull a
60+instance (Nullable a, IsMaybe a ~ 'False) => NotNull a
61
61
62
62
63-- | @Homonullable a b@ means that both @a@ and @b@ can be @null@, or neither
63-- | @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
67instance IsMaybe a ~ IsMaybe b => Homonullable a b
67instance IsMaybe a ~ IsMaybe b => Homonullable a b
68
68
69
69
70−type Nullability :: Type -> Type
70+type Nullity :: Type -> Type
71−data Nullability a where
71+data Nullity a where
72− NonNullable :: NotNull a => Nullability a
72+ NotNull :: NotNull a => Nullity a
73− Nullable :: NotNull a => Nullability (Maybe a)
73+ Null :: NotNull a => Nullity (Maybe a)
74
74
75
75
76−type HasNullability' :: Bool -> Type -> Constraint
76+type Nullable' :: Bool -> Type -> Constraint
77class
77class
78 ( IsMaybe a ~ isMaybe
78 ( IsMaybe a ~ isMaybe
79 , IsMaybe (Unnullify a) ~ 'False
79 , IsMaybe (Unnullify a) ~ 'False
80 , Nullify' isMaybe (Unnullify a) ~ a
80 , Nullify' isMaybe (Unnullify a) ~ a
81− ) => HasNullability' isMaybe a
81+ ) => Nullable' isMaybe a
82 where
82 where
83− nullabilization' :: Nullability a
83+ nullable' :: Nullity a
84
84
85
85
86−instance IsMaybe a ~ 'False => HasNullability' 'False a where
86+instance IsMaybe a ~ 'False => Nullable' 'False a where
87− nullabilization' = NonNullable
87+ nullable' = NotNull
88
88
89
89
90−instance IsMaybe a ~ 'False => HasNullability' 'True (Maybe a) where
90+instance IsMaybe a ~ 'False => Nullable' 'True (Maybe a) where
91− nullabilization' = Nullable
91+ nullable' = Null
92
92
93
93
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
95-- type that can take @null@ values or not.
95-- type that can take @null@ values or not.
96−type HasNullability :: Type -> Constraint
96+type Nullable :: Type -> Constraint
97−class HasNullability' (IsMaybe a) a => HasNullability a
97+class Nullable' (IsMaybe a) a => Nullable a
98−instance HasNullability' (IsMaybe a) a => HasNullability a
98+instance Nullable' (IsMaybe a) a => Nullable a
99
99
100
100
101−nullabilization :: HasNullability a => Nullability a
101+nullable :: Nullable a => Nullity a
102−nullabilization = nullabilization'
102+nullable = nullable'
103
103
104
104
105-- | The @Sql@ type class describes both null and not null database values,
105-- | The @Sql@ type class describes both null and not null database values,
@@ -109,12 +109,12 @@ nullabilization = nullabilization'
109-- supports equality, and @a@ can either be exactly an @a@, or it could also be
109-- supports equality, and @a@ can either be exactly an @a@, or it could also be
110-- @Maybe a@.
110-- @Maybe a@.
111type Sql :: (Type -> Constraint) -> Type -> Constraint
111type Sql :: (Type -> Constraint) -> Type -> Constraint
112−class (constraint (Unnullify a), HasNullability a) => Sql constraint a
112+class (constraint (Unnullify a), Nullable a) => Sql constraint a
113−instance (constraint (Unnullify a), HasNullability a) => Sql constraint a
113+instance (constraint (Unnullify a), Nullable a) => Sql constraint a
114
114
115
115
116−fromSql :: Dict (Sql constraint) a -> (Nullability a, Dict constraint (Unnullify a))
116+fromSql :: Dict (Sql constraint) a -> (Nullity a, Dict constraint (Unnullify a))
117−fromSql Dict = (nullabilization, Dict)
117+fromSql Dict = (nullable, Dict)
118{-# INLINABLE fromSql #-}
118{-# INLINABLE fromSql #-}
119
119
120
120
@@ -122,10 +122,10 @@ mapSql :: ()
122 => (forall x. Dict constraint x -> Dict constraint' x)
122 => (forall x. Dict constraint x -> Dict constraint' x)
123 -> Dict (Sql constraint) a -> Dict (Sql constraint') a
123 -> Dict (Sql constraint) a -> Dict (Sql constraint') a
124mapSql f dict = case fromSql dict of
124mapSql f dict = case fromSql dict of
125− (nullability, dict') -> toSql nullability (f dict')
125+ (nullity, dict') -> toSql nullity (f dict')
126
126
127
127
128−toSql :: Nullability a -> Dict constraint (Unnullify a) -> Dict (Sql constraint) a
128+toSql :: Nullity a -> Dict constraint (Unnullify a) -> Dict (Sql constraint) a
129−toSql NonNullable Dict = Dict
129+toSql NotNull Dict = Dict
130−toSql Nullable Dict = Dict
130+toSql Null Dict = Dict
131{-# INLINABLE toSql #-}
131{-# INLINABLE toSql #-}
src/Rel8/Schema/Spec.hs+4−4
@@ -6,7 +6,7 @@
6
6
7module Rel8.Schema.Spec
7module Rel8.Schema.Spec
8 ( Spec( Spec )
8 ( Spec( Spec )
9− , SSpec( SSpec, labels, necessity, info, nullability )
9+ , SSpec( SSpec, labels, necessity, info, nullity )
10 , KnownSpec( specSing )
10 , KnownSpec( specSing )
11 , KContext, HKTable
11 , KContext, HKTable
12 , KTable
12 , KTable
@@ -24,7 +24,7 @@ import Rel8.Kind.Necessity
24 , SNecessity
24 , SNecessity
25 , KnownNecessity, necessitySing
25 , KnownNecessity, necessitySing
26 )
26 )
27−import Rel8.Schema.Nullability ( Nullability, Sql, Unnullify, nullabilization )
27+import Rel8.Schema.Null ( Nullity, Sql, Unnullify, nullable )
28import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type ( DBType, typeInformation )
29import Rel8.Type.Information ( TypeInformation )
29import Rel8.Type.Information ( TypeInformation )
30
30
@@ -39,7 +39,7 @@ data SSpec spec where
39 { labels :: SLabels labels
39 { labels :: SLabels labels
40 , necessity :: SNecessity necessity
40 , necessity :: SNecessity necessity
41 , info :: TypeInformation (Unnullify a)
41 , info :: TypeInformation (Unnullify a)
42− , nullability :: Nullability a
42+ , nullity :: Nullity a
43 }
43 }
44 -> SSpec ('Spec labels necessity a)
44 -> SSpec ('Spec labels necessity a)
45
45
@@ -60,7 +60,7 @@ instance
60 { labels = labelsSing
60 { labels = labelsSing
61 , necessity = necessitySing
61 , necessity = necessitySing
62 , info = typeInformation
62 , info = typeInformation
63− , nullability = nullabilization
63+ , nullity = nullable
64 }
64 }
65
65
66
66
src/Rel8/Schema/Spec/ConstrainDBType.hs+9−13
@@ -9,9 +9,9 @@
9
9
10module Rel8.Schema.Spec.ConstrainDBType
10module Rel8.Schema.Spec.ConstrainDBType
11 ( ConstrainDBType
11 ( ConstrainDBType
12− , dbTypeNullability
12+ , dbTypeNullity
13 , dbTypeDict
13 , dbTypeDict
14− , fromNullabilityDict
14+ , fromNullityDict
15 )
15 )
16where
16where
17
17
@@ -21,11 +21,7 @@ import Prelude
21
21
22-- rel8
22-- rel8
23import Rel8.Schema.Dict ( Dict( Dict ) )
23import Rel8.Schema.Dict ( Dict( Dict ) )
24−import Rel8.Schema.Nullability
24+import Rel8.Schema.Null ( Unnullify, Nullity, Sql, nullable, toSql )
25− ( Unnullify
26− , Nullability
27− , Sql, nullabilization, toSql
28− )
29import Rel8.Schema.Spec ( Spec( Spec ) )
25import Rel8.Schema.Spec ( Spec( Spec ) )
30
26
31
27
@@ -43,14 +39,14 @@ instance
43 => ConstrainDBType constraint spec
39 => ConstrainDBType constraint spec
44
40
45
41
46−dbTypeNullability :: Dict (ConstrainDBType c) ('Spec l n a) -> Nullability a
42+dbTypeNullity :: Dict (ConstrainDBType c) ('Spec l n a) -> Nullity a
47−dbTypeNullability = step2 . step1
43+dbTypeNullity = step2 . step1
48 where
44 where
49 step1 :: Dict (ConstrainDBType c) ('Spec l n a) -> Dict (Sql c) a
45 step1 :: Dict (ConstrainDBType c) ('Spec l n a) -> Dict (Sql c) a
50 step1 Dict = Dict
46 step1 Dict = Dict
51
47
52− step2 :: Dict (Sql c) a -> Nullability a
48+ step2 :: Dict (Sql c) a -> Nullity a
53− step2 Dict = nullabilization
49+ step2 Dict = nullable
54
50
55
51
56dbTypeDict :: Dict (ConstrainDBType c) ('Spec l n a) -> Dict c (Unnullify a)
52dbTypeDict :: Dict (ConstrainDBType c) ('Spec l n a) -> Dict c (Unnullify a)
@@ -63,8 +59,8 @@ dbTypeDict = step2 . step1
63 step2 Dict = Dict
59 step2 Dict = Dict
64
60
65
61
66−fromNullabilityDict :: Nullability a -> Dict c (Unnullify a) -> Dict (ConstrainDBType c) ('Spec l n a)
62+fromNullityDict :: Nullity a -> Dict c (Unnullify a) -> Dict (ConstrainDBType c) ('Spec l n a)
67−fromNullabilityDict nullability = step2 . toSql nullability
63+fromNullityDict nullity = step2 . toSql nullity
68 where
64 where
69 step2 :: Dict (Sql c) a -> Dict (ConstrainDBType c) ('Spec l n a)
65 step2 :: Dict (Sql c) a -> Dict (ConstrainDBType c) ('Spec l n a)
70 step2 Dict = Dict
66 step2 Dict = Dict
src/Rel8/Table.hs+1−1
@@ -31,7 +31,7 @@ import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
31import Rel8.Schema.HTable.Trio ( HTrio(..) )
31import Rel8.Schema.HTable.Trio ( HTrio(..) )
32import Rel8.Schema.HTable.Type ( HType( HType ) )
32import Rel8.Schema.HTable.Type ( HType( HType ) )
33import qualified Rel8.Schema.Kind as K
33import qualified Rel8.Schema.Kind as K
34−import Rel8.Schema.Nullability ( Sql )
34+import Rel8.Schema.Null ( Sql )
35import Rel8.Schema.Spec ( KnownSpec )
35import Rel8.Schema.Spec ( KnownSpec )
36import Rel8.Type ( DBType )
36import Rel8.Type ( DBType )
37
37
src/Rel8/Table/Eq.hs+1−1
@@ -40,10 +40,10 @@ import Rel8.Schema.HTable.Pair ( HPair(..) )
40import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
40import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
41import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
41import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
42import Rel8.Schema.HTable.Trio ( HTrio(..) )
42import Rel8.Schema.HTable.Trio ( HTrio(..) )
43+import Rel8.Schema.Null ( Sql )
43import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
44import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
44import Rel8.Table ( Table, Columns, toColumns )
45import Rel8.Table ( Table, Columns, toColumns )
45import Rel8.Type.Eq ( DBEq )
46import Rel8.Type.Eq ( DBEq )
46−import Rel8.Schema.Nullability ( Sql )
47
47
48
48
49-- | The class of 'Table's that can be compared for equality. Equality on
49-- | 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 )
25import Rel8.Schema.Dict ( Dict( Dict ) )
25import Rel8.Schema.Dict ( Dict( Dict ) )
26import Rel8.Schema.HTable.List ( HListTable )
26import Rel8.Schema.HTable.List ( HListTable )
27import Rel8.Schema.HTable.Vectorize ( happend, hempty, hvectorize )
27import Rel8.Schema.HTable.Vectorize ( happend, hempty, hvectorize )
28−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
28+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
29import Rel8.Schema.Spec ( SSpec(..) )
29import Rel8.Schema.Spec ( SSpec(..) )
30−import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
30+import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullity )
31import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
31import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
32import Rel8.Table.Alternative
32import Rel8.Table.Alternative
33 ( AltTable, (<|>:)
33 ( AltTable, (<|>:)
@@ -60,9 +60,9 @@ instance EqTable a => EqTable (ListTable a) where
60 eqTable =
60 eqTable =
61 hvectorize
61 hvectorize
62 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
62 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
63− Dict -> case dbTypeNullability dict of
63+ Dict -> case dbTypeNullity dict of
64− Nullable -> Dict
64+ Null -> Dict
65− NonNullable -> Dict)
65+ NotNull -> Dict)
66 (Identity (eqTable @a))
66 (Identity (eqTable @a))
67
67
68
68
@@ -70,9 +70,9 @@ instance OrdTable a => OrdTable (ListTable a) where
70 ordTable =
70 ordTable =
71 hvectorize
71 hvectorize
72 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
72 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
73− Dict -> case dbTypeNullability dict of
73+ Dict -> case dbTypeNullity dict of
74− Nullable -> Dict
74+ Null -> Dict
75− NonNullable -> Dict)
75+ NotNull -> Dict)
76 (Identity (ordTable @a))
76 (Identity (ordTable @a))
77
77
78
78
src/Rel8/Table/Maybe.hs+4−8
@@ -43,11 +43,7 @@ import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
43import Rel8.Schema.HTable.Maybe ( HMaybeTable(..), HMaybeNullifiable )
43import Rel8.Schema.HTable.Maybe ( HMaybeTable(..), HMaybeNullifiable )
44import Rel8.Schema.HTable.Nullify ( hnullify, hunnullify )
44import Rel8.Schema.HTable.Nullify ( hnullify, hunnullify )
45import Rel8.Schema.Name ( Name )
45import Rel8.Schema.Name ( Name )
46−import Rel8.Schema.Nullability
46+import Rel8.Schema.Null ( Nullify, Nullity( Null, NotNull ), Sql, nullable )
47− ( Nullify
48− , Nullability( Nullable, NonNullable )
49− , Sql, nullabilization
50− )
51import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
47import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
52import Rel8.Table.Alternative
48import Rel8.Table.Alternative
53 ( AltTable, (<|>:)
49 ( AltTable, (<|>:)
@@ -214,9 +210,9 @@ justTable = MaybeTable (fromExpr mempty)
214-- @null@.
210-- @null@.
215($?) :: forall a b. Sql DBType b
211($?) :: forall a b. Sql DBType b
216 => (a -> Expr b) -> MaybeTable a -> Expr (Nullify b)
212 => (a -> Expr b) -> MaybeTable a -> Expr (Nullify b)
217−f $? ma@(MaybeTable _ a) = case nullabilization @b of
213+f $? ma@(MaybeTable _ a) = case nullable @b of
218− Nullable -> boolExpr (f a) null (isNothingTable ma)
214+ Null -> boolExpr (f a) null (isNothingTable ma)
219− NonNullable -> boolExpr (nullify (f a)) null (isNothingTable ma)
215+ NotNull -> boolExpr (nullify (f a)) null (isNothingTable ma)
220infixl 4 $?
216infixl 4 $?
221
217
222
218
src/Rel8/Table/NonEmpty.hs+8−8
@@ -27,9 +27,9 @@ import Rel8.Expr.Array ( sappend1, snonEmptyOf )
27import Rel8.Schema.Dict ( Dict( Dict ) )
27import Rel8.Schema.Dict ( Dict( Dict ) )
28import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
28import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
29import Rel8.Schema.HTable.Vectorize ( happend, hvectorize )
29import Rel8.Schema.HTable.Vectorize ( happend, hvectorize )
30−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
30+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
31import Rel8.Schema.Spec ( SSpec(..) )
31import Rel8.Schema.Spec ( SSpec(..) )
32−import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
32+import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullity )
33import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
33import Rel8.Table ( Table, Context, Columns, fromColumns, toColumns )
34import Rel8.Table.Alternative ( AltTable, (<|>:) )
34import Rel8.Table.Alternative ( AltTable, (<|>:) )
35import Rel8.Table.Eq ( EqTable, eqTable )
35import Rel8.Table.Eq ( EqTable, eqTable )
@@ -60,9 +60,9 @@ instance EqTable a => EqTable (NonEmptyTable a) where
60 eqTable =
60 eqTable =
61 hvectorize
61 hvectorize
62 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
62 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
63− Dict -> case dbTypeNullability dict of
63+ Dict -> case dbTypeNullity dict of
64− Nullable -> Dict
64+ Null -> Dict
65− NonNullable -> Dict)
65+ NotNull -> Dict)
66 (Identity (eqTable @a))
66 (Identity (eqTable @a))
67
67
68
68
@@ -70,9 +70,9 @@ instance OrdTable a => OrdTable (NonEmptyTable a) where
70 ordTable =
70 ordTable =
71 hvectorize
71 hvectorize
72 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
72 (\SSpec {} (Identity dict) -> case dbTypeDict dict of
73− Dict -> case dbTypeNullability dict of
73+ Dict -> case dbTypeNullity dict of
74− Nullable -> Dict
74+ Null -> Dict
75− NonNullable -> Dict)
75+ NotNull -> Dict)
76 (Identity (ordTable @a))
76 (Identity (ordTable @a))
77
77
78
78
src/Rel8/Table/Ord.hs+1−1
@@ -37,13 +37,13 @@ import Rel8.Schema.HTable.Pair ( HPair(..) )
37import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
37import Rel8.Schema.HTable.Quartet ( HQuartet(..) )
38import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
38import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
39import Rel8.Schema.HTable.Trio ( HTrio(..) )
39import Rel8.Schema.HTable.Trio ( HTrio(..) )
40+import Rel8.Schema.Null (Sql)
40import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
41import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
41import Rel8.Table ( Table, Columns, toColumns )
42import Rel8.Table ( Table, Columns, toColumns )
42import Rel8.Table.Bool ( bool )
43import Rel8.Table.Bool ( bool )
43import Rel8.Table.Eq ( EqTable )
44import Rel8.Table.Eq ( EqTable )
44import Rel8.Type.Eq ( DBEq )
45import Rel8.Type.Eq ( DBEq )
45import Rel8.Type.Ord ( DBOrd )
46import Rel8.Type.Ord ( DBOrd )
46−import Rel8.Schema.Nullability (Sql)
47
47
48
48
49-- | The class of 'Table's that can be ordered. Ordering on tables is defined
49-- | 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 )
20import Rel8.Order ( Order )
20import Rel8.Order ( Order )
21import Rel8.Schema.Dict ( Dict( Dict ) )
21import Rel8.Schema.Dict ( Dict( Dict ) )
22import Rel8.Schema.HTable (htabulateA, hfield, hspecs)
22import Rel8.Schema.HTable (htabulateA, hfield, hspecs)
23−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
23+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
24import Rel8.Schema.Spec ( SSpec( SSpec ) )
24import Rel8.Schema.Spec ( SSpec( SSpec ) )
25−import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullability )
25+import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullity )
26−import Rel8.Table
26+import Rel8.Table ( Columns, toColumns )
27import Rel8.Table.Ord
27import Rel8.Table.Ord
28
28
29
29
@@ -35,9 +35,9 @@ ascTable = contramap toColumns $ getConst $
35 SSpec {} -> case hfield (ordTable @a) field of
35 SSpec {} -> case hfield (ordTable @a) field of
36 dict@Dict -> case dbTypeDict dict of
36 dict@Dict -> case dbTypeDict dict of
37 Dict -> Const $ unDB . (`hfield` field) >$<
37 Dict -> Const $ unDB . (`hfield` field) >$<
38− case dbTypeNullability dict of
38+ case dbTypeNullity dict of
39− Nullable -> nullsFirst asc
39+ Null -> nullsFirst asc
40− NonNullable -> asc
40+ NotNull -> asc
41
41
42
42
43-- | Construct an 'Order' for a 'Table' by sorting all columns into descending
43-- | Construct an 'Order' for a 'Table' by sorting all columns into descending
@@ -48,6 +48,6 @@ descTable = contramap toColumns $ getConst $
48 SSpec {} -> case hfield (ordTable @a) field of
48 SSpec {} -> case hfield (ordTable @a) field of
49 dict@Dict -> case dbTypeDict dict of
49 dict@Dict -> case dbTypeDict dict of
50 Dict -> Const $ unDB . (`hfield` field) >$<
50 Dict -> Const $ unDB . (`hfield` field) >$<
51− case dbTypeNullability dict of
51+ case dbTypeNullity dict of
52− Nullable -> nullsLast desc
52+ Null -> nullsLast desc
53− NonNullable -> desc
53+ NotNull -> desc
src/Rel8/Table/Recontextualize.hs+1−1
@@ -21,7 +21,7 @@ import Rel8.Schema.Context ( Col )
21import Rel8.Schema.Context.Label ( Labelable )
21import Rel8.Schema.Context.Label ( Labelable )
22import Rel8.Schema.HTable ( HTable )
22import Rel8.Schema.HTable ( HTable )
23import qualified Rel8.Schema.Kind as K
23import qualified Rel8.Schema.Kind as K
24−import Rel8.Schema.Nullability ( Sql )
24+import Rel8.Schema.Null ( Sql )
25import Rel8.Table ( Table, Congruent )
25import Rel8.Table ( Table, Congruent )
26import Rel8.Type ( DBType )
26import Rel8.Type ( DBType )
27
27
src/Rel8/Table/Serialize.hs+4−4
@@ -46,7 +46,7 @@ import Rel8.Schema.HTable.Quintet ( HQuintet(..) )
46import Rel8.Schema.HTable.Pair ( HPair(..) )
46import Rel8.Schema.HTable.Pair ( HPair(..) )
47import Rel8.Schema.HTable.Trio ( HTrio(..) )
47import Rel8.Schema.HTable.Trio ( HTrio(..) )
48import Rel8.Schema.HTable.Type ( HType(..) )
48import Rel8.Schema.HTable.Type ( HType(..) )
49−import Rel8.Schema.Nullability ( NotNull, Sql )
49+import Rel8.Schema.Null ( NotNull, Sql )
50import Rel8.Schema.Spec ( SSpec(..), KnownSpec )
50import Rel8.Schema.Spec ( SSpec(..), KnownSpec )
51import Rel8.Table ( Table, Columns, fromColumns, toColumns )
51import Rel8.Table ( Table, Columns, fromColumns, toColumns )
52import Rel8.Table.Either ( EitherTable )
52import Rel8.Table.Either ( EitherTable )
@@ -338,11 +338,11 @@ litTable = lit
338litHTable :: HTable t => t (Col Identity) -> t (Col Expr)
338litHTable :: HTable t => t (Col Identity) -> t (Col Expr)
339litHTable as = htabulate $ \field ->
339litHTable as = htabulate $ \field ->
340 case hfield hspecs field of
340 case hfield hspecs field of
341− SSpec {nullability, info} -> case hfield as field of
341+ SSpec {nullity, info} -> case hfield as field of
342− Result value -> DB (slitExpr nullability info value)
342+ Result value -> DB (slitExpr nullity info value)
343
343
344
344
345parseHTable :: HTable t => Hasql.Row (t (Col Identity))
345parseHTable :: HTable t => Hasql.Row (t (Col Identity))
346parseHTable = unwrapApplicative $ htabulateA $ \field ->
346parseHTable = unwrapApplicative $ htabulateA $ \field ->
347 WrapApplicative $ case hfield hspecs field of
347 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 )
31import Rel8.Expr.Opaleye ( fromPrimExpr )
31import Rel8.Expr.Opaleye ( fromPrimExpr )
32import Rel8.Schema.Dict ( Dict( Dict ) )
32import Rel8.Schema.Dict ( Dict( Dict ) )
33import Rel8.Schema.Name ( Name( Name ) )
33import Rel8.Schema.Name ( Name( Name ) )
34−import Rel8.Schema.Nullability ( Sql, mapSql )
34+import Rel8.Schema.Null ( Sql, mapSql )
35import Rel8.Type.Monoid ( DBMonoid )
35import Rel8.Type.Monoid ( DBMonoid )
36import Rel8.Type.Semigroup ( DBSemigroup )
36import Rel8.Type.Semigroup ( DBSemigroup )
37
37
src/Rel8/Table/Undefined.hs+4−4
@@ -14,13 +14,13 @@ import Prelude hiding ( undefined )
14import Rel8.Expr ( Expr, Col(..) )
14import Rel8.Expr ( Expr, Col(..) )
15import Rel8.Expr.Null ( snull, unsafeUnnullify )
15import Rel8.Expr.Null ( snull, unsafeUnnullify )
16import Rel8.Schema.HTable ( htabulate, hfield, hspecs )
16import Rel8.Schema.HTable ( htabulate, hfield, hspecs )
17−import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
17+import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
18import Rel8.Schema.Spec ( SSpec(..) )
18import Rel8.Schema.Spec ( SSpec(..) )
19import Rel8.Table ( Table, fromColumns )
19import Rel8.Table ( Table, fromColumns )
20
20
21
21
22undefined :: Table Expr a => a
22undefined :: Table Expr a => a
23undefined = fromColumns $ htabulate $ \field -> case hfield hspecs field of
23undefined = fromColumns $ htabulate $ \field -> case hfield hspecs field of
24− SSpec {nullability, info} -> case nullability of
24+ SSpec {nullity, info} -> case nullity of
25− Nullable -> DB (snull info)
25+ Null -> DB (snull info)
26− NonNullable -> DB (unsafeUnnullify (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
35import qualified Opaleye.Internal.HaskellDB.Sql.Default as Opaleye ( quote )
35import qualified Opaleye.Internal.HaskellDB.Sql.Default as Opaleye ( quote )
36
36
37-- rel8
37-- rel8
38−import Rel8.Schema.Nullability
38+import Rel8.Schema.Null ( NotNull, Sql, nullable )
39− ( NotNull
40− , nullabilization
41− , Sql
42− )
43import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
39import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
44import Rel8.Type.Information ( TypeInformation(..), mapTypeInformation )
40import Rel8.Type.Information ( TypeInformation(..), mapTypeInformation )
45
41
@@ -275,8 +271,8 @@ instance DBType Value where
275
271
276
272
277instance Sql DBType a => DBType [a] where
273instance Sql DBType a => DBType [a] where
278− typeInformation = listTypeInformation nullabilization typeInformation
274+ typeInformation = listTypeInformation nullable typeInformation
279
275
280
276
281instance Sql DBType a => DBType (NonEmpty a) where
277instance 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
22import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
22import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
23
23
24-- rel8
24-- rel8
25−import Rel8.Schema.Nullability ( Unnullify, Nullability( Nullable, NonNullable ) )
25+import Rel8.Schema.Null ( Unnullify, Nullity( Null, NotNull ) )
26import Rel8.Type.Information ( TypeInformation(..), parseTypeInformation )
26import Rel8.Type.Information ( TypeInformation(..), parseTypeInformation )
27
27
28
28
@@ -35,18 +35,18 @@ array TypeInformation {typeName} =
35
35
36
36
37listTypeInformation :: ()
37listTypeInformation :: ()
38− => Nullability a
38+ => Nullity a
39 -> TypeInformation (Unnullify a)
39 -> TypeInformation (Unnullify a)
40 -> TypeInformation [a]
40 -> TypeInformation [a]
41−listTypeInformation nullability info =
41+listTypeInformation nullity info =
42 case info of
42 case info of
43 TypeInformation{ encode, decode } -> TypeInformation
43 TypeInformation{ encode, decode } -> TypeInformation
44− { decode = row $ case nullability of
44+ { decode = row $ case nullity of
45− Nullable -> Hasql.listArray (Hasql.nullable decode)
45+ Null -> Hasql.listArray (Hasql.nullable decode)
46− NonNullable -> Hasql.listArray (Hasql.nonNullable decode)
46+ NotNull -> Hasql.listArray (Hasql.nonNullable decode)
47− , encode = case nullability of
47+ , encode = case nullity of
48− Nullable -> array info . fmap (maybe null encode)
48+ Null -> array info . fmap (maybe null encode)
49− NonNullable -> array info . fmap encode
49+ NotNull -> array info . fmap encode
50 , typeName = "record"
50 , typeName = "record"
51 }
51 }
52 where
52 where
@@ -55,11 +55,11 @@ listTypeInformation nullability info =
55
55
56
56
57nonEmptyTypeInformation :: ()
57nonEmptyTypeInformation :: ()
58− => Nullability a
58+ => Nullity a
59 -> TypeInformation (Unnullify a)
59 -> TypeInformation (Unnullify a)
60 -> TypeInformation (NonEmpty a)
60 -> TypeInformation (NonEmpty a)
61−nonEmptyTypeInformation nullability =
61+nonEmptyTypeInformation nullity =
62− parseTypeInformation parse toList . listTypeInformation nullability
62+ parseTypeInformation parse toList . listTypeInformation nullity
63 where
63 where
64 parse = maybe (Left message) Right . nonEmpty
64 parse = maybe (Left message) Right . nonEmpty
65 message = "failed to decode NonEmptyList: got empty list"
65 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
42-- rel8
42-- rel8
43import Rel8.Expr.Opaleye ( zipPrimExprsWith )
43import Rel8.Expr.Opaleye ( zipPrimExprsWith )
44import Rel8.Expr.Serialize ( litExpr )
44import Rel8.Expr.Serialize ( litExpr )
45−import Rel8.Schema.Nullability
45+import Rel8.Schema.Null ( Unnullify, Nullity( Null, NotNull ), Sql, nullable )
46− ( Unnullify
47− , Nullability( Nullable, NonNullable )
48− , Sql, nullabilization
49− )
50import Rel8.Type ( DBType, typeInformation )
46import Rel8.Type ( DBType, typeInformation )
51import Rel8.Type.Eq ( DBEq )
47import Rel8.Type.Eq ( DBEq )
52import Rel8.Type.Information ( TypeInformation(..) )
48import Rel8.Type.Information ( TypeInformation(..) )
@@ -94,18 +90,18 @@ type family IsArray1D a where
94
90
95
91
96array1DTypeInformation :: IsArray1D (Unnullify a) ~ 'False
92array1DTypeInformation :: IsArray1D (Unnullify a) ~ 'False
97− => Nullability a
93+ => Nullity a
98 -> TypeInformation (Unnullify a)
94 -> TypeInformation (Unnullify a)
99 -> TypeInformation (Array1D a)
95 -> TypeInformation (Array1D a)
100−array1DTypeInformation nullability info =
96+array1DTypeInformation nullity info =
101 case info of
97 case info of
102 TypeInformation{ encode, decode, typeName } -> TypeInformation
98 TypeInformation{ encode, decode, typeName } -> TypeInformation
103− { decode = case nullability of
99+ { decode = case nullity of
104− Nullable -> Array1D <$> Hasql.listArray (Hasql.nullable decode)
100+ Null -> Array1D <$> Hasql.listArray (Hasql.nullable decode)
105− NonNullable -> Array1D <$> Hasql.listArray (Hasql.nonNullable decode)
101+ NotNull -> Array1D <$> Hasql.listArray (Hasql.nonNullable decode)
106− , encode = case nullability of
102+ , encode = case nullity of
107− Nullable -> Opaleye.ArrayExpr . fmap (maybe null encode) . getArray1D
103+ Null -> Opaleye.ArrayExpr . fmap (maybe null encode) . getArray1D
108− NonNullable -> Opaleye.ArrayExpr . fmap encode . getArray1D
104+ NotNull -> Opaleye.ArrayExpr . fmap encode . getArray1D
109 , typeName = typeName <> "[]"
105 , typeName = typeName <> "[]"
110 }
106 }
111 where
107 where
@@ -113,7 +109,7 @@ array1DTypeInformation nullability info =
113
109
114
110
115instance (Sql DBType a, IsArray1D (Unnullify a) ~ 'False) => DBType (Array1D a) where
111instance (Sql DBType a, IsArray1D (Unnullify a) ~ 'False) => DBType (Array1D a) where
116− typeInformation = array1DTypeInformation nullabilization typeInformation
112+ typeInformation = array1DTypeInformation nullable typeInformation
117
113
118
114
119instance (Sql DBEq a, IsArray1D (Unnullify a) ~ 'False) => DBEq (Array1D a)
115instance (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 )
27import Data.CaseInsensitive ( CI )
27import Data.CaseInsensitive ( CI )
28
28
29-- rel8
29-- rel8
30−import Rel8.Schema.Nullability ( Sql )
30+import Rel8.Schema.Null ( Sql )
31import Rel8.Type ( DBType )
31import Rel8.Type ( DBType )
32
32
33-- scientific
33-- scientific
src/Rel8/Type/Monoid.hs+2−2
@@ -27,7 +27,7 @@ import Data.CaseInsensitive ( CI )
27import {-# SOURCE #-} Rel8.Expr ( Expr )
27import {-# SOURCE #-} Rel8.Expr ( Expr )
28import Rel8.Expr.Array ( sempty )
28import Rel8.Expr.Array ( sempty )
29import Rel8.Expr.Serialize ( litExpr )
29import Rel8.Expr.Serialize ( litExpr )
30−import Rel8.Schema.Nullability ( Sql, nullabilization )
30+import Rel8.Schema.Null ( Sql, nullable )
31import Rel8.Type ( DBType, typeInformation )
31import Rel8.Type ( DBType, typeInformation )
32import Rel8.Type.Semigroup ( DBSemigroup )
32import Rel8.Type.Semigroup ( DBSemigroup )
33
33
@@ -48,7 +48,7 @@ class DBSemigroup a => DBMonoid a where
48
48
49
49
50instance Sql DBType a => DBMonoid [a] where
50instance Sql DBType a => DBMonoid [a] where
51− memptyExpr = sempty nullabilization typeInformation
51+ memptyExpr = sempty nullable typeInformation
52
52
53
53
54instance DBMonoid CalendarDiffTime where
54instance DBMonoid CalendarDiffTime where
src/Rel8/Type/Ord.hs+1−1
@@ -25,7 +25,7 @@ import qualified Data.ByteString.Lazy as Lazy ( ByteString )
25import Data.CaseInsensitive ( CI )
25import Data.CaseInsensitive ( CI )
26
26
27-- rel8
27-- rel8
28−import Rel8.Schema.Nullability ( Sql )
28+import Rel8.Schema.Null ( Sql )
29import Rel8.Type.Eq ( DBEq )
29import Rel8.Type.Eq ( DBEq )
30
30
31-- scientific
31-- scientific
src/Rel8/Type/Semigroup.hs+1−1
@@ -29,7 +29,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
29-- rel8
29-- rel8
30import {-# SOURCE #-} Rel8.Expr ( Expr )
30import {-# SOURCE #-} Rel8.Expr ( Expr )
31import Rel8.Expr.Opaleye ( zipPrimExprsWith )
31import Rel8.Expr.Opaleye ( zipPrimExprsWith )
32−import Rel8.Schema.Nullability ( Sql )
32+import Rel8.Schema.Null ( Sql )
33import Rel8.Type ( DBType )
33import Rel8.Type ( DBType )
34
34
35-- text
35-- text
tests/Main.hs+1−1
@@ -516,7 +516,7 @@ testCatMaybe = databasePropertyTest "catMaybe" \transaction -> evalM do
516
516
517 transaction \connection -> do
517 transaction \connection -> do
518 selected <- evalM $ liftIO $ Rel8.select connection do
518 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)
520
520
521 sort selected === sort (catMaybes rows)
521 sort selected === sort (catMaybes rows)
522
522