Last active
March 2, 2018 11:41
-
-
Save bennycode/3e9024c2d65907e301cdc4da00a9dbc5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
async function getAllDexieDatabaseNames(dexieRootName = '__dbnames') { | |
return new Promise((resolve, reject) => { | |
const DBOpenRequest = window.indexedDB.open(dexieRootName); | |
DBOpenRequest.onerror = () => reject(DBOpenRequest.error); | |
DBOpenRequest.onsuccess = () => { | |
const db = DBOpenRequest.result; | |
const dbNameStore = Array.from(event.target.result.objectStoreNames); | |
if (dbNameStore.length > 0) { | |
const transaction = db.transaction('dbnames', 'readonly'); | |
transaction.onerror = () => reject(transaction.error); | |
const objectStore = transaction.objectStore('dbnames'); | |
const request = objectStore.getAll(); | |
request.onerror = () => reject(request.error); | |
request.onsuccess = (event) => { | |
const databaseNames = event.target.result.map(item => item.name); | |
resolve(databaseNames); | |
}; | |
} else { | |
resolve([]); | |
} | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment