Created
July 11, 2022 23:03
-
-
Save adriancuadrado/bc45a1874f000665b17ad9d76797d184 to your computer and use it in GitHub Desktop.
Import/export indexedDB database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
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