-
Notifications
You must be signed in to change notification settings - Fork 56
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
Use native BigInt type in Node 10+ #78
Comments
Neat, didn't know about this!
So we're in a bit of an odd position where it would be nice for node 10 users to have BigInts but we can't make that backwards compatible for <10. If you upgrade your app from node 8 to 10, do the types suddenly change? I don't think that's ok. That would mean adding BigInt support as opt in, e.g. |
I agree that this is the best path forward. That also makes the transition less painful if we eventually cut a new major version that dropped support for Node < 10, but that's probably a few years out.
True, but if the alternative is to use strings on Node < 10, then that's even less like |
Even after reschedule EOL for Node 8, it ends this year. So, a major release with native @bendrucker @brianc What do you think about drawbacks with:
? |
pg currently supports node 4. I think it’s reasonable to track LTS but I’d like to do that by project policy rather than evaluating on a per-release basis. Please open an issue about that on the main pg repo and we can discuss and document accordingly. |
I try to keep pg supporting any LTS release which is still in its support window. Looks like I could drop support for node 4 and node 6 as they've both left the LTS window. |
I have done some research in this area, as I am currently adding support of First of all, since And since this driver does not do its own query formatting, its support for For regular pg.types.setTypeParser(20, BigInt); // Type Id 20 = BIGINT | BIGSERIAL And also to get arrays of // 1016 = Type Id for arrays of BigInt values
const parseBigIntArray = pg.types.getTypeParser(1016);
pg.types.setTypeParser(1016, a => parseBigIntArray(a).map(BigInt)); And that is it, the rest should just work as it is. |
Node 8 reaches end of life on December 31, 2019. At that point all active Nodejs releases will have BigInt. |
Node.js v10.4.0 onward, actually. Also, as per comments above, enabling |
Yes, but I believe v10 went LTS at 10.13. I would be surprised if there were still an appreciable number of clients running an older version of v10 before the LTS. If there are, I sure hope they're getting patched!
It's fine if this issue is closed as "won't fix". But I think there is an opportunity for node-pg to change its defaults. If it were written from scratch today, I see no reason why it wouldn't default to using BigInt (ignoring the LTS debate for a moment). |
Lots of them are old, and won't be patched.
Such "opportunity" would require major version change, as it would break huge number of clients out there, while at the same time bringing in nothing new, because |
The "something new" is that node-pg does what you expect out of the box. |
You would only expect it, if you do not know how 64-bit numbers are handled in JavaScript, and nuances of switching between 53-bit For example, you can multiply |
Yeah I agree w/ @vitaly-t ... it's a huge change in a lot of subtle ways. What happens to all your queries which were doing There are other edge cases too like |
I think the great thing about it is that the changes aren’t subtle.
|
Not sure I follow. As @charmander mentioned, you need to decide how you want to serialize BigInts anyway. If using JSON, that means they'll still typically be represented as strings. Or does node-pg need to support running in browsers? I assumed from the name that it only ran in Node :) |
yeah it only runs in node (as far as I know! someone might have gone crazy w/ webpack hacks at some point?) but i just mean its common in apps to take query results and serialize them to JSON and there's weirdness w/ json and bigint. But yeah...I definitely have never nor do I plan on supporting running node-postgres in the browser - if that's something someone wants to do...more power to 'em. 😄 |
So although I don’t understand how IndexedDB could be a problem if Still, waiting doesn’t make it less painful in the future. Maybe the next major version can make it opt-in with a single function call, with a deprecation warning if you don’t |
I think that's a cool idea. |
FWIW I think https://github.com/GoogleChromeLabs/jsbi is the superior choice for BigInt.
I agree that the best thing to do is make native bigint usage customizable -- which it already is, but build-in the option to the library.
The error is a new, but default JSON.parse/JSON.stringify could never round-trip all node-pg types anyway (e.g. Date). |
@pauldraper Actually, in case of |
PR welcome here. Based on the factors discussed here and in brianc/node-postgres#2398 this is a reasonable default. I'm removing this from the 4.0 milestone because I don't have time to work on it right now and don't want to continue holding up other breaking change PRs that were submitted and merged. |
Now that Javascript has a native BigInt type, it may be time to rethink the decision to return large integers as strings.
node-pg could even fallback to a polyfill like https://www.npmjs.com/package/big-integer for older versions of Node.
The text was updated successfully, but these errors were encountered: