git.iko.soy/purestack-dev/project-m36-rest
on master help sign in
1 file changed+17−19
since splitsnapshots
unifiedsplit
src/ProjectM36/Rest.hs+17−19
src/ProjectM36/Rest.hs+17−19
@@ -98,25 +98,23 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
9898 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
9999 ]
100100
101−decodeRelationType :: A.Array -> A.Parser (V.Vector Attribute)
102−decodeRelationType o =
103− traverse parseJSON o
104− >>= traverse
105− ( \(key, v) ->
106− Attribute (Key.toText key) <$> case v of
107− A.String "int" -> pure IntAtomType
108− A.String "integer" -> pure IntegerAtomType
109− A.String "scientific" -> pure ScientificAtomType
110− A.String "double" -> pure DoubleAtomType
111− A.String "text" -> pure TextAtomType
112− A.String "day" -> pure DayAtomType
113− A.String "datetime" -> pure DateTimeAtomType
114− A.String "bytestring" -> pure ByteStringAtomType
115− A.String "bool" -> pure BoolAtomType
116− A.String "uuid" -> pure UUIDAtomType
117− A.Array x -> RelationAtomType . Attributes <$> decodeRelationType x
118− _ -> fail $ "unknown type: " <> show v
119− )
101+decodeRelationType :: V.Vector (Text, A.Value) -> A.Parser (V.Vector Attribute)
102+decodeRelationType =
103+ traverse
104+ ( \(key, v) ->
105+ Attribute key <$> case v of
106+ A.String "int" -> pure IntAtomType
107+ A.String "integer" -> pure IntegerAtomType
108+ A.String "scientific" -> pure ScientificAtomType
109+ A.String "double" -> pure DoubleAtomType
110+ A.String "text" -> pure TextAtomType
111+ A.String "day" -> pure DayAtomType
112+ A.String "datetime" -> pure DateTimeAtomType
113+ A.String "bytestring" -> pure ByteStringAtomType
114+ A.String "bool" -> pure BoolAtomType
115+ A.String "uuid" -> pure UUIDAtomType
116+ x -> parseJSON x >>= fmap (RelationAtomType . Attributes) . decodeRelationType
117+ )
120118
121119decodeExpr :: A.Value -> A.Parser RelationalExpr
122120decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of