on master help sign in
Simplify Column type family
11a2229Shane O'Brien
src/Rel8/Schema/Column.hs+5−18
@@ -17,26 +17,13 @@ import Rel8.Schema.Field ( Field )
17import qualified Rel8.Schema.Kind as K
17import qualified Rel8.Schema.Kind as K
18
18
19
19
20−type Default :: Type -> Type
21−data Default a
22−
23−
24−type GetNecessity :: Type -> Necessity
25−type family GetNecessity a where
26− GetNecessity (Default _) = 'Optional
27− GetNecessity _ = 'Required
28−
29−
30−type UnwrapDefault :: Type -> Type
31−type family UnwrapDefault a where
32− UnwrapDefault (Default a) = a
33− UnwrapDefault a = a
34−
35−
36-- | The @Column@ type family should be used to indicate which fields of your
20-- | The @Column@ type family should be used to indicate which fields of your
37-- data types are single columns in queries. This type family has special
21-- data types are single columns in queries. This type family has special
38-- support when a query is executed, allowing you to use a single data type for
22-- support when a query is executed, allowing you to use a single data type for
39-- both query data and rows decoded to Haskell.
23-- both query data and rows decoded to Haskell.
40type Column :: K.Context -> Type -> Type
24type Column :: K.Context -> Type -> Type
41−type Column context a =
25+type Column context a = Field context 'Required a
42− Field context (GetNecessity a) (UnwrapDefault a)
26+
27+
28+type Default :: K.Context -> Type -> Type
29+type Default context a = Field context 'Optional a
src/Rel8/Schema/Generic/Test.hs+2−2
@@ -31,7 +31,7 @@ data Table f = Table
31
31
32
32
33data TablePair f = TablePair
33data TablePair f = TablePair
34− { foo :: Column f (Default Bool)
34+ { foo :: Default f Bool
35 , bars :: (Column f Text, Column f Text)
35 , bars :: (Column f Text, Column f Text)
36 }
36 }
37 deriving stock Generic
37 deriving stock Generic
@@ -72,7 +72,7 @@ data TableList f = TableList
72
72
73data TableNonEmpty f = TableNonEmpty
73data TableNonEmpty f = TableNonEmpty
74 { foo :: Column f Bool
74 { foo :: Column f Bool
75− , bars :: HNonEmpty f (TableList f)
75+ , bars :: HNonEmpty f (TableList f, Default f Char)
76 }
76 }
77 deriving stock Generic
77 deriving stock Generic
78 deriving anyclass Rel8able
78 deriving anyclass Rel8able