backbone-indexeddb
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -20,13 +20,5 @@ (function () { /*global _: false, Backbone: false */ | ||
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB ; | ||
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction; // No prefix in moz | ||
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || { READ_WRITE: "readwrite" }; // No prefix in moz | ||
var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange ; // No prefix in moz | ||
/* Horrible Hack to prevent ' Expected an identifier and instead saw 'continue' (a reserved word).'*/ | ||
if (window.indexedDB) { | ||
indexedDB.prototype._continue = indexedDB.prototype.continue; | ||
} else if (window.webkitIDBRequest) { | ||
webkitIDBRequest.prototype._continue = webkitIDBRequest.prototype.continue; | ||
} | ||
window.indexedDB = indexedDB; | ||
window.IDBCursor = window.IDBCursor || window.webkitIDBCursor || window.mozIDBCursor || window.msIDBCursor ; | ||
@@ -69,11 +61,12 @@ | ||
this.db = e.target.result; // Attach the connection ot the queue. | ||
if(!this.supportOnUpgradeNeeded) | ||
{ | ||
var currentIntDBVersion = (parseInt(this.db.version) || 0); // we need convert beacuse chrome store in integer and ie10 DP4+ in int; | ||
var lastMigrationInt = (parseInt(lastMigrationPathVersion) || 0); // And make sure we compare numbers with numbers. | ||
if (currentIntDBVersion === lastMigrationPathVersion) { //if support new event onupgradeneeded will trigger the ready function | ||
if (currentIntDBVersion === lastMigrationInt) { //if support new event onupgradeneeded will trigger the ready function | ||
// No migration to perform! | ||
this.ready(); | ||
} else if (currentIntDBVersion < lastMigrationPathVersion ) { | ||
} else if (currentIntDBVersion < lastMigrationInt ) { | ||
// We need to migrate up to the current migration defined in the database | ||
@@ -83,3 +76,3 @@ this.launchMigrationPath(currentIntDBVersion); | ||
// Looks like the IndexedDB is at a higher version than the current driver schema. | ||
this.error = "Database version is greater than current code " + currentIntDBVersion + " expected was " + lastMigrationPathVersion; | ||
this.error = "Database version is greater than current code " + currentIntDBVersion + " expected was " + lastMigrationInt; | ||
} | ||
@@ -250,3 +243,7 @@ }; | ||
case "delete": | ||
this.delete(storeName, object, options); // We may want to check that this is not a collection. TOFIX | ||
if (object.id || object.cid) { | ||
this.delete(storeName, object, options); | ||
} else { | ||
this.clear(storeName, object, options); | ||
} | ||
break; | ||
@@ -261,11 +258,16 @@ default: | ||
create: function (storeName, object, options) { | ||
var writeTransaction = this.db.transaction([storeName], "readwrite"); | ||
var writeTransaction = this.db.transaction([storeName], IDBTransaction.READ_WRITE); | ||
//this._track_transaction(writeTransaction); | ||
var store = writeTransaction.objectStore(storeName); | ||
var json = object.toJSON(); | ||
var writeRequest; | ||
if (!json.id) json.id = guid(); | ||
if (json.id === undefined) json.id = guid(); | ||
if (json.id === null) delete json.id; | ||
if (!store.keyPath) | ||
writeRequest = store.add(json, json.id); | ||
else | ||
writeRequest = store.add(json); | ||
var writeRequest = store.add(json, json.id); | ||
writeRequest.onerror = function (e) { | ||
@@ -282,10 +284,14 @@ options.error(e); | ||
update: function (storeName, object, options) { | ||
var writeTransaction = this.db.transaction([storeName], "readwrite"); | ||
var writeTransaction = this.db.transaction([storeName], IDBTransaction.READ_WRITE); | ||
//this._track_transaction(writeTransaction); | ||
var store = writeTransaction.objectStore(storeName); | ||
var json = object.toJSON(); | ||
var writeRequest; | ||
if (!json.id) json.id = guid(); | ||
var writeRequest = store.put(json, json.id); | ||
if (!store.keyPath) | ||
writeRequest = store.put(json, json.id); | ||
else | ||
writeRequest = store.put(json); | ||
@@ -339,3 +345,3 @@ writeRequest.onerror = function (e) { | ||
delete: function (storeName, object, options) { | ||
var deleteTransaction = this.db.transaction([storeName], "readwrite"); | ||
var deleteTransaction = this.db.transaction([storeName], IDBTransaction.READ_WRITE); | ||
//this._track_transaction(deleteTransaction); | ||
@@ -355,2 +361,18 @@ | ||
// Clears all records for storeName from db. | ||
clear: function (storeName, object, options) { | ||
var deleteTransaction = this.db.transaction([storeName], "readwrite"); | ||
//this._track_transaction(deleteTransaction); | ||
var store = deleteTransaction.objectStore(storeName); | ||
var deleteRequest = store.clear(); | ||
deleteRequest.onsuccess = function (event) { | ||
options.success(null); | ||
}; | ||
deleteRequest.onerror = function (event) { | ||
options.error("Not Cleared"); | ||
}; | ||
}, | ||
// Performs a query on storeName in db. | ||
@@ -392,3 +414,3 @@ // options may include : | ||
} | ||
} else if (options.conditions[index.keyPath]) { | ||
} else if (options.conditions[index.keyPath] != undefined) { | ||
bounds = IDBKeyRange.only(options.conditions[index.keyPath]); | ||
@@ -526,3 +548,4 @@ readCursor = index.openCursor(bounds); | ||
}); | ||
// Clean up active databases object. | ||
Databases = {} | ||
return; | ||
@@ -529,0 +552,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "An backbone adapter for indexeddb. Useless for most people untile indexeddb is ported to the browser", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
261772
12
2992
0
173