News for hackers. Stuff that matters.
Re:The perils of UUID primary keys in SQLite by spiffytech on Friday June 05, 2026 @10:52PM (#48420945)
Fortunately we're seeing more JS DB libraries offering to read large numbers as the BigInt type.
Re:The perils of UUID primary keys in SQLite by shakna on Saturday June 06, 2026 @01:53AM (#48421812)
But frustratingly, a JS BigInt is nothing like a BigInt in any other language.

In JS - BigInt is 64bit integer.

In anything else - BigInt is a arbitrarily large integer.

Re:The perils of UUID primary keys in SQLite by anematode on Saturday June 06, 2026 @02:02AM (#48421857)
Hm? JavaScript BigInts are arbitrary precision, and you need to use methods like BigInt.asIntN(64, a) to convert them to 64 bits
Re:The perils of UUID primary keys in SQLite by mort96 on Saturday June 06, 2026 @03:27AM (#48422364)
I hate this so much because you can’t nicely serialise a BigInt as JSON. Using a string is nicer but it only makes sense where int64 is used as an ID, not where it’s used as a number; and you don’t wanna have to configure this per field per query.
Re:The perils of UUID primary keys in SQLite by nh2 on Saturday June 06, 2026 @04:11AM (#48422605)
JSON has arbitrary length numbers in the spec only.
Re:The perils of UUID primary keys in SQLite by mort96 on Saturday June 06, 2026 @06:26AM (#48423451)
Completely and utterly irrelevant.
Re:The perils of UUID primary keys in SQLite by sheept on Saturday June 06, 2026 @06:06AM (#48423314)
You can serialize a BigInt by specifying a replacer:

    const obj = { a: 9007199254740993n }
    JSON.stringify(obj, (_key, value) => typeof value === 'bigint' ? JSON.rawJSON(value.toString()) : value)
Re:The perils of UUID primary keys in SQLite by mort96 on Saturday June 06, 2026 @06:27AM (#48423459)
And then you end up with strings on the other side, not numbers.
Re:The perils of UUID primary keys in SQLite by sheept on Saturday June 06, 2026 @06:46AM (#48423574)
No you don't? The example I gave produces

    {"a":9007199254740993}
not

    {"a":"9007199254740993"}
Re:The perils of UUID primary keys in SQLite by mort96 on Saturday June 06, 2026 @10:20AM (#48425391)
Oh, that's much worse! The JSON string `{"a":9007199254740993}` decodes to the object `{"a":9007199254740992}` with typical JSON parsers like JavaScript's `JSON.parse`.
Re:The perils of UUID primary keys in SQLite by sheept on Saturday June 06, 2026 @02:02PM (#48427370)
If you're applying a replacer, then you'd supply a reviver when parsing:

    const json = '{ "a": 9007199254740993 }'
    JSON.parse(json, (_key, value, context) => /^\d+$/.test(context.source) ? BigInt(context.source) : value)
Re:The perils of UUID primary keys in SQLite by mort96 on Saturday June 06, 2026 @02:29PM (#48427597)
Yeah but now you have the world's biggest foot gun in your API.
Re:The perils of UUID primary keys in SQLite by marcosdumay on Saturday June 06, 2026 @01:59PM (#48427343)
IMO, I'm tending toward thinking that having types on your readable serialization format is a mistake, and that they should be always input to the (de)serializer instead.
Re:The perils of UUID primary keys in SQLite by Etheryte on Saturday June 06, 2026 @02:50AM (#48422119)
This is simply not true? Or maybe I misunderstand what you mean?