Skip to content

Instantly share code, notes, and snippets.

@axxapy
Last active February 10, 2022 04:07
Show Gist options
  • Save axxapy/215f83e658a967add415ae1bb5547b11 to your computer and use it in GitHub Desktop.
Save axxapy/215f83e658a967add415ae1bb5547b11 to your computer and use it in GitHub Desktop.
export indexedDB as a json
((storeName) => {
let _result = {}
const _req = indexedDB.open(storeName)
_req.onsuccess = async () => {
const db = _req.result
let semaphore = 0
for (num in [...db.objectStoreNames]) {
semaphore++
const tableName = db.objectStoreNames[num]
db.transaction(tableName, 'readonly').objectStore(tableName).getAll().onsuccess = (e) => {
_result[tableName] = e.target.result
semaphore--
}
}
while(semaphore > 0 ) {
await new Promise(r => setTimeout(r, 10))
}
const url = "data:text/javascript;base64,"+btoa(JSON.stringify(_result, null, 2))
const a = document.createElement('a')
a.download=`${storeName}.bkp.json`
a.href = url
a.click()
};
})('PUT_DATABASE_NAME_HERE')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment