You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add openCursor(key, primaryKey) and continuePrimaryKey #14
In the openCursor() case, is the lower-bound of the key range implicitly the index key if primaryKey is specified (and thus it's an error if a open lower bound is specified), or should the range and starting position be decoupled and require both the key and primaryKey to be explicit specified e.g. openCursor(null, null, {key: x, primaryKey: y}) ?
Agree. IDBIndexOpenCursorOptions should be a complete cursor position.
dictionary IDBIndexOpenCursorOptions {
IDBKey key, // nullable, default to lower-bound
IDBKey primaryKey; // nullable, default to first
}
Using openCursor becomes easier. Let the keyRange unchanged and open with different starting position, without requiring keyRange to be met with cursor position.
For posterity, here's how you'd write a fallback if these methods didn't exist:
varoptions={key: 2,primaryKey: 2};varreq=idx.openCursor(null,'next',options);req.onsuccess=function(){varcursor=req.result;if(!cursor)return;if(indexedDB.cmp(cursor.key,options.key)<0||(indexedDB.cmp(cursor.key,options.key)===0&&indexedDB.cmp(cursor.primaryKey,options.primaryKey)<0)){// if you have continuePrimaryKey but not openCursor(..., options) for some reasonif(cursor.continuePrimaryKey){cursor.continuePrimaryKey(options.key,options.primaryKey);return;}// If index key is too low we can jump directly to that.if(indexedDB.cmp(cursor.key,options.key)<0){cursor.continue();return;}// Otherwise we're stuck iterating until we hit the right primary key.cursor.continue();return;}// The cursor is positioned at appropriate record - use it!cursor.continue();};
Activity
inexorabletash commentedon May 28, 2015
Need to specify what happens if you call
continuePrimaryKey()on a cursor where the source is an object store. Throw?I'm updating the experimental impl in Blink to throw
InvalidAccessErrorin this case, pending further discussion.inexorabletash commentedon Jun 5, 2015
What should the behavior of
continuePrimaryKey()be with"prevunique"iteration? Given this index:If direction is "prevunique" and the cursor is at r3,
continue('a')is specified to end up at r1 (the first record with matching key).Cases:
continue('a', 1)should end up at... ?continue('a', 2)should end up at... ?continue('a', 3)should end up at... ?inexorabletash commentedon Jun 6, 2015
Heh, http://crbug.com/497454
inexorabletash commentedon Jun 6, 2015
Initial work in a4e4d2b
inexorabletash commentedon Jun 11, 2015
Another option is to throw if
continuePrimaryKey()is used with"nextunique"or"prevunique"since the behavior is a bit odd.yathit commentedon Jun 16, 2015
@inexorabletash +1 throw InvalidAccessError
inexorabletash commentedon Jun 16, 2015
@yathit do you mean for the object store source case, or for "nextunique" / "prevunique", or both?
yathit commentedon Jun 16, 2015
@inexorabletash both cases.
Disallow continuePrimaryKey on unique cursors, per #14
inexorabletash commentedon Jun 17, 2015
sgtm!
inexorabletash commentedon Jun 19, 2015
In the
openCursor()case, is the lower-bound of the key range implicitly the index key if primaryKey is specified (and thus it's an error if a open lower bound is specified), or should the range and starting position be decoupled and require both the key and primaryKey to be explicit specified e.g.openCursor(null, null, {key: x, primaryKey: y})?yathit commentedon Jun 20, 2015
Agree.
IDBIndexOpenCursorOptionsshould be a complete cursor position.Using
openCursorbecomes easier. Let the keyRange unchanged and open with different starting position, without requiring keyRange to be met with cursor position.inexorabletash commentedon Feb 19, 2016
Should we throw if
primaryKeyis specified butkeyis not? (I vote yes.)Should we define any special behavior if options are used on a unique index? (I vote no.)
inexorabletash commentedon Feb 19, 2016
For posterity, here's how you'd write a fallback if these methods didn't exist:
pwnall commentedon Mar 9, 2017
Should this issue be closed? I'm pretty sure Chrome, Firefox and Safari are shipping this.
inexorabletash commentedon Mar 9, 2017
openCursor()with primaryKey specified is still a proposal - no-one implements that.Currently you need to open the cursor against key then maybe call
continuePrimaryKey()to advance it to the right primaryKey on the first iteration.pwnall commentedon Mar 9, 2017
Thanks for explaining! I missed that first part.