How to upgrade the IndexedDB version in a program... I have a button, If I click, the IDB version should be automatically upgraded to next version and onupgradeneeded event should be called and also if I open it the next time, it has to open with the newly upgraded version. How can I do like this??
Asked
Active
Viewed 1,585 times
0
-
1please take a look at this question http://stackoverflow.com/a/20106136/366114 – Deni Spasovski Apr 02 '14 at 14:16
1 Answers
3
Open the database with a higher version number.
This wil trigger the onupgradeneeded event. Once this is handle the onsuccess will return ths IDB connection in the latest version.
var dbrequest = indexedDB.open("name", version);
dbrequest.onupgradeneeded = function (){
// Upgrade db code
}
dbrequest.onsuccess = function(){
// db opened in the provided version.
}
If you just want to open a connection to the latest version, you can call the open method without providing a version.
var dbrequest = indexedDB.open("name");
dbrequest.onsuccess = function(){
// db opened in the latest version.
}

Kristof Degrave
- 4,142
- 22
- 32
-
1Right on. In your database is already open, as it sounds like it might be, for the `version` variable, @Manikandan, you can pass `indexedDB.open` the current `IDBDatabase.version` property and `+ 1` and always trigger an `upgradeneeded` event. – buley Apr 02 '14 at 12:57