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

switch default type of int8, float8 and numeric to typescript type number #373

Closed
wants to merge 1 commit into from

Conversation

xddq
Copy link

@xddq xddq commented Feb 12, 2023

Thank you for this project! So far it is super helpful.

I noiticed that the default type of my bigint/int8 columns were generated as string types.
I would expect the default mapping to be of type number.

I checked the defaulttypemap and found this to be true also for float8 and numeric types.
Is there a specific reason for this default mapping?

This PR would simply adapt these types to be mapped to number

@kristiandupont
Copy link
Owner

Thank you for this, but it's a deliberate decision.

JS numbers are always floating point and so only 53 bits of "integer precision" while Bigint has 64, so there is a risk of data loss for large values. This same design decision was made in node-postgres. If you want to override it because you know it's safe or you want to use BigInt, you should just override the values in your config. But now that you mention it, I guess it could safely be number for float8...

@xddq
Copy link
Author

xddq commented Feb 13, 2023

Ahh, interesting! I like the decision to follow node-postgres.

I checked node-postgres and it looks like float4 and float8 are parsed as number types by default! (Or did I make a mistake here?) src

I will go ahead and ask in node-postgres why they are not using BigInt type by default. I would assume that the reason is that BigInt did not exist back then and now they don't want to break backwards compatibility..?

@kristiandupont
Copy link
Owner

Good question, I am not sure. Related to this is the issues of ranges which I recently added as tuples. That is actually inconsistent with what node-postgres returns as well. I think I need to figure out what my strategy is exactly :-)

@kristiandupont
Copy link
Owner

I published a new version where float8 is treated as a number, and where the reason for the string is documented.
I also reverted the builtin ranges to be strings as that's apparently what node-postgres returns, even though node-pg-types has been updated to support the Range class from postgres-range. It's a bit of a mess.

@xddq
Copy link
Author

xddq commented Feb 19, 2023

Aight, thanks a lot! I still like the idea of defaulting what node-postgres currently uses. At least gives a decent starting point IMO.

@xddq xddq closed this Feb 19, 2023
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

Successfully merging this pull request may close these issues.

2 participants