Source code
Revision control
Copy as Markdown
Other Tools
<html>
<head>
<script>
async function ensureIDB(name, ver, store) {
return new Promise((resolve, reject) => {
let createObjectStore = (db, store) => {
db.createObjectStore(store);
};
var req = indexedDB.open(name, ver);
req.onerror = reject;
req.onsuccess = () => {
resolve(req.result);
};
req.onupgradeneeded = function (event) {
let db = event.target.result;
createObjectStore(db, store);
};
});
};
async function addDataIntoIDB(idb, store, key, value) {
let db = await ensureIDB(idb, 1, store);
await (new Promise((resolve, reject) => {
var transaction = db.transaction([store], "readwrite");
var put = transaction.objectStore(store).put(value, key);
put.onerror = reject;
put.onsuccess = resolve;
}));
closeIDB(db)
};
function closeIDB(db) {
db.close();
}
function deleteIDB(db) {
return new Promise((resolve, reject) => {
let deleteReq = indexedDB.deleteDatabase(db);
deleteReq.onerror = reject;
deleteReq.onsuccess = resolve;
});
}
</script>
</head>
</html>