Simple question, but I haven't been able to find an answer.
How can I reset an object store in IndexedDB so the auto-increment key starts at 0 (or 1) again?
I am using IDBWrapper currently, but could use an alternative library if it is easier. I am using in-line keys.
From here:
If you need to clear the store from all stored entries, you can use the clear method. Note that this won’t reset Chrome’s autoIncrement counter.
If I manually clear the object store in Chrome Developer tools, this does not reset the key to 0 (or 1).
I did find this rejected bug: .cgi?id=635551 and from there, this outline of key generation:
Presumably I could write my own logic to remember when the store was last cleared and then alter the code where records are inserted to manually override the key to be 0 (or 1), but is this really necessary?
Simple question, but I haven't been able to find an answer.
How can I reset an object store in IndexedDB so the auto-increment key starts at 0 (or 1) again?
I am using IDBWrapper currently, but could use an alternative library if it is easier. I am using in-line keys.
From here: http://jensarps.de/2011/11/25/working-with-idbwrapper-part-1
If you need to clear the store from all stored entries, you can use the clear method. Note that this won’t reset Chrome’s autoIncrement counter.
If I manually clear the object store in Chrome Developer tools, this does not reset the key to 0 (or 1).
I did find this rejected bug: https://bugzilla.mozilla/show_bug.cgi?id=635551 and from there, this outline of key generation: http://www.w3/TR/2012/WD-IndexedDB-20120524/#key-generator-concept
Presumably I could write my own logic to remember when the store was last cleared and then alter the code where records are inserted to manually override the key to be 0 (or 1), but is this really necessary?
Share Improve this question edited Sep 6, 2013 at 8:21 Adam Marshall asked Sep 6, 2013 at 8:15 Adam MarshallAdam Marshall 3,0099 gold badges47 silver badges82 bronze badges3 Answers
Reset to default 11You can't reset the generator, without deleting and recreating the object store.
As noted in https://w3c.github.io/IndexedDB/#key-generator-construct the maximum generated key is 9007199254740992 and:
If you generate a new key 1000 times per second day and night, you won’t run into this limit for over 285000 years.
According to spec, generated key value can be anything depending on browser implementation. Your code should not rely on it.
You can't reset the generator, without deleting and recreating the object store. https://github./Tesfaye-Eshetie/reusable-ment-ponent/blob/store-ments-IndexedDB/js/idb/indexedDB.js