bucardo / dbdpg

Perl Postgres driver DBD::Pg aka dbdpg
48 stars 36 forks source link

Q: autoJSONify #32

Open mche opened 7 years ago

mche commented 7 years ago

Hi!

Let me stupid question. Do you have planned to autoJSONify from Perl data to PG json/jsonb data types and backwards?

Regards.

turnstep commented 6 years ago

Yes, it's been on our long-term todo for a while. Not sure when people will have tuits for this: it's a non-trivial task.

machack666 commented 5 years ago

@turnstep are you thinking of rolling-your-own serialization/deserialization, or just hooking into JSON::XS or similar?

turnstep commented 5 years ago

We need to do our own parsing regardless, in the same way the arrays are done now. Whether or how to involve JSON::XS is somewhat secondary at the moment.

waaeer commented 5 years ago

JSON is probably the most important type for automatic conversion in DBD::Pg, but not the only one. In some cases users may want to convert NUMERICSs to Math::BigInt or Math::BigFloat; dates/times and composite types also may be converted to something etc.

Do the thing I am thinking about is to allow custom conversion for the data types. A user may be given a possibility to specify converters for the data types (like TRANSFORMS in stored procedures). Something like $dbi->set_transform('jsonb', \&JSON::XS::encode_json,\&JSON::XS::decode_json) This would be a flexible universal solution.

turnstep commented 5 years ago

That sounds nice in theory, but I'm not sure how that would work in practice. The conversions happen in the Perl XS code, and involve low-level transformations of textual representations of certain types to Perl objects.

ap commented 2 years ago

Not sure when people will have tuits for this: it's a non-trivial task.

What areas does the complexity reside in?