Created
March 13, 2024 18:29
-
-
Save suthaharan/3a4e2d30b272689da056627681d3e2f8 to your computer and use it in GitHub Desktop.
IndexedDB: Read all data
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
var connection = indexedDB.open('<DBNAME>', <Version#>); | |
connection.onsuccess = (event) => { | |
const db = event.target.result; | |
// get all contacts | |
getAllContacts(db); | |
}; | |
function getAllContacts(db) { | |
const txn = db.transaction('record', "readonly"); | |
const objectStore = txn.objectStore('record'); | |
//console.log(objectStore); | |
objectStore.openCursor().onsuccess = (event) => { | |
let cursor = event.target.result; | |
if (cursor) { | |
let contact = cursor.value; | |
console.log(contact); | |
// continue next record | |
cursor.continue(); | |
} | |
}; | |
// close the database connection | |
txn.oncomplete = function () { | |
db.close(); | |
}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment