-
Notifications
You must be signed in to change notification settings - Fork 57
will major browsers support native IndexedDb sorting for BigInt? or will users need to custom-serialize it themselves in sortable form? #123
Comments
Good question for IndexedDB people--cc @inexorabletash |
I assume this is about use as keys (hence, sorting), not values (which cloning would cover). Re: keys: It won't happen automagically without IndexedDB changes in all browsers, independent of ES implementation changes. Keys in IndexedDB are defined as number, date, string, arraybuffer, or array of other keys. I haven't been following the BigInt design very closely, but the steps for converting an ES value to a key almost certainly would reject a BigInt. Questions include:
|
Note that if the answers are "types are conserved" and "BigInts are greater than all Numbers and smaller than all Dates" then it's reasonably straightforward. Otherwise, we need to put on our clever glasses. |
I'd suggest that the type should be conserved, and that there shouldn't be this coercion between keys. BigInt is designed around a "no coercion" philosophy.
Operators like
I don't see why it would be, beyond supporting BigInt64Arrays as values. |
Is there a separate issue for this? Would be nice to make that work from day one. |
For IDB, it seems like it would be nice if Number and BigInt could occupy the same ordering slot while preserving type, if that's how they work elsewhere in JavaScript. |
Serialization (structured clone) handling is proposed in this HTML PR. I'll follow up with a further proposal in a PR on IDB. @annevk Number and Date can be compared in ECMAScript, but in IDB, it looks like dates are consistently "greater than" numbers. What would be the downside of following a similar pattern here with BigInt? The design of BigInt discourages its mixed use in the same domain as Number, so the impact could be less than if we were talking about another programming language. |
If it's already inconsistent between the two I don't care much. |
I opened a PR on IndexedDB to track the idea to permit BigInt as IndexedDB keys. Let's continue the discussion there (given that it's impossible to support within this repository). |
also, the common-use case is likely BigInt64 (as many users might be satisfied with feature-parity with sql-databases), which may or may not simplify IndexedDb implementations by restricting native-support to that use-case.
The text was updated successfully, but these errors were encountered: