Last active
February 10, 2022 04:07
-
-
Save axxapy/215f83e658a967add415ae1bb5547b11 to your computer and use it in GitHub Desktop.
export indexedDB as a json
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
((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