-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow expressions in addition to keyPaths when creating indexes #33
Comments
Lots of stuff to work through here, e.g. do we make expressions side-effect free by running in isolated execution environments? (VM implementers say: that's not cheap!) Also, loading libraries (e.g. text segmentation, ...) means these are probably non-trivial expressions... so do we abandon the notion that these are pure functions over the values and give sites the ability to do dumb (dangerous?) things? |
Worklets might be the way to go for this. They do require developers to be consistent, but that seems like an acceptable constraint. Very rough sketch: I haven't thought this through in detail, but something like:
Developers need to remember to call var open = indexedDB.open('stuff');
// new "registerworklet" phase always precedes "upgradeneeded" (if needed) and "success"
open.onregisterworklet = function() {
var db = open.result;
db.worklet.import('my_worklet_code.js');
};
// "upgradeneeded" implicitly delayed until all worklet imports are complete
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore('records');
store.createIndex('freeText', 'words()', {multiEntry: true});
store.createIndex('area', 'area()');
};
open.onsuccess = function() {
var db = open.result;
...
}; And registerIndexExpression('area', r => r.width * r.height);
registerIndexExpression('words', r => r.body.split(/\s+/)); |
Whether the binding (name -> function) should occur in the owning context or the worklet context should be consistent with other uses of worklets. |
This looks pretty fun :) Looks like result of an index can only be primitives + array + binary? Is it possible for a index to have multiple types? I.e. registerIndexExpression('foo', r => { return r.bool ? r.str : r.arrayType }); |
The "result" is a key, which (in Indexed DB) is a number, date, string, binary (proposed!), or array-of-key. See https://w3c.github.io/IndexedDB/#key-construct. Boolean is not supported (but see #76). There's no requirement that keys within a store or index have the same type or "shape", so your example is valid. |
If you're watching this issue... One of the primitives necessary for building full text search on top of indexes is text segmentation. @littledan has a proposal for adding this to ECMA-402 (the ECMAScript Intl object). He'd love feedback: |
Imported from https://www.w3.org/Bugs/Public/show_bug.cgi?id=10000
Discussion here: http://lists.w3.org/Archives/Public/public-webapps/2010AprJun/1094.html
The text was updated successfully, but these errors were encountered: