- From: Joshua Bell <notifications@github.com>
- Date: Fri, 19 Feb 2016 14:32:30 -0800
- To: w3c/IndexedDB <IndexedDB@noreply.github.com>
- Message-ID: <w3c/IndexedDB/issues/14/186435507@github.com>
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