logoalt Hacker News

Fabricio20today at 2:39 AM5 repliesview on HN

> bigints are smaller and faster, with less footguns

But be careful!! Javascript WILL interpret your bigints as Number() and round them down because they are too big without telling you!!!

Famously seen by every snowflake user that has interacted with Javascript, quite an annoying problem.


Replies

silvestrovtoday at 7:32 AM

Good trick is to prefix all such keys with magic, i.e. a couple of letters that identify type type of key.

Then it will always be a string and you will be free to change the format/type of the key in the future to UUID or whatever you like.

show 1 reply
Piezoidtoday at 10:29 AM

Using a Feistel cipher and base 32 encoding at the boundaries of the system can help catching vibe coded edge code that attempt to decode identifiers in javascript. It also somewhat obfuscate the cardinalities and fill rate of the tables.

sheepttoday at 10:03 AM

This can be avoided by supplying a reviver:

    const json = '{ "a": 9007199254740993 }'
    JSON.parse(json, (_key, value, context) => /^\d+$/.test(context.source) ? BigInt(context.source) : value)
show 1 reply
spiffytechtoday at 2:52 AM

Fortunately we're seeing more JS DB libraries offering to read large numbers as the BigInt type.

show 1 reply
paulddrapertoday at 3:10 AM

!!

Node.js drivers will correctly read int64 as string or bigint, not number.

E.g. pg for PostgreSQL

Maybe there’s a buggy driver but I don’t know it.

show 1 reply