on master help sign in
Magic Sql constraint synonym
b983defShane O'Brien
src/Rel8/Expr.hs+6−6
@@ -32,7 +32,7 @@ import Rel8.Expr.Opaleye
32import Rel8.Expr.Serialize ( litExpr )
32import Rel8.Expr.Serialize ( litExpr )
33import Rel8.Schema.Nullability
33import Rel8.Schema.Nullability
34 ( Nullability( Nullable, NonNullable )
34 ( Nullability( Nullable, NonNullable )
35− , Nullabilizes, nullabilization
35+ , Sql, nullabilization
36 )
36 )
37import Rel8.Type ( DBType )
37import Rel8.Type ( DBType )
38import Rel8.Type.Monoid ( DBMonoid, memptyExpr )
38import Rel8.Type.Monoid ( DBMonoid, memptyExpr )
@@ -46,25 +46,25 @@ newtype Expr a = Expr Opaleye.PrimExpr
46 deriving stock Show
46 deriving stock Show
47
47
48
48
49−instance (DBSemigroup db, Nullabilizes db a) => Semigroup (Expr a) where
49+instance Sql DBSemigroup a => Semigroup (Expr a) where
50 (<>) = case nullabilization @a of
50 (<>) = case nullabilization @a of
51 Nullable -> liftOpNullable (<>.)
51 Nullable -> liftOpNullable (<>.)
52 NonNullable -> (<>.)
52 NonNullable -> (<>.)
53
53
54
54
55−instance (DBMonoid db, Nullabilizes db a) => Monoid (Expr a) where
55+instance Sql DBMonoid a => Monoid (Expr a) where
56 mempty = case nullabilization @a of
56 mempty = case nullabilization @a of
57 Nullable -> nullify memptyExpr
57 Nullable -> nullify memptyExpr
58 NonNullable -> memptyExpr
58 NonNullable -> memptyExpr
59
59
60
60
61−instance (IsString db, DBType db, Nullabilizes db a) => IsString (Expr a) where
61+instance (Sql IsString a, Sql DBType a) => IsString (Expr a) where
62 fromString = litExpr . case nullabilization @a of
62 fromString = litExpr . case nullabilization @a of
63 Nullable -> Just . fromString
63 Nullable -> Just . fromString
64 NonNullable -> fromString
64 NonNullable -> fromString
65
65
66
66
67−instance (DBNum db, Nullabilizes db a) => Num (Expr a) where
67+instance Sql DBNum a => Num (Expr a) where
68 (+) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:+))
68 (+) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:+))
69 (*) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:*))
69 (*) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:*))
70 (-) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:-))
70 (-) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:-))
@@ -77,7 +77,7 @@ instance (DBNum db, Nullabilizes db a) => Num (Expr a) where
77 fromInteger = castExpr . fromPrimExpr . Opaleye.ConstExpr . Opaleye.IntegerLit
77 fromInteger = castExpr . fromPrimExpr . Opaleye.ConstExpr . Opaleye.IntegerLit
78
78
79
79
80−instance (DBFractional db, Nullabilizes db a) => Fractional (Expr a) where
80+instance Sql DBFractional a => Fractional (Expr a) where
81 (/) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:/))
81 (/) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:/))
82
82
83 fromRational =
83 fromRational =
src/Rel8/Expr/Aggregate.hs+9−8
@@ -1,4 +1,5 @@
1{-# language DataKinds #-}
1{-# language DataKinds #-}
2+{-# language FlexibleContexts #-}
2{-# language ScopedTypeVariables #-}
3{-# language ScopedTypeVariables #-}
3{-# language TypeApplications #-}
4{-# language TypeApplications #-}
4{-# language TypeFamilies #-}
5{-# language TypeFamilies #-}
@@ -37,7 +38,7 @@ import Rel8.Expr.Opaleye
37 )
38 )
38import Rel8.Expr.Null ( null )
39import Rel8.Expr.Null ( null )
39import Rel8.Expr.Serialize ( litExpr )
40import Rel8.Expr.Serialize ( litExpr )
40−import Rel8.Schema.Nullability ( Nullability, Nullabilizes, nullabilization )
41+import Rel8.Schema.Nullability ( Nullability, Sql, nullabilization )
41import Rel8.Type.Array ( fromPrimArray )
42import Rel8.Type.Array ( fromPrimArray )
42import Rel8.Type.Eq ( DBEq )
43import Rel8.Type.Eq ( DBEq )
43import Rel8.Type.Num ( DBNum )
44import Rel8.Type.Num ( DBNum )
@@ -97,7 +98,7 @@ or = unsafeMakeAggregate toPrimExpr fromPrimExpr $
97
98
98
99
99-- | Produce an aggregation for @Expr a@ using the @max@ function.
100-- | Produce an aggregation for @Expr a@ using the @max@ function.
100−max :: (DBMax db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
101+max :: Sql DBMax a => Expr a -> Aggregate (Expr a)
101max = unsafeMakeAggregate toPrimExpr fromPrimExpr $
102max = unsafeMakeAggregate toPrimExpr fromPrimExpr $
102 Just Aggregator
103 Just Aggregator
103 { operation = Opaleye.AggrSum
104 { operation = Opaleye.AggrSum
@@ -107,7 +108,7 @@ max = unsafeMakeAggregate toPrimExpr fromPrimExpr $
107
108
108
109
109-- | Produce an aggregation for @Expr a@ using the @max@ function.
110-- | Produce an aggregation for @Expr a@ using the @max@ function.
110−min :: (DBMin db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
111+min :: Sql DBMin a => Expr a -> Aggregate (Expr a)
111min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
112min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
112 Just Aggregator
113 Just Aggregator
113 { operation = Opaleye.AggrSum
114 { operation = Opaleye.AggrSum
@@ -116,7 +117,7 @@ min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
116 }
117 }
117
118
118-- | Corresponds to @sum@.
119-- | Corresponds to @sum@.
119−sum :: (DBSum db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
120+sum :: Sql DBSum a => Expr a -> Aggregate (Expr a)
120sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
121sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
121 Just Aggregator
122 Just Aggregator
122 { operation = Opaleye.AggrSum
123 { operation = Opaleye.AggrSum
@@ -125,12 +126,12 @@ sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
125 }
126 }
126
127
127
128
128−sumWhere :: (DBNum db, DBSum db, Nullabilizes db a)
129+sumWhere :: (Sql DBNum a, Sql DBSum a)
129 => Expr Bool -> Expr a -> Aggregate (Expr a)
130 => Expr Bool -> Expr a -> Aggregate (Expr a)
130sumWhere condition a = sum (caseExpr [(condition, a)] 0)
131sumWhere condition a = sum (caseExpr [(condition, a)] 0)
131
132
132
133
133−stringAgg :: (DBString db, Nullabilizes db a)
134+stringAgg :: Sql DBString a
134 => Expr db -> Expr a -> Aggregate (Expr a)
135 => Expr db -> Expr a -> Aggregate (Expr a)
135stringAgg delimiter =
136stringAgg delimiter =
136 unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
137 unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
@@ -141,8 +142,8 @@ stringAgg delimiter =
141 }
142 }
142
143
143
144
144−-- | Aggregate a value by grouping by it.
145+-- | Aggregate a value by grouping by it.
145−groupByExpr :: (DBEq db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
146+groupByExpr :: Sql DBEq a => Expr a -> Aggregate (Expr a)
146groupByExpr = sgroupByExpr nullabilization
147groupByExpr = sgroupByExpr nullabilization
147
148
148
149
src/Rel8/Expr/Array.hs+7−7
@@ -28,7 +28,7 @@ import Rel8.Expr.Opaleye
28import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type ( DBType, typeInformation )
29import Rel8.Type.Array ( array, zipPrimArraysWith )
29import Rel8.Type.Array ( array, zipPrimArraysWith )
30import Rel8.Type.Information ( TypeInformation(..) )
30import Rel8.Type.Information ( TypeInformation(..) )
31−import Rel8.Schema.Nullability ( Nullability, Nullabilizes )
31+import Rel8.Schema.Nullability ( Unnullify, Nullability, Sql )
32
32
33
33
34sappend :: Expr [a] -> Expr [a] -> Expr [a]
34sappend :: Expr [a] -> Expr [a] -> Expr [a]
@@ -43,11 +43,11 @@ sempty :: Nullability t a -> TypeInformation t -> Expr [a]
43sempty _ info = fromPrimExpr $ array info []
43sempty _ info = fromPrimExpr $ array info []
44
44
45
45
46−listOf :: forall a t. (Nullabilizes t a, DBType t)
46+listOf :: forall a. Sql DBType a => [Expr a] -> Expr [a]
47− => [Expr a] -> Expr [a]
47+listOf =
48−listOf = fromPrimExpr . array (typeInformation @t) . fmap toPrimExpr
48+ fromPrimExpr . array (typeInformation @(Unnullify a)) . fmap toPrimExpr
49
49
50
50
51−nonEmptyOf :: forall a t. (Nullabilizes t a, DBType t)
52− => NonEmpty (Expr a) -> Expr (NonEmpty a)
51+nonEmptyOf :: forall a. Sql DBType a => NonEmpty (Expr a) -> Expr (NonEmpty a)
52+nonEmptyOf =
53−nonEmptyOf = fromPrimExpr . array (typeInformation @t) . fmap toPrimExpr
53+ fromPrimExpr . array (typeInformation @(Unnullify a)) . fmap toPrimExpr
src/Rel8/Expr/Eq.hs+5−5
@@ -1,3 +1,4 @@
1+{-# language FlexibleContexts #-}
1{-# language GADTs #-}
2{-# language GADTs #-}
2{-# language LambdaCase #-}
3{-# language LambdaCase #-}
3{-# language ViewPatterns #-}
4{-# language ViewPatterns #-}
@@ -27,7 +28,7 @@ import Rel8.Expr.Null ( isNull, unsafeLiftOpNullable )
27import Rel8.Expr.Opaleye ( fromPrimExpr, toPrimExpr, zipPrimExprsWith )
28import Rel8.Expr.Opaleye ( fromPrimExpr, toPrimExpr, zipPrimExprsWith )
28import Rel8.Schema.Nullability
29import Rel8.Schema.Nullability
29 ( Nullability( NonNullable, Nullable )
30 ( Nullability( NonNullable, Nullable )
30− , Nullabilizes, nullabilization
31+ , Sql, nullabilization
31 )
32 )
32import Rel8.Type.Eq ( DBEq )
33import Rel8.Type.Eq ( DBEq )
33
34
@@ -65,12 +66,12 @@ sin nullability (toList -> as) a = case nullability of
65 (Opaleye.ListExpr (toPrimExpr <$> xs))
66 (Opaleye.ListExpr (toPrimExpr <$> xs))
66
67
67
68
68−(==.) :: (DBEq db, Nullabilizes db a) => Expr a -> Expr a -> Expr Bool
69+(==.) :: Sql DBEq a => Expr a -> Expr a -> Expr Bool
69(==.) = seq nullabilization
70(==.) = seq nullabilization
70infix 4 ==.
71infix 4 ==.
71
72
72
73
73−(/=.) :: (DBEq db, Nullabilizes db a) => Expr a -> Expr a -> Expr Bool
74+(/=.) :: Sql DBEq a => Expr a -> Expr a -> Expr Bool
74(/=.) = sne nullabilization
75(/=.) = sne nullabilization
75infix 4 /=.
76infix 4 /=.
76
77
@@ -93,6 +94,5 @@ infix 4 /=?
93--
94--
94-- >>> select c $ return $ lit (42 :: Int32) `in_` [ lit x | x <- [1..5] ]
95-- >>> select c $ return $ lit (42 :: Int32) `in_` [ lit x | x <- [1..5] ]
95-- [False]
96-- [False]
96−in_ :: (DBEq db, Nullabilizes db a, Foldable f)
97− => f (Expr a) -> Expr a -> Expr Bool
97+in_ :: (Sql DBEq a, Foldable f) => f (Expr a) -> Expr a -> Expr Bool
98in_ = sin nullabilization
98in_ = sin nullabilization
src/Rel8/Expr/Function.hs+4−6
@@ -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 ( Nullabilizes )
28+import Rel8.Schema.Nullability ( Sql )
29import Rel8.Type ( DBType )
29import Rel8.Type ( DBType )
30
30
31
31
@@ -34,8 +34,7 @@ class Function arg res where
34 applyArgument :: ([Opaleye.PrimExpr] -> Opaleye.PrimExpr) -> arg -> res
34 applyArgument :: ([Opaleye.PrimExpr] -> Opaleye.PrimExpr) -> arg -> res
35
35
36
36
37−instance (arg ~ Expr a, DBType db, Nullabilizes db b) => Function arg (Expr b)
37+instance (arg ~ Expr a, Sql DBType b) => Function arg (Expr b) where
38− where
39 applyArgument f a = castExpr $ fromPrimExpr $ f [toPrimExpr a]
38 applyArgument f a = castExpr $ fromPrimExpr $ f [toPrimExpr a]
40
39
41
40
@@ -81,13 +80,12 @@ function = applyArgument . Opaleye.FunExpr
81--
80--
82-- >>> select c $ pure $ sqlPi
81-- >>> select c $ pure $ sqlPi
83-- [3.141592653589793]
82-- [3.141592653589793]
84−nullaryFunction :: (DBType db, Nullabilizes db a) => String -> Expr a
83+nullaryFunction :: Sql DBType a => String -> Expr a
85nullaryFunction name = castExpr $ Expr (Opaleye.FunExpr name [])
84nullaryFunction name = castExpr $ Expr (Opaleye.FunExpr name [])
86
85
87
86
88-- | Construct an expression by applying an infix binary operator to two
87-- | Construct an expression by applying an infix binary operator to two
89-- operands.
88-- operands.
90−binaryOperator :: (DBType db, Nullabilizes db c)
91− => String -> Expr a -> Expr b -> Expr c
89+binaryOperator :: Sql DBType c => String -> Expr a -> Expr b -> Expr c
92binaryOperator operator a b =
90binaryOperator operator a b =
93 castExpr $ zipPrimExprsWith (Opaleye.BinExpr (Opaleye.OpOther operator)) a b
91 castExpr $ zipPrimExprsWith (Opaleye.BinExpr (Opaleye.OpOther operator)) a b
src/Rel8/Expr/Num.hs+10−33
@@ -1,3 +1,4 @@
1+{-# language FlexibleContexts #-}
1{-# language TypeFamilies #-}
2{-# language TypeFamilies #-}
2
3
3{-# options_ghc -fno-warn-redundant-constraints #-}
4{-# options_ghc -fno-warn-redundant-constraints #-}
@@ -14,67 +15,43 @@ import Prelude ()
14import Rel8.Expr ( Expr( Expr ) )
15import Rel8.Expr ( Expr( Expr ) )
15import Rel8.Expr.Function ( function )
16import Rel8.Expr.Function ( function )
16import Rel8.Expr.Opaleye ( castExpr )
17import Rel8.Expr.Opaleye ( castExpr )
17−import Rel8.Schema.Nullability ( IsMaybe, Nullabilizes )
18+import Rel8.Schema.Nullability ( IsMaybe, Sql )
18import Rel8.Type.Num ( DBFractional, DBIntegral, DBNum )
19import Rel8.Type.Num ( DBFractional, DBIntegral, DBNum )
19
20
20
21
21−fromIntegral ::
22− ( DBIntegral _a, Nullabilizes _a a
23− , DBNum _b, Nullabilizes _b b
24− , IsMaybe a ~ IsMaybe b
22+fromIntegral :: (Sql DBIntegral a, Sql DBNum b, IsMaybe a ~ IsMaybe b)
25− )
26 => Expr a -> Expr b
23 => Expr a -> Expr b
27fromIntegral (Expr a) = castExpr (Expr a)
24fromIntegral (Expr a) = castExpr (Expr a)
28
25
29
26
30−realToFrac ::
31− ( DBNum _a, Nullabilizes _a a
32− , DBFractional _b, Nullabilizes _b b
33− , IsMaybe a ~ IsMaybe b
27+realToFrac :: (Sql DBNum a, Sql DBFractional b, IsMaybe a ~ IsMaybe b)
34− )
35 => Expr a -> Expr b
28 => Expr a -> Expr b
36realToFrac (Expr a) = castExpr (Expr a)
29realToFrac (Expr a) = castExpr (Expr a)
37
30
38
31
39−ceiling ::
40− ( DBFractional _a, Nullabilizes _a a
41− , DBIntegral _b, Nullabilizes _b b
42− , IsMaybe a ~ IsMaybe b
32+ceiling :: (Sql DBFractional a, Sql DBIntegral b, IsMaybe a ~ IsMaybe b)
43− )
44 => Expr a -> Expr b
33 => Expr a -> Expr b
45ceiling = function "CEILING"
34ceiling = function "CEILING"
46
35
47
36
48−div :: (DBIntegral _a, Nullabilizes _a a) => Expr a -> Expr a -> Expr a
37+div :: Sql DBIntegral a => Expr a -> Expr a -> Expr a
49div = function "DIV"
38div = function "DIV"
50
39
51
40
52−mod :: (DBIntegral _a, Nullabilizes _a a) => Expr a -> Expr a -> Expr a
41+mod :: Sql DBIntegral a => Expr a -> Expr a -> Expr a
53mod = function "MOD"
42mod = function "MOD"
54
43
55
44
56−floor ::
57− ( DBFractional _a, Nullabilizes _a a
58− , DBIntegral _b, Nullabilizes _b b
59− , IsMaybe a ~ IsMaybe b
45+floor :: (Sql DBFractional a, Sql DBIntegral b, IsMaybe a ~ IsMaybe b)
60− )
61 => Expr a -> Expr b
46 => Expr a -> Expr b
62floor = function "FLOOR"
47floor = function "FLOOR"
63
48
64
49
65−round ::
66− ( DBFractional _a, Nullabilizes _a a
67− , DBIntegral _b, Nullabilizes _b b
68− , IsMaybe a ~ IsMaybe b
50+round :: (Sql DBFractional a, Sql DBIntegral b, IsMaybe a ~ IsMaybe b)
69− )
70 => Expr a -> Expr b
51 => Expr a -> Expr b
71round = function "ROUND"
52round = function "ROUND"
72
53
73
54
74−truncate ::
75− ( DBFractional _a, Nullabilizes _a a
76− , DBIntegral _b, Nullabilizes _b b
77− , IsMaybe a ~ IsMaybe b
55+truncate :: (Sql DBFractional a, Sql DBIntegral b, IsMaybe a ~ IsMaybe b)
78− )
79 => Expr a -> Expr b
56 => Expr a -> Expr b
80truncate = function "TRUNC"
57truncate = function "TRUNC"
src/Rel8/Expr/Opaleye.hs+4−4
@@ -25,16 +25,16 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
25
25
26-- rel8
26-- rel8
27import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
27import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
28−import Rel8.Schema.Nullability ( Nullability, Nullabilizes, nullabilization )
28+import Rel8.Schema.Nullability ( Nullability, Sql, nullabilization )
29import Rel8.Type ( DBType, typeInformation )
29import Rel8.Type ( DBType, typeInformation )
30import Rel8.Type.Information ( TypeInformation(..) )
30import Rel8.Type.Information ( TypeInformation(..) )
31
31
32
32
33−castExpr :: (DBType db, Nullabilizes db a) => Expr a -> Expr a
33+castExpr :: Sql DBType a => Expr a -> Expr a
34castExpr = scastExpr nullabilization typeInformation
34castExpr = scastExpr nullabilization typeInformation
35
35
36
36
37−unsafeCastExpr :: (DBType db, Nullabilizes db b) => Expr a -> Expr b
37+unsafeCastExpr :: Sql DBType b => Expr a -> Expr b
38unsafeCastExpr = sunsafeCastExpr nullabilization typeInformation
38unsafeCastExpr = sunsafeCastExpr nullabilization typeInformation
39
39
40
40
@@ -48,7 +48,7 @@ sunsafeCastExpr _ TypeInformation {typeName} =
48 fromPrimExpr . Opaleye.CastExpr typeName . toPrimExpr
48 fromPrimExpr . Opaleye.CastExpr typeName . toPrimExpr
49
49
50
50
51−unsafeLiteral :: (DBType db, Nullabilizes db a) => String -> Expr a
51+unsafeLiteral :: Sql DBType a => String -> Expr a
52unsafeLiteral = castExpr . Expr . Opaleye.ConstExpr . Opaleye.OtherLit
52unsafeLiteral = castExpr . Expr . Opaleye.ConstExpr . Opaleye.OtherLit
53
53
54
54
src/Rel8/Expr/Ord.hs+8−10
@@ -1,4 +1,5 @@
1{-# language DataKinds #-}
1{-# language DataKinds #-}
2+{-# language FlexibleContexts #-}
2{-# language LambdaCase #-}
3{-# language LambdaCase #-}
3{-# language GADTs #-}
4{-# language GADTs #-}
4{-# language ScopedTypeVariables #-}
5{-# language ScopedTypeVariables #-}
@@ -27,7 +28,7 @@ import Rel8.Expr.Null ( isNull, isNonNull, nullable, unsafeLiftOpNullable )
27import Rel8.Expr.Opaleye ( zipPrimExprsWith )
28import Rel8.Expr.Opaleye ( zipPrimExprsWith )
28import Rel8.Schema.Nullability
29import Rel8.Schema.Nullability
29 ( Nullability( NonNullable, Nullable )
30 ( Nullability( NonNullable, Nullable )
30− , Nullabilizes, nullabilization
31+ , Sql, nullabilization
31 )
32 )
32import Rel8.Type.Ord ( DBOrd )
33import Rel8.Type.Ord ( DBOrd )
33
34
@@ -72,26 +73,25 @@ sge = \case
72 NonNullable -> ge
73 NonNullable -> ge
73
74
74
75
75−-- | The PostgreSQL @<@ operator.
76−(<.) :: (DBOrd db, Nullabilizes db a) => Expr a -> Expr a -> Expr Bool
76+(<.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
77(<.) = slt nullabilization
77(<.) = slt nullabilization
78infix 4 <.
78infix 4 <.
79
79
80
80
81-- | The PostgreSQL @<=@ operator.
81-- | The PostgreSQL @<=@ operator.
82−(<=.) :: (DBOrd db, Nullabilizes db a) => Expr a -> Expr a -> Expr Bool
82+(<=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
83(<=.) = sle nullabilization
83(<=.) = sle nullabilization
84infix 4 <=.
84infix 4 <=.
85
85
86
86
87-- | The PostgreSQL @>@ operator.
87-- | The PostgreSQL @>@ operator.
88−(>.) :: (DBOrd db, Nullabilizes db a) => Expr a -> Expr a -> Expr Bool
88+(>.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
89(>.) = sgt nullabilization
89(>.) = sgt nullabilization
90infix 4 >.
90infix 4 >.
91
91
92
92
93-- | The PostgreSQL @>=@ operator.
93-- | The PostgreSQL @>=@ operator.
94−(>=.) :: (DBOrd db, Nullabilizes db a) => Expr a -> Expr a -> Expr Bool
94+(>=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
95(>=.) = sge nullabilization
95(>=.) = sge nullabilization
96infix 4 >=.
96infix 4 >=.
97
97
@@ -116,8 +116,7 @@ a >=? b = coalesce $ unsafeLiftOpNullable ge a b
116infix 4 >=?
116infix 4 >=?
117
117
118
118
119−leastExpr :: forall a db. (DBOrd db, Nullabilizes db a)
119+leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
120− => Expr a -> Expr a -> Expr a
121leastExpr ma mb = case nullabilization @a of
120leastExpr ma mb = case nullabilization @a of
122 Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
121 Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
123 NonNullable -> least_ ma mb
122 NonNullable -> least_ ma mb
@@ -125,8 +124,7 @@ leastExpr ma mb = case nullabilization @a of
125 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
124 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
126
125
127
126
128−greatestExpr :: forall a db. (DBOrd db, Nullabilizes db a)
127+greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
129− => Expr a -> Expr a -> Expr a
130greatestExpr ma mb = case nullabilization @a of
128greatestExpr ma mb = case nullabilization @a of
131 Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
129 Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
132 NonNullable -> greatest_ ma mb
130 NonNullable -> greatest_ ma mb
src/Rel8/Expr/Serialize.hs+3−2
@@ -1,3 +1,4 @@
1+{-# language FlexibleContexts #-}
1{-# language NamedFieldPuns #-}
2{-# language NamedFieldPuns #-}
2{-# language TypeFamilies #-}
3{-# language TypeFamilies #-}
3
4
@@ -22,13 +23,13 @@ import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
22import Rel8.Expr.Opaleye ( scastExpr )
23import Rel8.Expr.Opaleye ( scastExpr )
23import Rel8.Schema.Nullability
24import Rel8.Schema.Nullability
24 ( Nullability( Nullable, NonNullable )
25 ( Nullability( Nullable, NonNullable )
25− , Nullabilizes, nullabilization
26+ , Sql, nullabilization
26 )
27 )
27import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type.Information ( TypeInformation(..) )
29import Rel8.Type.Information ( TypeInformation(..) )
29
30
30
31
31−litExpr :: (DBType db, Nullabilizes db a) => a -> Expr a
32+litExpr :: Sql DBType a => a -> Expr a
32litExpr = slitExpr nullabilization typeInformation
33litExpr = slitExpr nullabilization typeInformation
33
34
34
35
src/Rel8/Schema/Context.hs+5−18
@@ -33,7 +33,7 @@ import Rel8.Kind.Necessity
33 , SNecessity( SOptional, SRequired )
33 , SNecessity( SOptional, SRequired )
34 , KnownNecessity, necessitySing
34 , KnownNecessity, necessitySing
35 )
35 )
36−import Rel8.Schema.Nullability ( Nullabilizes )
36+import Rel8.Schema.Nullability ( Sql )
37import Rel8.Schema.Spec ( Context, Spec( Spec ) )
37import Rel8.Schema.Spec ( Context, Spec( Spec ) )
38import Rel8.Schema.Structure ( Structure )
38import Rel8.Schema.Structure ( Structure )
39import Rel8.Type.Monoid ( DBMonoid )
39import Rel8.Type.Monoid ( DBMonoid )
@@ -55,21 +55,13 @@ data DB spec where
55deriving stock instance Show (DB spec)
55deriving stock instance Show (DB spec)
56
56
57
57
58−instance
59− ( spec ~ 'Spec labels necessity dbType a
58+instance (spec ~ 'Spec labels necessity dbType a, Sql DBSemigroup a) =>
60− , DBSemigroup dbType
61− , Nullabilizes dbType a
62− ) =>
63 Semigroup (DB spec)
59 Semigroup (DB spec)
64 where
60 where
65 DB a <> DB b = DB (a <> b)
61 DB a <> DB b = DB (a <> b)
66
62
67
63
68−instance
69− ( spec ~ 'Spec labels necessity dbType a
64+instance (spec ~ 'Spec labels necessity dbType a, Sql DBMonoid a) =>
70− , DBMonoid dbType
71− , Nullabilizes dbType a
72− ) =>
73 Monoid (DB spec)
65 Monoid (DB spec)
74 where
66 where
75 mempty = DB mempty
67 mempty = DB mempty
@@ -86,11 +78,7 @@ data Insertion spec where
86deriving stock instance Show (Insertion spec)
78deriving stock instance Show (Insertion spec)
87
79
88
80
89−instance
90− ( spec ~ 'Spec labels necessity dbType a
81+instance (spec ~ 'Spec labels necessity dbType a, Sql DBSemigroup a) =>
91− , DBSemigroup dbType
92− , Nullabilizes dbType a
93− ) =>
94 Semigroup (Insertion spec)
82 Semigroup (Insertion spec)
95 where
83 where
96 RequiredInsert a <> RequiredInsert b = RequiredInsert (a <> b)
84 RequiredInsert a <> RequiredInsert b = RequiredInsert (a <> b)
@@ -100,8 +88,7 @@ instance
100instance
88instance
101 ( spec ~ 'Spec labels necessity dbType a
89 ( spec ~ 'Spec labels necessity dbType a
102 , KnownNecessity necessity
90 , KnownNecessity necessity
103− , DBMonoid dbType
91+ , Sql DBMonoid a
104− , Nullabilizes dbType a
105 ) => Monoid (Insertion spec)
92 ) => Monoid (Insertion spec)
106 where
93 where
107 mempty = case necessitySing @necessity of
94 mempty = case necessitySing @necessity of
src/Rel8/Schema/Context/Nullify.hs+3−6
@@ -41,10 +41,7 @@ import Rel8.Schema.Context
41 , Insertion( RequiredInsert, OptionalInsert )
41 , Insertion( RequiredInsert, OptionalInsert )
42 , Name( Name )
42 , Name( Name )
43 )
43 )
44−import Rel8.Schema.Nullability
45− ( Nullability( Nullable, NonNullable )
44+import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ), Sql )
46− , Nullabilizes
47− )
48import Rel8.Schema.Spec ( Context, Spec( Spec ), SSpec(..) )
45import Rel8.Schema.Spec ( Context, Spec( Spec ), SSpec(..) )
49import Rel8.Type.Eq ( DBEq )
46import Rel8.Type.Eq ( DBEq )
50import Rel8.Type.Monoid ( DBMonoid )
47import Rel8.Type.Monoid ( DBMonoid )
@@ -52,11 +49,11 @@ import Rel8.Type.Monoid ( DBMonoid )
52
49
53type Nullifiable :: Context -> Constraint
50type Nullifiable :: Context -> Constraint
54class Nullifiable context where
51class Nullifiable context where
55− encodeTag :: (DBEq db, Nullabilizes db a, KnownLabels labels)
52+ encodeTag :: (Sql DBEq a, KnownLabels labels)
56 => Expr a
53 => Expr a
57 -> context ('Spec labels 'Required db a)
54 -> context ('Spec labels 'Required db a)
58
55
59− decodeTag :: (DBMonoid db, Nullabilizes db a)
56+ decodeTag :: Sql DBMonoid a
60 => context ('Spec labels 'Required db a)
57 => context ('Spec labels 'Required db a)
61 -> Expr a
58 -> Expr a
62
59
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 Rel8.Schema.HTable.Context ( H, HKTable )
25import Rel8.Schema.HTable.Context ( H, HKTable )
26−import Rel8.Schema.Nullability ( Unnullify, Nullabilizes, nullabilization )
26+import Rel8.Schema.Nullability ( Unnullify, Sql, nullabilization )
27import Rel8.Schema.Spec ( Context, Spec( Spec ), SSpec(..) )
27import Rel8.Schema.Spec ( Context, Spec( Spec ), SSpec(..) )
28import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type ( DBType, typeInformation )
29
29
@@ -40,7 +40,7 @@ data HTypeField a spec where
40 HTypeField :: HTypeField a ('Spec '[""] 'Required (Unnullify a) a)
40 HTypeField :: HTypeField a ('Spec '[""] 'Required (Unnullify a) a)
41
41
42
42
43−instance (DBType db, Nullabilizes db a) => HTable (HType a) where
43+instance Sql DBType a => HTable (HType a) where
44 type HConstrainTable (HType a) c = c ('Spec '[""] 'Required (Unnullify a) a)
44 type HConstrainTable (HType a) c = c ('Spec '[""] 'Required (Unnullify a) a)
45 type HField (HType a) = HTypeField a
45 type HField (HType a) = HTypeField a
46
46
src/Rel8/Schema/Nullability.hs+14
@@ -9,10 +9,12 @@
9{-# language StandaloneKindSignatures #-}
9{-# language StandaloneKindSignatures #-}
10{-# language TypeFamilies #-}
10{-# language TypeFamilies #-}
11{-# language UndecidableInstances #-}
11{-# language UndecidableInstances #-}
12+{-# language UndecidableSuperClasses #-}
12
13
13module Rel8.Schema.Nullability
14module Rel8.Schema.Nullability
14 ( IsMaybe, Nullify, Unnullify
15 ( IsMaybe, Nullify, Unnullify
15 , Nullability( Nullable, NonNullable )
16 , Nullability( Nullable, NonNullable )
17+ , Sql
16 , Nullabilizes, nullabilization
18 , Nullabilizes, nullabilization
17 )
19 )
18where
20where
@@ -82,5 +84,17 @@ instance Nullabilizes' (IsMaybe ma) a ma => Nullabilizes a ma
82instance {-# OVERLAPPING #-} Nullabilizes Opaque Opaque
84instance {-# OVERLAPPING #-} Nullabilizes Opaque Opaque
83
85
84
86
87+type Sql :: (Type -> Constraint) -> Type -> Constraint
88+class
89+ ( (forall c. (forall x. (constraint x => c x)) => Sql c a)
90+ , Nullabilizes (Unnullify a) a
91+ , constraint (Unnullify a)
92+ )
93+ => Sql constraint a
94+instance (constraint db, Nullabilizes db a) => Sql constraint a
95+instance {-# OVERLAPPING #-} (constraint Opaque, Sql constraint Opaque) => Sql constraint Opaque
96+-- instance {-# OVERLAPPING #-} Sql OpaqueC Opaque => Sql OpaqueC Opaque
97+
98+
85nullabilization :: forall a db. Nullabilizes db a => Nullability db a
99nullabilization :: forall a db. Nullabilizes db a => Nullability db a
86nullabilization = nullabilization'
100nullabilization = nullabilization'
src/Rel8/Schema/Spec.hs+5−4
@@ -23,7 +23,7 @@ import Rel8.Kind.Necessity
23 , SNecessity
23 , SNecessity
24 , KnownNecessity, necessitySing
24 , KnownNecessity, necessitySing
25 )
25 )
26−import Rel8.Schema.Nullability ( Nullability, Nullabilizes, nullabilization )
26+import Rel8.Schema.Nullability ( Unnullify, Nullability, Sql, nullabilization )
27import Rel8.Type ( DBType, typeInformation )
27import Rel8.Type ( DBType, typeInformation )
28import Rel8.Type.Information ( TypeInformation )
28import Rel8.Type.Information ( TypeInformation )
29
29
@@ -51,9 +51,10 @@ class KnownSpec spec where
51instance
51instance
52 ( KnownLabels labels
52 ( KnownLabels labels
53 , KnownNecessity necessity
53 , KnownNecessity necessity
54− , DBType db
54+ , Sql DBType a
55− , Nullabilizes db a
55+ , db ~ Unnullify a
56+ )
56− ) => KnownSpec ('Spec labels necessity db a)
57+ => KnownSpec ('Spec labels necessity db a)
57 where
58 where
58 specSing = SSpec
59 specSing = SSpec
59 { labels = labelsSing
60 { labels = labelsSing
src/Rel8/Table.hs+3−3
@@ -38,7 +38,7 @@ import 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(..) )
40import Rel8.Schema.HTable.Type ( HType( HType ) )
40import Rel8.Schema.HTable.Type ( HType( HType ) )
41−import Rel8.Schema.Nullability ( Nullabilizes )
41+import Rel8.Schema.Nullability ( Sql )
42import Rel8.Schema.Spec ( SSpec( SSpec ), KnownSpec )
42import Rel8.Schema.Spec ( SSpec( SSpec ), KnownSpec )
43import qualified Rel8.Schema.Spec as Kind ( Context )
43import qualified Rel8.Schema.Spec as Kind ( Context )
44import Rel8.Type ( DBType )
44import Rel8.Type ( DBType )
@@ -82,7 +82,7 @@ instance Table DB a => Table Aggregation (Aggregate a) where
82 Aggregation a -> DB <$> a
82 Aggregation a -> DB <$> a
83
83
84
84
85−instance (DBType db, Nullabilizes db a) => Table DB (Expr a) where
85+instance Sql DBType a => Table DB (Expr a) where
86 type Columns (Expr a) = HType a
86 type Columns (Expr a) = HType a
87 type Context (Expr a) = DB
87 type Context (Expr a) = DB
88
88
@@ -90,7 +90,7 @@ instance (DBType db, Nullabilizes db a) => Table DB (Expr a) where
90 fromColumns (HType (DB a)) = a
90 fromColumns (HType (DB a)) = a
91
91
92
92
93−instance (DBType db, Nullabilizes db a) => Table Result (Identity a) where
93+instance Sql DBType a => Table Result (Identity a) where
94 type Columns (Identity a) = HType a
94 type Columns (Identity a) = HType a
95 type Context (Identity a) = Result
95 type Context (Identity a) = Result
96
96
src/Rel8/Table/Maybe.hs+5−4
@@ -41,8 +41,9 @@ import Rel8.Schema.HTable.Label ( HLabel, hlabel, hunlabel )
41import Rel8.Schema.HTable.Maybe ( HMaybeTable(..) )
41import Rel8.Schema.HTable.Maybe ( HMaybeTable(..) )
42import Rel8.Schema.HTable.Nullify ( hnullify, hunnullify )
42import Rel8.Schema.HTable.Nullify ( hnullify, hunnullify )
43import Rel8.Schema.Nullability
43import Rel8.Schema.Nullability
44+ ( Nullify
44− ( Nullability( Nullable, NonNullable )
45+ , Nullability( Nullable, NonNullable )
45− , Nullabilizes, nullabilization
46+ , Sql, nullabilization
46 )
47 )
47import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
48import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
48import Rel8.Table.Alternative
49import Rel8.Table.Alternative
@@ -196,8 +197,8 @@ justTable = MaybeTable (nullify (litExpr IsJust))
196--
197--
197-- >>> select c $ fmap (fst $?) (optional (values [lit (True, False)]))
198-- >>> select c $ fmap (fst $?) (optional (values [lit (True, False)]))
198-- [Just True]
199-- [Just True]
199−($?) :: forall a b db. (DBType db, Nullabilizes db b)
200+($?) :: forall a b. Sql DBType b
200− => (a -> Expr b) -> MaybeTable a -> Expr (Maybe db)
201+ => (a -> Expr b) -> MaybeTable a -> Expr (Nullify b)
201f $? ma@(MaybeTable _ a) = case nullabilization @b of
202f $? ma@(MaybeTable _ a) = case nullabilization @b of
202 Nullable -> boolExpr (f a) null (isNothingTable ma)
203 Nullable -> boolExpr (f a) null (isNothingTable ma)
203 NonNullable -> boolExpr (nullify (f a)) null (isNothingTable ma)
204 NonNullable -> boolExpr (nullify (f a)) null (isNothingTable ma)
src/Rel8/Table/Recontextualize.hs+10−10
@@ -29,7 +29,7 @@ import Rel8.Schema.Context ( Aggregation, DB, Insertion, Name, Result )
29import Rel8.Schema.Context.Label ( Labelable )
29import Rel8.Schema.Context.Label ( Labelable )
30import Rel8.Schema.HTable ( HTable )
30import Rel8.Schema.HTable ( HTable )
31import Rel8.Schema.HTable.Context ( H )
31import Rel8.Schema.HTable.Context ( H )
32−import Rel8.Schema.Nullability ( Nullabilizes )
32+import Rel8.Schema.Nullability ( Sql )
33import Rel8.Schema.Spec ( KnownSpec )
33import Rel8.Schema.Spec ( KnownSpec )
34import qualified Rel8.Schema.Spec as Kind ( Context )
34import qualified Rel8.Schema.Spec as Kind ( Context )
35import Rel8.Table ( Table, Congruent )
35import Rel8.Table ( Table, Congruent )
@@ -51,39 +51,39 @@ class
51 , b from -> a
51 , b from -> a
52
52
53
53
54−instance (DBType db, Nullabilizes db a) =>
54+instance Sql DBType a =>
55 Recontextualize Aggregation Aggregation (Aggregate (Expr a)) (Aggregate (Expr a))
55 Recontextualize Aggregation Aggregation (Aggregate (Expr a)) (Aggregate (Expr a))
56
56
57
57
58−instance (DBType db, Nullabilizes db a) =>
58+instance Sql DBType a =>
59 Recontextualize Aggregation DB (Aggregate (Expr a)) (Expr a)
59 Recontextualize Aggregation DB (Aggregate (Expr a)) (Expr a)
60
60
61
61
62−instance (DBType db, Nullabilizes db a) =>
62+instance Sql DBType a =>
63 Recontextualize Aggregation Result (Aggregate (Expr a)) (Identity a)
63 Recontextualize Aggregation Result (Aggregate (Expr a)) (Identity a)
64
64
65
65
66−instance (DBType db, Nullabilizes db a) =>
66+instance Sql DBType a =>
67 Recontextualize DB Aggregation (Expr a) (Aggregate (Expr a))
67 Recontextualize DB Aggregation (Expr a) (Aggregate (Expr a))
68
68
69
69
70−instance (DBType db, Nullabilizes db a) =>
70+instance Sql DBType a =>
71 Recontextualize DB DB (Expr a) (Expr a)
71 Recontextualize DB DB (Expr a) (Expr a)
72
72
73
73
74−instance (DBType db, Nullabilizes db a) =>
74+instance Sql DBType a =>
75 Recontextualize DB Result (Expr a) (Identity a)
75 Recontextualize DB Result (Expr a) (Identity a)
76
76
77
77
78−instance (DBType db, Nullabilizes db a) =>
78+instance Sql DBType a =>
79 Recontextualize Result Aggregation (Identity a) (Aggregate (Expr a))
79 Recontextualize Result Aggregation (Identity a) (Aggregate (Expr a))
80
80
81
81
82−instance (DBType db, Nullabilizes db a) =>
82+instance Sql DBType a =>
83 Recontextualize Result DB (Identity a) (Expr a)
83 Recontextualize Result DB (Identity a) (Expr a)
84
84
85
85
86−instance (DBType db, Nullabilizes db a) =>
86+instance Sql DBType a =>
87 Recontextualize Result Result (Identity a) (Identity a)
87 Recontextualize Result Result (Identity a) (Identity a)
88
88
89
89
src/Rel8/Table/Serialize.hs+5−7
@@ -47,7 +47,7 @@ import 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(..) )
49import Rel8.Schema.HTable.Context ( H )
49import Rel8.Schema.HTable.Context ( H )
50−import Rel8.Schema.Nullability ( IsMaybe, Nullabilizes )
50+import Rel8.Schema.Nullability ( IsMaybe, Sql )
51import Rel8.Schema.Spec ( SSpec(..), KnownSpec )
51import Rel8.Schema.Spec ( SSpec(..), KnownSpec )
52import Rel8.Table ( Table, Columns, fromColumns, toColumns )
52import Rel8.Table ( Table, Columns, fromColumns, toColumns )
53import Rel8.Table.Either ( EitherTable )
53import Rel8.Table.Either ( EitherTable )
@@ -151,8 +151,7 @@ instance
151
151
152
152
153instance
153instance
154− ( DBType db
154+ ( Sql DBType a
155− , Nullabilizes db a
156 , IsListTabular a ~ 'False
155 , IsListTabular a ~ 'False
157 , x ~ [a]
156 , x ~ [a]
158 ) => ExprsFor 'False 'False [a] (Expr x)
157 ) => ExprsFor 'False 'False [a] (Expr x)
@@ -162,9 +161,9 @@ instance
162
161
163
162
164instance
163instance
165− ( DBType a
164+ ( Sql DBType a
166− , Nullabilizes a (Maybe a)
167 , isTabular ~ 'False
165 , isTabular ~ 'False
166+ , IsMaybe a ~ 'False
168 , IsMaybeTabular a ~ 'False
167 , IsMaybeTabular a ~ 'False
169 , x ~ Maybe a
168 , x ~ Maybe a
170 ) => ExprsFor 'False 'False (Maybe a) (Expr x)
169 ) => ExprsFor 'False 'False (Maybe a) (Expr x)
@@ -174,8 +173,7 @@ instance
174
173
175
174
176instance
175instance
177− ( DBType db
176+ ( Sql DBType a
178− , Nullabilizes db a
179 , IsListTabular a ~ 'False
177 , IsListTabular a ~ 'False
180 , x ~ NonEmpty a
178 , x ~ NonEmpty a
181 ) => ExprsFor 'False 'False (NonEmpty a) (Expr x)
179 ) => ExprsFor 'False 'False (NonEmpty a) (Expr x)
src/Rel8/Type.hs+3−3
@@ -36,7 +36,7 @@ import qualified Opaleye.Internal.HaskellDB.Sql.Default as Opaleye ( quote )
36
36
37-- rel8
37-- rel8
38import Rel8.Opaque ( Opaque )
38import Rel8.Opaque ( Opaque )
39−import Rel8.Schema.Nullability ( Nullabilizes, nullabilization )
39+import Rel8.Schema.Nullability ( Sql, nullabilization )
40import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
40import Rel8.Type.Array ( listTypeInformation, nonEmptyTypeInformation )
41import Rel8.Type.Information ( TypeInformation(..), mapTypeInformation )
41import Rel8.Type.Information ( TypeInformation(..), mapTypeInformation )
42
42
@@ -301,11 +301,11 @@ instance DBType Value where
301 }
301 }
302
302
303
303
304−instance (DBType db, Nullabilizes db a) => DBType [a] where
304+instance Sql DBType a => DBType [a] where
305 typeInformation = listTypeInformation nullabilization typeInformation
305 typeInformation = listTypeInformation nullabilization typeInformation
306
306
307
307
308−instance (DBType db, Nullabilizes db a) => DBType (NonEmpty a) where
308+instance Sql DBType a => DBType (NonEmpty a) where
309 typeInformation = nonEmptyTypeInformation nullabilization typeInformation
309 typeInformation = nonEmptyTypeInformation nullabilization typeInformation
310
310
311
311
src/Rel8/Type/Array1D.hs+10−9
@@ -43,8 +43,9 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
43import Rel8.Expr.Opaleye ( zipPrimExprsWith )
43import Rel8.Expr.Opaleye ( zipPrimExprsWith )
44import Rel8.Expr.Serialize ( litExpr )
44import Rel8.Expr.Serialize ( litExpr )
45import Rel8.Schema.Nullability
45import Rel8.Schema.Nullability
46+ ( Unnullify
46− ( Nullability( Nullable, NonNullable )
47+ , Nullability( Nullable, NonNullable )
47− , Nullabilizes, nullabilization
48+ , Sql, nullabilization
48 )
49 )
49import Rel8.Type ( DBType, typeInformation )
50import Rel8.Type ( DBType, typeInformation )
50import Rel8.Type.Eq ( DBEq )
51import Rel8.Type.Eq ( DBEq )
@@ -111,25 +112,25 @@ array1DTypeInformation nullability info =
111 null = Opaleye.ConstExpr Opaleye.NullLit
112 null = Opaleye.ConstExpr Opaleye.NullLit
112
113
113
114
114−instance (DBType db, Nullabilizes db a, IsArray1D db ~ 'False) => DBType (Array1D a) where
115+instance (Sql DBType a, IsArray1D (Unnullify a) ~ 'False) => DBType (Array1D a) where
115 typeInformation = array1DTypeInformation nullabilization typeInformation
116 typeInformation = array1DTypeInformation nullabilization typeInformation
116
117
117
118
118−instance (DBEq db, Nullabilizes db a, IsArray1D db ~ 'False) => DBEq (Array1D a)
119+instance (Sql DBEq a, IsArray1D (Unnullify a) ~ 'False) => DBEq (Array1D a)
119
120
120
121
121−instance (DBOrd db, Nullabilizes db a, IsArray1D db ~ 'False) => DBOrd (Array1D a)
122+instance (Sql DBOrd a, IsArray1D (Unnullify a) ~ 'False) => DBOrd (Array1D a)
122
123
123
124
124−instance (DBMax db, Nullabilizes db a, IsArray1D db ~ 'False) => DBMax (Array1D a)
125+instance (Sql DBMax a, IsArray1D (Unnullify a) ~ 'False) => DBMax (Array1D a)
125
126
126
127
127−instance (DBMin db, Nullabilizes db a, IsArray1D db ~ 'False) => DBMin (Array1D a)
128+instance (Sql DBMin a, IsArray1D (Unnullify a) ~ 'False) => DBMin (Array1D a)
128
129
129
130
130−instance (DBType db, Nullabilizes db a, IsArray1D db ~ 'False) => DBSemigroup (Array1D a) where
131+instance (Sql DBType a, IsArray1D (Unnullify a) ~ 'False) => DBSemigroup (Array1D a) where
131 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
132 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
132
133
133
134
134−instance (DBType db, Nullabilizes db a, IsArray1D db ~ 'False) => DBMonoid (Array1D a) where
135+instance (Sql DBType a, IsArray1D (Unnullify a) ~ 'False) => DBMonoid (Array1D a) where
135 memptyExpr = litExpr mempty
136 memptyExpr = litExpr mempty
src/Rel8/Type/Eq.hs+3−3
@@ -26,7 +26,7 @@ import Data.CaseInsensitive ( CI )
26
26
27-- rel8
27-- rel8
28import Rel8.Opaque ( Opaque )
28import Rel8.Opaque ( Opaque )
29−import Rel8.Schema.Nullability ( Nullabilizes )
29+import Rel8.Schema.Nullability ( Sql )
30import Rel8.Type ( DBType )
30import Rel8.Type ( DBType )
31
31
32-- scientific
32-- scientific
@@ -104,6 +104,6 @@ instance DBEq ByteString
104instance DBEq Lazy.ByteString
104instance DBEq Lazy.ByteString
105instance DBEq UUID
105instance DBEq UUID
106instance DBEq Value
106instance DBEq Value
107−instance (DBEq db, Nullabilizes db a) => DBEq [a]
107+instance Sql DBEq a => DBEq [a]
108−instance (DBEq db, Nullabilizes db a) => DBEq (NonEmpty a)
108+instance Sql DBEq a => DBEq (NonEmpty a)
109instance DBEq Opaque
109instance DBEq Opaque
src/Rel8/Type/Monoid.hs+2−2
@@ -26,7 +26,7 @@ import Data.CaseInsensitive ( CI )
26import {-# SOURCE #-} Rel8.Expr ( Expr )
26import {-# SOURCE #-} Rel8.Expr ( Expr )
27import Rel8.Expr.Array ( sempty )
27import Rel8.Expr.Array ( sempty )
28import Rel8.Expr.Serialize ( litExpr )
28import Rel8.Expr.Serialize ( litExpr )
29−import Rel8.Schema.Nullability ( Nullabilizes, nullabilization )
29+import Rel8.Schema.Nullability ( Sql, nullabilization )
30import Rel8.Type ( DBType, typeInformation )
30import Rel8.Type ( DBType, typeInformation )
31import Rel8.Type.Semigroup ( DBSemigroup )
31import Rel8.Type.Semigroup ( DBSemigroup )
32
32
@@ -43,7 +43,7 @@ class DBSemigroup a => DBMonoid a where
43 memptyExpr :: Expr a
43 memptyExpr :: Expr a
44
44
45
45
46−instance (DBType db, Nullabilizes db a) => DBMonoid [a] where
46+instance Sql DBType a => DBMonoid [a] where
47 memptyExpr = sempty nullabilization typeInformation
47 memptyExpr = sempty nullabilization typeInformation
48
48
49
49
src/Rel8/Type/Ord.hs+7−7
@@ -24,7 +24,7 @@ import Data.CaseInsensitive ( CI )
24
24
25-- rel8
25-- rel8
26import Rel8.Opaque ( Opaque )
26import Rel8.Opaque ( Opaque )
27−import Rel8.Schema.Nullability ( Nullabilizes )
27+import Rel8.Schema.Nullability ( Sql )
28import Rel8.Type.Eq ( DBEq )
28import Rel8.Type.Eq ( DBEq )
29
29
30-- scientific
30-- scientific
@@ -66,8 +66,8 @@ instance DBOrd (CI Lazy.Text)
66instance DBOrd ByteString
66instance DBOrd ByteString
67instance DBOrd Lazy.ByteString
67instance DBOrd Lazy.ByteString
68instance DBOrd UUID
68instance DBOrd UUID
69−instance (DBOrd db, Nullabilizes db a) => DBOrd [a]
69+instance Sql DBOrd a => DBOrd [a]
70−instance (DBOrd db, Nullabilizes db a) => DBOrd (NonEmpty a)
70+instance Sql DBOrd a => DBOrd (NonEmpty a)
71instance {-# OVERLAPPING #-} DBOrd Opaque
71instance {-# OVERLAPPING #-} DBOrd Opaque
72
72
73
73
@@ -93,8 +93,8 @@ instance DBMax (CI Text)
93instance DBMax (CI Lazy.Text)
93instance DBMax (CI Lazy.Text)
94instance DBMax ByteString
94instance DBMax ByteString
95instance DBMax Lazy.ByteString
95instance DBMax Lazy.ByteString
96−instance (DBMax db, Nullabilizes db a) => DBMax [a]
96+instance Sql DBMax a => DBMax [a]
97−instance (DBMax db, Nullabilizes db a) => DBMax (NonEmpty a)
97+instance Sql DBMax a => DBMax (NonEmpty a)
98
98
99
99
100type DBMin :: Type -> Constraint
100type DBMin :: Type -> Constraint
@@ -119,5 +119,5 @@ instance DBMin (CI Text)
119instance DBMin (CI Lazy.Text)
119instance DBMin (CI Lazy.Text)
120instance DBMin ByteString
120instance DBMin ByteString
121instance DBMin Lazy.ByteString
121instance DBMin Lazy.ByteString
122−instance (DBMin db, Nullabilizes db a) => DBMin [a]
122+instance Sql DBMin a => DBMin [a]
123−instance (DBMin db, Nullabilizes db a) => DBMin (NonEmpty a)
123+instance Sql DBMin a => DBMin (NonEmpty a)
src/Rel8/Type/Semigroup.hs+3−3
@@ -30,7 +30,7 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
30-- rel8
30-- rel8
31import {-# SOURCE #-} Rel8.Expr ( Expr )
31import {-# SOURCE #-} Rel8.Expr ( Expr )
32import Rel8.Expr.Opaleye ( zipPrimExprsWith )
32import Rel8.Expr.Opaleye ( zipPrimExprsWith )
33−import Rel8.Schema.Nullability ( Nullabilizes )
33+import Rel8.Schema.Nullability ( Sql )
34import Rel8.Type ( DBType )
34import Rel8.Type ( DBType )
35
35
36-- text
36-- text
@@ -47,11 +47,11 @@ class DBType a => DBSemigroup a where
47 infixr 6 <>.
47 infixr 6 <>.
48
48
49
49
50−instance (DBType db, Nullabilizes db a) => DBSemigroup [a] where
50+instance Sql DBType a => DBSemigroup [a] where
51 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
51 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
52
52
53
53
54−instance (DBType db, Nullabilizes db a) => DBSemigroup (NonEmpty a) where
54+instance Sql DBType a => DBSemigroup (NonEmpty a) where
55 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
55 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
56
56
57
57