Skip to content

Instantly share code, notes, and snippets.

@adriancuadrado
Created July 11, 2022 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adriancuadrado/bc45a1874f000665b17ad9d76797d184 to your computer and use it in GitHub Desktop.
Save adriancuadrado/bc45a1874f000665b17ad9d76797d184 to your computer and use it in GitHub Desktop.
Import/export indexedDB database
(() => {
indexedDB.open('postman-app').onsuccess = async event => {
let db = event.target.result;
let transaction = db.transaction(db.objectStoreNames);
// TODO: Create and download a file instead of outputting the contents
console.log(
Object.fromEntries(
await Promise.all(
[...db.objectStoreNames]
.map(
objectStoreName =>
new Promise(resolve =>
transaction
.objectStore(objectStoreName)
.getAll()
.onsuccess = e => resolve([
objectStoreName,
e.target.result
])
)
)
)
)
);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment