Re: [IndexedDB] Add openCursor(key, primaryKey) and continuePrimaryKey (#14)

For posterity, here's how you'd write a fallback if these methods didn't exist:

```js
  var options = {key: 2, primaryKey: 2};

  var req = idx.openCursor(null, 'next', options);
  req.onsuccess = function() {
    var cursor = 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 reason
          if (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();
  };
```


---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/IndexedDB/issues/14#issuecomment-186435507

Received on Friday, 19 February 2016 22:33:25 UTC