The autoIncrement
read-only property of the IDBObjectStore
interface returns the value of the auto increment flag for this object store.
Note that every object store has its own separate auto increment counter.
In the following code snippet, we open a read/write transaction on our database and add some data to an object store using add()
. After the object store has been created, we log objectStore.autoIncrement
to the console. For a full working example, see our To-do Notifications app (view example live.)
var DBOpenRequest = window.indexedDB.open("toDoList", 4);
DBOpenRequest.onsuccess = function(event) {
note.innerHTML += '<li>Database initialized.</li>';
db = DBOpenRequest.result;
addData();
};
function addData() {
var newItem = [ { taskTitle: "Walk dog", hours: 19, minutes: 30, day: 24, month: "December", year: 2013, notified: "no" } ];
var transaction = db.transaction(["toDoList"], "readwrite");
transaction.oncomplete = function(event) {
note.innerHTML += '<li>Transaction completed.</li>';
};
transaction.onerror = function(event) {
note.innerHTML += '<li>Transaction not opened due to error. Duplicate items not allowed.</li>';
};
var objectStore = transaction.objectStore("toDoList");
console.log(objectStore.autoIncrement);
var objectStoreRequest = objectStore.add(newItem[0]);
objectStoreRequest.onsuccess = function(event) {
note.innerHTML += '<li>Request successful.</li>';
};
};