Created
May 18, 2013 13:31
-
-
Save aaronshaf/5604395 to your computer and use it in GitHub Desktop.
Get the "signature" of an IndexedDB database. Hopefully this becomes useful to those who are trying to circumvent versioning.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getIDBSignature(name,callback) { | |
var request = window.indexedDB.open(name); | |
request.onsuccess = function(event) { | |
var x,db = event.target.result; | |
var objectStore,objectStores = []; | |
for(x = 0;x < db.objectStoreNames.length;x++) { | |
objectStores.push(db.objectStoreNames.item(x)); | |
} | |
var transaction = db.transaction(objectStores, "readonly"); | |
objectStores = objectStores.map(function(objectStoreName) { | |
var objectStore = transaction.objectStore(objectStoreName); | |
console.log(objectStore); | |
var indexNames = []; | |
for(var x = 0;x < objectStore.indexNames.length;x++) { | |
indexNames.push(objectStore.indexNames.item(x)); | |
} | |
return { | |
autoIncrement: objectStore.autoIncrement, | |
indexNames: indexNames, | |
keyPath: objectStore.keyPath, | |
name: objectStore.name | |
}; | |
}); | |
callback({ | |
name: db.name, | |
objectStores: objectStores, | |
version: db.version | |
}); | |
db.close(name); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment