Reputation: 47653
Specifying the name of the "table" in the Object Store method seems repetitive if the transaction is for only 1 "table".
Q: Is there a way to reduce the repetition of:
var transaction = db.transaction(["toDoList"], "readwrite");
var objectStore = transaction.objectStore("toDoList");
Upvotes: 0
Views: 32
Reputation: 9683
The reason there is repetition is that you can open a transaction on multiple object stores. If you are commonly just opening a transaction on one object store, you could wrap it in a function:
function getObjectStore(name) {
var transaction = db.transaction([name], "readwrite");
return transaction.objectStore(name);
}
var objectStore = getObjectStore("toDoList");
More generally, the entire IndexedDB API is rather verbose and it's more pleasant to use a wrapper library like http://dexie.org/ or https://github.com/jakearchibald/idb
Upvotes: 1