Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export PgType #1369

Open
forrest-akin opened this issue Aug 10, 2021 · 9 comments
Open

Export PgType #1369

forrest-akin opened this issue Aug 10, 2021 · 9 comments

Comments

@forrest-akin
Copy link

This issue is to request exporting of the PgType enum from the postgres module.

I'm struggling a bit with serializing rows from arbitrary queries to JSON. Ideally, PgRows would have a convenient way of being serialized to JSON (even if you don't know the structure ahead of time). I haven't found a good way to do this, so instead I'm iterating over column metadata for each row and mapping the value to rust types according to the value's type_info per the documented type mappings. Unfortunately, I'm having to match against the .name() of each type since it's the only public method that seems to be available for me to see the type. Deref is implemented for PgTypeInfo so I'm able to get a PgType, but since the enum isn't exported by the postgres module I'm not able to match on it.

@Lispython
Copy link

+1

I'm waiting this feature too. I tried to implement Type for my structure and I also need PgType.

@garmoned
Copy link

Yeah it is a really simple fix to make the type enums public instead of protected. Is there a good reason we only have access to the type via it's string name?

@mehcode
Copy link
Member

mehcode commented Sep 27, 2021

This will be done but the main issue is how breaking a change it will be to change the type enumeration around before we stabilize it. We've tried to hide or make private most of the internal api for now because of not wanting to worry about making larger changes until we settle on a nice api.

@andrewbaxter
Copy link

andrewbaxter commented Nov 12, 2022

Just spent 30m trying to figure out what I was missing and finally landed here. With sufficient warning, I (and I think others) would prefer an unstable way to do this than no way or having to write extra fallible conversion boilerplate.

Edit: I thought I could work around this somehow with oids but nope, those methods are pub(crate) too. I don't see any way to do this legitimately and I don't know the implications of using with_name or with_oid which seem to use different enum variants.

@andrewbaxter
Copy link

andrewbaxter commented Nov 12, 2022

Found a workaround for producing the type info at least: for most types I think you can do String::type_info() or i64::type_info() and piggy back off the blanket implementations to get the internal values.

@humb1t
Copy link

humb1t commented Aug 8, 2023

Also voting for making this part of public API. I know that it's more about architecture decision than development effort, but will be able to help with dev part once architecture decision to make it public will be done.

@kylebarron
Copy link

FWIW In my project I copied PgTypeInfo and PgType and converted from the upstream version to my own via the oid: https://github.com/geoarrow/geoarrow-rs/blob/ac9b72db0eb7696330440909f5ecf2700ef16139/src/io/postgis/type_info.rs

@sumeetattree
Copy link

I have a similar use case where I need to know what the underlying PgType is. Even though PgValueRef exposes PgTypeInfo I can't do any comparisons on PgType because it's private. I could compare based on the PgTypeInfo::display_name but this seems to be brittle and I want to avoid it if possible.

Up until now I was able to copy the PgTypeInfo code into my own repo and use the pg_catalog data to directly convert udt_name into a PgType but this doesn't work when detecting type names from the PgValueRef struct.

@andrew-rj
Copy link

andrew-rj commented Nov 6, 2024

+1

We would greatly benefit from this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants