on master help sign in
Rename Insertion constructor to Value
commit63c5e03dabc5d212d53fa8d4a255ea8420b9b637 authorShane O'Brien <shane.obrien@circuithub.com> dateSun 13 Jun 2021, 17:56 (5 years ago) parent0f76861
5 files changed+16−17
src/Rel8/Column/Field.hs+4−4 src/Rel8/Generic/Construction.hs+3−3 src/Rel8/Schema/Insert.hs+5−6 src/Rel8/Table/Insert.hs+2−2 src/Rel8/Table/Opaleye.hs+2−2
src/Rel8/Column/Field.hs+4−4
@@ -88,10 +88,10 @@ sfromColumn = \case
8888 SExpr -> \_ (E a) -> AField a
8989 SInsert -> \case
9090 SRequired -> \case
91− I (Insertion a) -> AField a
91+ I (Value a) -> AField a
9292 SOptional -> \case
9393 I Default -> AField Nothing
94− I (Insertion a) -> AField (Just a)
94+ I (Value a) -> AField (Just a)
9595 SName -> \_ (N a) -> AField a
9696 SResult -> \_ (R a) -> AField a
9797 SReify context ->
@@ -107,8 +107,8 @@ stoColumn = \case
107107 SAggregate -> \_ (AField a) -> A a
108108 SExpr -> \_ (AField a) -> E a
109109 SInsert -> \case
110− SRequired -> \(AField a) -> I (Insertion a)
111− SOptional -> \(AField ma) -> I $ maybe Default Insertion ma
110+ SRequired -> \(AField a) -> I (Value a)
111+ SOptional -> \(AField ma) -> I $ maybe Default Value ma
112112 SName -> \_ (AField a) -> N a
113113 SResult -> \_ (AField a) -> R a
114114 SReify context ->
src/Rel8/Generic/Construction.hs+3−3
@@ -189,13 +189,13 @@ gginsert gfromColumns = case algebraSing @algebra of
189189 @name
190190 @(Eval (rep (Reify Insert)))
191191 (\(_ :: proxy x) -> toColumns . reify @_ @x Refl)
192− (\SSpec {info} -> Reify $ I (Insertion (snull info)))
192+ (\SSpec {info} -> Reify $ I (Value (snull info)))
193193 (\SSpec {nullity} -> case nullity of
194194 Null -> id
195195 NotNull -> \case
196196 Reify (I Default) -> Reify (I Default)
197− Reify (I (Insertion a)) -> Reify (I (Insertion (nullify a))))
198− (HType . Reify . I . Insertion . litExpr)
197+ Reify (I (Value a)) -> Reify (I (Value (nullify a))))
198+ (HType . Reify . I . Value . litExpr)
199199
200200
201201type GGConstructable :: K.Algebra -> (K.Context -> Exp (Type -> Type)) -> Constraint
src/Rel8/Schema/Insert.hs+5−6
@@ -85,7 +85,7 @@ instance Interpretation Insert where
8585type Insertion :: Necessity -> Type -> Type
8686data Insertion necessity a where
8787 Default :: Insertion 'Optional a
88− Insertion :: Expr a -> Insertion necessity a
88+ Value :: Expr a -> Insertion necessity a
8989
9090
9191instance (KnownNecessity necessity, Sql DBType a) =>
@@ -137,20 +137,19 @@ instance Labelable Insert where
137137
138138
139139instance Nullifiable Insert where
140− encodeTag = I . Insertion . expr
140+ encodeTag = I . Value . expr
141141
142− decodeTag (I (Insertion a)) = fromExpr a
142+ decodeTag (I (Value a)) = fromExpr a
143143
144144 nullifier Tag {expr} test SSpec {nullity} = \case
145145 I Default -> I Default
146− I (Insertion a) ->
147− I $ Insertion $ runTag nullity condition a
146+ I (Value a) -> I $ Value $ runTag nullity condition a
148147 where
149148 condition = test expr
150149
151150 unnullifier SSpec {nullity} = \case
152151 I Default -> I Default
153− I (Insertion a) -> I $ Insertion $ unnull nullity a
152+ I (Value a) -> I $ Value $ unnull nullity a
154153
155154 {-# INLINABLE encodeTag #-}
156155 {-# INLINABLE decodeTag #-}
src/Rel8/Table/Insert.hs+2−2
@@ -29,7 +29,7 @@ toInsert :: Inserts exprs inserts => exprs -> inserts
2929toInsert (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
3030 case hfield hspecs field of
3131 SSpec {} -> I $ case hfield exprs field of
32− E expr -> Insertion expr
32+ E expr -> Value expr
3333
3434
3535-- | @toInsertDefaults@ converts a 'Table' of 'Expr's into a 'Table' that can
@@ -45,5 +45,5 @@ toInsertDefaults (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
4545 case hfield hspecs field of
4646 SSpec {necessity} -> case hfield exprs field of
4747 E expr -> I $ case necessity of
48− SRequired -> Insertion expr
48+ SRequired -> Value expr
4949 SOptional -> Default
src/Rel8/Table/Opaleye.hs+2−2
@@ -99,7 +99,7 @@ tableFields (toColumns -> names) = dimap toColumns fromColumns $
9999 go :: SSpec spec -> Col Name spec -> Opaleye.TableFields (Col Insert spec) (Col Expr spec)
100100 go SSpec {necessity} (N (Name name)) = case necessity of
101101 SRequired ->
102− lmap (\(I (Insertion a)) -> toColumn $ toPrimExpr a) $
102+ lmap (\(I (Value a)) -> toColumn $ toPrimExpr a) $
103103 E . fromPrimExpr . fromColumn <$>
104104 Opaleye.requiredTableField name
105105 SOptional ->
@@ -109,7 +109,7 @@ tableFields (toColumns -> names) = dimap toColumns fromColumns $
109109 where
110110 fromInsert = \case
111111 Default -> Nothing
112− Insertion a -> Just a
112+ Value a -> Just a
113113
114114
115115unpackspec :: Table Expr a => Opaleye.Unpackspec a a