Skip to content

Instantly share code, notes, and snippets.

@aaronshaf
Created May 18, 2013 13:31
Show Gist options
  • Save aaronshaf/5604395 to your computer and use it in GitHub Desktop.
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.
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