Skip to content

Instantly share code, notes, and snippets.

@sdnts
Created October 9, 2019 12:00
Show Gist options
  • Save sdnts/2f084889730528511d5da12984491678 to your computer and use it in GitHub Desktop.
Save sdnts/2f084889730528511d5da12984491678 to your computer and use it in GitHub Desktop.

To dump all IndexedDB data to console:

(() => {
  const asyncForEach = (array, callback, done) => {
    const runAndWait = i => {
      if (i === array.length) return done();
      return callback(array[i], () => runAndWait(i + 1));
    };
    return runAndWait(0);
  };

  const dump = {};
  const dbRequest = window.indexedDB.open("Prisma Studio");
  dbRequest.onsuccess = () => {
    const db = dbRequest.result;
    const stores = Array.from(db.objectStoreNames);

    const tx = db.transaction(stores);
    asyncForEach(
      stores,
      (store, next) => {
        const req = tx.objectStore(store).getAll();
        req.onsuccess = () => {
          dump[store] = req.result;
          next();
        };
      },
      () => {
        console.log(JSON.stringify(dump));
      }
    );
  };
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment