w3c / IndexedDB

Indexed Database API
https://w3c.github.io/IndexedDB/
Other
240 stars 62 forks source link

Future: Support Tuples as compound keys #390

Open inexorabletash opened 2 years ago

inexorabletash commented 2 years ago

Assuming the Record & Tuple proposal lands in ECMAScript, we should support specifying composite keys with tuples. Namely things like this would be expected to work:

// tuples and arrays are equally valid ways to specify composite keys
assert(indexedDB.cmp([1,2,3], #[1,2,3]) === 0);

// tuples and arrays are interchangeable where keys are used
store.put('value1', #[1,2,3]); 
store.put('value2', [4,5,6]); 
store.get([1,2,3]).onsuccess = e => { assert(e.target.result === 'value1'; };
store.get(#[4,5,6]).onsuccess = e => { assert(e.target.result === 'value2'; };

// but IndexedDB operations that return composite keys to script still produce arrays
store.put('value', #[1,2,3]).onsuccess = e => { let key = e.target.result; assert(Array.isArray(key)); };

I believe this would only require normative changes in https://w3c.github.io/IndexedDB/#convert-value-to-key and an non-normative changes in https://w3c.github.io/IndexedDB/#key-construct

inexorabletash commented 2 years ago

Also, I'd want to resolve #360 first (just an editorial change, though - no normative behavior differences)