4 ms·
The common pattern I've seen is to send the 64 bit integer back as a string. So it would be a "numeric string"
by _RPM 10y ago
The common pattern I've seen is to send the 64 bit integer back as a string. So it would be a "numeric string"
- sshykes 10y ago100% agree with this method. Math calculations are never really used with IDs in my experience.
- hinkley 10y agoRight, but generally this has not been the default behavior. If you're lucky and your chosen libraries were written by wise people, it's a couple lines of code and a few tests. But it's usually set wrong by default, and if your IDs are monotonically increasing you'll probably never notice.
- bmm6o 10y agoIt also depends on your environment. On a platform like .Net it's not impossible to get your JS serializer to serialize 64-bit ints and floats as strings while keeping 32-bit and smaller numeric. So no matter how you represent it server-side it will survive a round trip. For a language that doesn't make that kind of distinction in the type system (I'm thinking Python, but I could be wrong), you really have to toString it right when you get it from the database. The only other option is to base the serialization decision on the value, which means sometimes your ids are returned as ints and sometimes as strings. At best it's ugly, at worst it leads to bugs.
- hinkley 10y agoIf you get to the point of sniffing, then a slightly better option might be to suffix all your foreign keys with something like 'key' or 'ID'. Or use slugs for everything. Or you could initialize all your tables with the first primary key being 2^32 and only lose one quarter billionth of your legal keyspace.