-
Notifications
You must be signed in to change notification settings - Fork 842
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
Enhancing Custom Type Registration in pgx #2150
Comments
You've got a lot of functionality in those packages. Just out of curiosity, what's the domain you're working in? As far as adding more public interfaces, I can see how it would be very useful in your particular case. But I'm not so sure if any of those internal functions are things I want to support.
I don't have any concrete reason for not exposing I don't know, I'm open to reconsidering, but I think copy and paste might actually be the best approach for the above-mentioned functions. As far as better supporting loading base types either through |
I found that a popular PostgreSQL extension for unsigned integer data types is no longer maintained, so I decided to implement my own version for learning and experience. For example, you can store a port number in uint2 (16-bit unsigned integer), but you can't store it in int2 without overflow. This leaves you with two options: casting uint16 to int16 (which causes overflow) or using int4 (int32) instead.
Yep, I see your point here, probably it's not the best place to maintain such function inside the driver, because once it becomes public it should cover all edge cases
I agree, probably future changes in this helper function behavior could break applications relying on the older behavior. So it's better to keep it internal. The only thing left to think about base types loading support, I'll research if there are more use cases for it |
I've created PostgreSQL extension that adds native unsigned integer data types to PostgreSQL.
I also implemented support of these types in pgx.
However implementing pgx part was a bit painful because I have need to copy & paste pgx internals code:
pgx/derived_types.go
Lines 249 to 262 in 2ec9004
https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register.go#L241-L257
pgx/pgtype/register_default_pg_types.go
Lines 5 to 35 in 2ec9004
https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register_default_pg_types.go#L31-L62
And there's also lack of ability to register base types:
pgx/derived_types.go
Lines 158 to 163 in 2ec9004
So, I have need need to implement types registration on my own:
https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register.go#L66-L122
https://github.com/pg-uint/pgx-pg-uint128/blob/d194dc5568275d1aabc0a6900f4311012e21abdf/types/register.go#L124-L130
To streamline the process, I suggest we export some of these functions, such as
registerDefaultPgTypeVariants
andserverVersion
(perhaps as a member method of conn).Additionally, we could either adapt the
LoadTypes
function to support loading base types or provide a new API for base type registration.The text was updated successfully, but these errors were encountered: