jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.29k stars 353 forks source link

Iterating an index throwing 'is not a function or its return value is not async iterable' error #172

Closed kuhlaid closed 4 years ago

kuhlaid commented 4 years ago

In this section of the demo code below, I receive a 'TypeError: index.iterate(...) is not a function or its return value is not async iterable':

// Add 'And, happy new year!' to all articles on 2019-01-01:
  {
    const tx = db.transaction('articles', 'readwrite');
    const index = tx.store.index('date');

    for await (const cursor of index.iterate(new Date('2019-01-01'))) {
      const article = { ...cursor.value };
      article.body += ' And, happy new year!';
      cursor.update(article);
    }

    await tx.done;
  }

I am working in the latest version of Chrome (v83). The database and index are created but just having issues with this index iterate.

jakearchibald commented 4 years ago

Note that you need a different import for async iterators https://github.com/jakearchibald/idb#async-iterators.

Please reopen if this isn't the issue.

kuhlaid commented 4 years ago

I switched to the 'idb/with-async-ittr.js' import and that fixed the issue. Thank you.

jakearchibald commented 4 years ago

Cool! I've updated the demo so it includes the import statement too. It should make it more obvious https://github.com/jakearchibald/idb/commit/54c8ec7c4d9356e2b31c48385b07e9bb17e8c450.

kuhlaid commented 4 years ago

I just noticed the import statement in the demo, that is most helpful. Keep up the good work and thank you for plugin to help us newbies work with indexedDb.

jakearchibald commented 4 years ago

I just noticed the import statement in the demo, that is most helpful.

Sorry it wasn't there earlier!