Open LukaHorvat opened 6 years ago
@LukaHorvat is this a solution for #238, too?
Nope, this is only for the fully typed ones. The parser should work for untyped records as well but there's an issue with calling the individual field parsers. You need to provide the runtime representation of the parsed type and you don't have that available.
And for ToField
:
instance FieldRenderers ts => ToField (Composite ts) where
toField = pgCompositeFieldRenderer
pgCompositeFieldRenderer
:: FieldRenderers ts => Composite ts -> Action
pgCompositeFieldRenderer c =
Many $ [ Plain "row(" ] ++
intersperse (Plain ",") (renderCompositeFields c) ++
[ Plain ")" ]
class FieldRenderers ts where
renderCompositeFields :: Composite ts -> [Action]
instance FieldRenderers '[] where
renderCompositeFields _ = []
instance (ToField t, FieldRenderers ts) => FieldRenderers (t ': ts) where
renderCompositeFields (t :& ts) = toField t : renderCompositeFields ts
might do the trick?
The parser should work for untyped records as well but there's an issue with calling the individual field parsers. You need to provide the runtime representation of the parsed type and you don't have that available.
@LukaHorvat I'm interested in adding support for anonymous/untyped records. Could you give me a clue where your implementation would need to change to support them?
It's been a while so I'm not sure, but I think elems = toList . fmap atttype . attributes $ ti
won't work because ti
isn't Composite for anonymous records.
I'm opening this issue to track support for composite types. Here's what I have so far.
This needs to be tested but it seems to work for simple cases. Perhaps it can be improved and merged into the library or at the very least it might save someone some effort.