node-mysql2
node-mysql2 copied to clipboard
JSON Column type will lose precision when include bigint
if mysql column is
{ "TemplateId": 7088992364139642880 }
when I query used mysql2.
It wil be
{ "TemplateId": 7088992364139642000 }.
And I found text_parse.js, It used JSON.parse not JSONBig, So it would lose precision when occurs bigint.

Personally I think everyone who uses JSON as a serialization format have to assume IEEE 754 double precision on number serialization, anything that can potentially out of that range should use string
We could add a flag to skip automatic JSON.parse by driver and return strings for JSON columns, in that case its a client choice what to use to deserialize
In fact, with .query() this is possible right now with typeCast config
potential solution: a config option to allow to pass custom JSON.parse function
The above solution would be great. I am working on upgrading several repos to use json-bigint. Instead of JSON.parse, I would pass in JSONbig.parse.
Also ran into this, I think if the supportBigNumbers flag is set in the config it'd make sense to support parsing BigInts in JSON