-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
BigInt errors inside prepared statements #2395
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
Comments
That's not specific to this driver. It's the default handling for > JSON.stringify({ a: 1n })
Uncaught TypeError: Do not know how to serialize a BigInt
at JSON.stringify (<anonymous>) You'll need to stringify it yourself or add system support for it it via a polyfill. I think it's not part of the |
I think this library should offer a default serialization for example: if(typeof BigInt.prototype.toJSON !== 'function') {
// no global BigInt serialization available,
// apply default serialization to BigInt-s,
// to avoid throwing errors
// use custom JSON.stringify
} |
I think that's a bad idea as if you round trip an object (i.e. INSERT then SELECT it back), you'll won't get a BigInt. The |
@sehrope De-serialization is a separate issue altogether, which works via custom parsers. This issue is strictly about serialization. |
I have been using custom serializer inside |
You have to explicitly add support for deserialization, so it makes sense to require explicit support for serialization. Having it work automatically in only one direction would lead to confusion and any errors may well be hidden in edge cases. Again, I don't see it as a failure of this library as nothing that handles JSON stringification works out of the box with BigInts. For example if you use express and return an object via |
No, it doesn't, because serialization doesn't bring any ambiguity, it produces just one format which Postgres understands, and that's it, while de-serialization allows for multiple interpretations of the incoming data, depending on precision requirements, etc. This is why de-serialization is where it belongs, so you can control |
Custom serializers are slow. People putting BigInts in JSON parameters can handle this themselves, I think. |
Why use of
BigInt
in Prepared Statements throws an error inside this library's formatter?throws library-level error (not server-level):
Note that the error is thrown while preparing the query for execution, and not on the returned result.
The text was updated successfully, but these errors were encountered: