Last active
January 20, 2019 01:53
-
-
Save arackaf/007cbd2c52d5ea03b52df7c063340962 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
function readTable(table, idxName) { | |
let open = indexedDB.open("books", 1); | |
return new Promise(resolve => { | |
open.onsuccess = evt => { | |
let db = open.result; | |
let tran = db.transaction(table); | |
let objStore = tran.objectStore(table); | |
let idx = objStore.index(idxName); | |
let tranCursor = idx.openCursor(); | |
let result = []; | |
tranCursor.onsuccess = evt => { | |
let cursor = evt.target.result; | |
if (!cursor) return resolve(result); | |
let item = cursor.value; | |
result.push(item); | |
cursor.continue(); | |
}; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment