Skip to content

Commit

Permalink
Update jquery.indexeddb.new.js
Browse files Browse the repository at this point in the history
  • Loading branch information
juzerali committed Mar 14, 2012
1 parent 3215105 commit 0f532f3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions jquery.indexeddb.new.js
Expand Up @@ -26,7 +26,7 @@
}
}
var doUpgrade = function(newV, oldV){ //This will be called from either onupgradeneeded or onsuccess, whichever is available first
if (config && config.schema) {
if (config && config.schema) {
// Assuming that version is always an integer
//console.log("Upgrading DB to ", db.version);
for (var i = e.oldVersion; i <= e.newVersion; i++) {
Expand Down Expand Up @@ -235,12 +235,13 @@
//console.log("Trying to open DB with", version);
return version ? indexedDB.open(dbName, version) : indexedDB.open(dbName);
});
dbPromise.then(function(db, e){
var oldVersion = Number(db.version); // Checking if the onupgradeneeded has handled the version change
if(oldVersion !== version){ // If not
if(!db.setVerion) {throw new Error("Version Change not supported in this browser");} // If setVersion also not available then throw error
var setV = db.setVersion(version); //Set the version, I would have wrapped this call under 'wrap' but then there is no way of passing the oldversion in argument
setV.onsuccess(doUpgrade(oldVersion, version)); // Handle version change manually
dbPromise.then(function(db, e){
var oldVersion = Number(db.version); // Checking if the onupgradeneeded has handled the version change
if(oldVersion !== version){ // If not
if(db.setVerion) { // If setVersion also not available then throw error
var setV = db.setVersion(version); //Set the version, I would have wrapped this call under 'wrap' but then there is no way of passing the oldversion in argument
setV.onsuccess(doUpgrade(oldVersion, db.version)); // Handle version change manually
}
}
//console.log("DB opened at", db.version);
db.onversionchange = function(){
Expand Down

0 comments on commit 0f532f3

Please sign in to comment.