git.iko.soy/purestack-dev/project-m36-rest
on master help sign in
Unified attribute type encoding
commitc3a0331d62f7f5c9d90012d533e5713095a5fb4e authoriko <mail@iko.soy> dateFri 4 Jul 2025, 16:43 (1 year ago) parent9fd9e10
1 file changed+17−20
unifiedsplit
src/ProjectM36/Rest.hs+17−20
src/ProjectM36/Rest.hs+17−20
@@ -98,26 +98,23 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
9898 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
9999 ]
100100
101−decodeRelationType :: A.Object -> A.Parser (V.Vector Attribute)
102−decodeRelationType o =
103− fmap V.fromList $
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.Object x -> RelationAtomType . Attributes <$> decodeRelationType x
118− _ -> fail $ "unknown type: " <> show v
119− )
120− (KeyMap.toList o)
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+ )
121118
122119decodeExpr :: A.Value -> A.Parser RelationalExpr
123120decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of