I'm trying to add some values to an object store, getting this error in return (at line 22). The object store uses a keyPath 'id' and autoincrement: true.
function cacheObject(storeName, object) {
return new Promise(function(resolve, reject) {
let transaction = db.transaction([storeName], "readwrite");
transaction.oncomplete = function(event) {
console.log("Transaction complete");
resolve(object);
};
transaction.onabort = function(event) {
console.log("Transaction aborted: " + event);
reject();
};
transaction.onerror = function (event) {
console.log("Transaction error: "+ event.toString());
reject();
};
let objectStore = transaction.objectStore(storeName);
let objectReq = objectStore.add(object);
objectReq.onsuccess = function (event) {
console.log("saved object to idb: " + JSON.stringify(object));
};
});
}
Here is a sample from the onupgradeneeded event:
req.onupgradeneeded = function (e) {
let db = e.target.result;
console.log("Running idb onupgradeneeded");
if (!db.objectStoreNames.contains(STORY_STORE_NAME)) {
let storyStore = db.createObjectStore(STORY_STORE_NAME, {keyPath: "id", autoIncrement: true});
storyStore.createIndex('picture', 'picture', {unique: false});
storyStore.createIndex('text', 'text', {unique: false});
//more indexes created here
cacheObject? It will help tie your store name and object to the schemas you defined. - Ryan Dabler