idb-wrapper
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,4 +5,4 @@ { | ||
"main": "idbstore.js", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"dependencies": {} | ||
} |
@@ -53,3 +53,5 @@ /*jshint expr:true */ | ||
* @param {Number} [kwArgs.dbVersion=1] The version of the store | ||
* @param {String} [kwArgs.keyPath='id'] The key path to use | ||
* @param {String} [kwArgs.keyPath='id'] The key path to use. If you want to | ||
* setup IDBWrapper to work with out-of-line keys, you need to set this to | ||
* `null` | ||
* @param {Boolean} [kwArgs.autoIncrement=true] If set to true, IDBStore will | ||
@@ -130,3 +132,3 @@ * automatically make sure a unique keyPath value is present on each object | ||
*/ | ||
version: '1.1.0', | ||
version: '1.2.0', | ||
@@ -237,3 +239,3 @@ /** | ||
var features = this.features = {}; | ||
features.hasAutoIncrement = !window.mozIndexedDB; // TODO: Still, really? | ||
features.hasAutoIncrement = !window.mozIndexedDB; | ||
@@ -249,3 +251,3 @@ var openRequest = this.idb.open(this.dbName, this.dbVersion); | ||
} else if ('errorCode' in error.target) { | ||
gotVersionErr = error.target.errorCode == 12; // TODO: Use const | ||
gotVersionErr = error.target.errorCode == 12; | ||
} | ||
@@ -370,8 +372,11 @@ | ||
/** | ||
* Puts an object into the store. If an entry with the given id exists, | ||
* it will be overwritten. | ||
* it will be overwritten. This method has a different signature for inline | ||
* keys and out-of-line keys; please see the examples below. | ||
* | ||
* @param {Object} dataObj The object to store. | ||
* @param {*} [key] The key to store. This is only needed if IDBWrapper | ||
* is set to use out-of-line keys. For inline keys - the default scenario - | ||
* this can be omitted. | ||
* @param {Object} value The data object to store. | ||
* @param {Function} [onSuccess] A callback that is called if insertion | ||
@@ -381,4 +386,26 @@ * was successful. | ||
* failed. | ||
* @example | ||
// Storing an object, using inline keys (the default scenario): | ||
var myCustomer = { | ||
customerid: 2346223, | ||
lastname: 'Doe', | ||
firstname: 'John' | ||
}; | ||
myCustomerStore.put(myCustomer, mySuccessHandler, myErrorHandler); | ||
// Note that passing success- and error-handlers is optional. | ||
* @example | ||
// Storing an object, using out-of-line keys: | ||
var myCustomer = { | ||
lastname: 'Doe', | ||
firstname: 'John' | ||
}; | ||
myCustomerStore.put(2346223, myCustomer, mySuccessHandler, myErrorHandler); | ||
// Note that passing success- and error-handlers is optional. | ||
*/ | ||
put: function (dataObj, onSuccess, onError) { | ||
put: function (key, value, onSuccess, onError) { | ||
if (this.keyPath !== null) { | ||
onError = onSuccess; | ||
onSuccess = value; | ||
value = key; | ||
} | ||
onError || (onError = function (error) { | ||
@@ -390,7 +417,5 @@ console.error('Could not write data.', error); | ||
var hasSuccess = false, | ||
result = null; | ||
result = null, | ||
putRequest; | ||
if (typeof dataObj[this.keyPath] == 'undefined' && !this.features.hasAutoIncrement) { | ||
dataObj[this.keyPath] = this._getUID(); | ||
} | ||
var putTransaction = this.db.transaction([this.storeName], this.consts.READ_WRITE); | ||
@@ -404,3 +429,8 @@ putTransaction.oncomplete = function () { | ||
var putRequest = putTransaction.objectStore(this.storeName).put(dataObj); | ||
if (this.keyPath !== null) { // in-line keys | ||
this._addIdPropertyIfNeeded(value); | ||
putRequest = putTransaction.objectStore(this.storeName).put(value); | ||
} else { // out-of-line keys | ||
putRequest = putTransaction.objectStore(this.storeName).put(value, key); | ||
} | ||
putRequest.onsuccess = function (event) { | ||
@@ -439,3 +469,2 @@ hasSuccess = true; | ||
getTransaction.onerror = onError; | ||
var getRequest = getTransaction.objectStore(this.storeName).get(key); | ||
@@ -540,6 +569,9 @@ getRequest.onsuccess = function (event) { | ||
} else if (type == "put") { | ||
if (typeof value[this.keyPath] == 'undefined' && !this.features.hasAutoIncrement) { | ||
value[this.keyPath] = this._getUID(); | ||
var putRequest; | ||
if (this.keyPath !== null) { // in-line keys | ||
this._addIdPropertyIfNeeded(value); | ||
putRequest = batchTransaction.objectStore(this.storeName).put(value); | ||
} else { // out-of-line keys | ||
putRequest = batchTransaction.objectStore(this.storeName).put(value, key); | ||
} | ||
var putRequest = batchTransaction.objectStore(this.storeName).put(value); | ||
putRequest.onsuccess = onItemSuccess; | ||
@@ -677,14 +709,14 @@ putRequest.onerror = onItemError; | ||
/** | ||
* Generates a numeric id unique to this instance of IDBStore. | ||
* Checks if an id property needs to present on a object and adds one if | ||
* necessary. | ||
* | ||
* @return {Number} The id | ||
* @param {Object} dataObj The data object that is about to be stored | ||
* @private | ||
*/ | ||
_getUID: function () { | ||
// FF bails at times on non-numeric ids. So we take an even | ||
// worse approach now, using current time as id. Sigh. | ||
return this._insertIdCount++ + Date.now(); | ||
_addIdPropertyIfNeeded: function (dataObj) { | ||
if (!this.features.hasAutoIncrement && typeof dataObj[this.keyPath] == 'undefined') { | ||
dataObj[this.keyPath] = this._insertIdCount++ + Date.now(); | ||
} | ||
}, | ||
/************ | ||
@@ -760,2 +792,4 @@ * indexing * | ||
* results, can be 'DESC' or 'ASC' | ||
* @param {Boolean} [options.autoContinue=true] Whether to automatically | ||
* iterate the cursor to the next result | ||
* @param {Boolean} [options.filterDuplicates=false] Whether to exclude | ||
@@ -768,4 +802,4 @@ * duplicate matches | ||
* iteration has ended | ||
* @param {Function} [options.onError=console.error] A callback to be called if an error | ||
* occurred during the operation. | ||
* @param {Function} [options.onError=console.error] A callback to be called | ||
* if an error occurred during the operation. | ||
*/ | ||
@@ -776,2 +810,3 @@ iterate: function (onItem, options) { | ||
order: 'ASC', | ||
autoContinue: true, | ||
filterDuplicates: false, | ||
@@ -818,3 +853,5 @@ keyRange: null, | ||
onItem(cursor.value, cursor, cursorTransaction); | ||
cursor['continue'](); | ||
if (options.autoContinue) { | ||
cursor['continue'](); | ||
} | ||
} else { | ||
@@ -821,0 +858,0 @@ hasSuccess = true; |
@@ -9,3 +9,3 @@ /* | ||
(function(j,h,i){"function"===typeof define?define(h):"undefined"!==typeof module&&module.exports?module.exports=h():i[j]=h()})("IDBStore",function(){var j={storeName:"Store",storePrefix:"IDBWrapper-",dbVersion:1,keyPath:"id",autoIncrement:!0,onStoreReady:function(){},onError:function(a){throw a;},indexes:[]},h=function(a,c){for(var b in j)this[b]="undefined"!=typeof a[b]?a[b]:j[b];this.dbName=this.storePrefix+this.storeName;this.dbVersion=parseInt(this.dbVersion,10);c&&(this.onStoreReady=c);this.idb= | ||
window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB;this.keyRange=window.IDBKeyRange||window.webkitIDBKeyRange||window.mozIDBKeyRange;this.consts={READ_ONLY:"readonly",READ_WRITE:"readwrite",VERSION_CHANGE:"versionchange",NEXT:"next",NEXT_NO_DUPLICATE:"nextunique",PREV:"prev",PREV_NO_DUPLICATE:"prevunique"};this.openDB()};h.prototype={version:"1.1.0",db:null,dbName:null,dbVersion:null,store:null,storeName:null,keyPath:null,autoIncrement:null,indexes:null,features:null,onStoreReady:null, | ||
window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB;this.keyRange=window.IDBKeyRange||window.webkitIDBKeyRange||window.mozIDBKeyRange;this.consts={READ_ONLY:"readonly",READ_WRITE:"readwrite",VERSION_CHANGE:"versionchange",NEXT:"next",NEXT_NO_DUPLICATE:"nextunique",PREV:"prev",PREV_NO_DUPLICATE:"prevunique"};this.openDB()};h.prototype={version:"1.2.0",db:null,dbName:null,dbVersion:null,store:null,storeName:null,keyPath:null,autoIncrement:null,indexes:null,features:null,onStoreReady:null, | ||
onError:null,_insertIdCount:0,openDB:function(){(this.features={}).hasAutoIncrement=!window.mozIndexedDB;var a=this.idb.open(this.dbName,this.dbVersion),c=!1;a.onerror=function(a){var c=!1;"error"in a.target?c="VersionError"==a.target.error.name:"errorCode"in a.target&&(c=12==a.target.errorCode);if(c)this.onError(Error("The version number provided is lower than the existing one."));else this.onError(a)}.bind(this);a.onsuccess=function(a){if(!c)if(this.db)this.onStoreReady();else if(this.db=a.target.result, | ||
@@ -15,12 +15,12 @@ "string"==typeof this.db.version)this.onError(Error("The IndexedDB implementation in this browser is outdated. Please upgrade your browser."));else if(this.db.objectStoreNames.contains(this.storeName))this.store=this.db.transaction([this.storeName],this.consts.READ_ONLY).objectStore(this.storeName),this.indexes.forEach(function(a){var b=a.name;b?(this.normalizeIndexData(a),this.hasIndex(b)?this.indexComplies(this.store.index(b),a)||(c=!0,this.onError(Error('Cannot modify index "'+b+'" for current version. Please bump version number to '+ | ||
a.target.transaction.objectStore(this.storeName):this.db.createObjectStore(this.storeName,{keyPath:this.keyPath,autoIncrement:this.autoIncrement});this.indexes.forEach(function(a){var b=a.name;b||(c=!0,this.onError(Error("Cannot create index: No index name given.")));this.normalizeIndexData(a);this.hasIndex(b)?this.indexComplies(this.store.index(b),a)||(this.store.deleteIndex(b),this.store.createIndex(b,a.keyPath,{unique:a.unique,multiEntry:a.multiEntry})):this.store.createIndex(b,a.keyPath,{unique:a.unique, | ||
multiEntry:a.multiEntry})},this)}.bind(this)},deleteDatabase:function(){this.idb.deleteDatabase&&this.idb.deleteDatabase(this.dbName)},put:function(a,c,b){b||(b=function(a){console.error("Could not write data.",a)});c||(c=i);var d=!1,f=null;"undefined"==typeof a[this.keyPath]&&!this.features.hasAutoIncrement&&(a[this.keyPath]=this._getUID());var e=this.db.transaction([this.storeName],this.consts.READ_WRITE);e.oncomplete=function(){(d?c:b)(f)};e.onabort=b;e.onerror=b;a=e.objectStore(this.storeName).put(a); | ||
a.onsuccess=function(a){d=!0;f=a.target.result};a.onerror=b},get:function(a,c,b){b||(b=function(a){console.error("Could not read data.",a)});c||(c=i);var d=!1,f=null,e=this.db.transaction([this.storeName],this.consts.READ_ONLY);e.oncomplete=function(){(d?c:b)(f)};e.onabort=b;e.onerror=b;a=e.objectStore(this.storeName).get(a);a.onsuccess=function(a){d=!0;f=a.target.result};a.onerror=b},remove:function(a,c,b){b||(b=function(a){console.error("Could not remove data.",a)});c||(c=i);var d=!1,f=null,e=this.db.transaction([this.storeName], | ||
this.consts.READ_WRITE);e.oncomplete=function(){(d?c:b)(f)};e.onabort=b;e.onerror=b;a=e.objectStore(this.storeName)["delete"](a);a.onsuccess=function(a){d=!0;f=a.target.result};a.onerror=b},batch:function(a,c,b){b||(b=function(a){console.error("Could not apply batch.",a)});c||(c=i);"[object Array]"!=Object.prototype.toString.call(a)&&b(Error("dataArray argument must be of type Array."));var d=this.db.transaction([this.storeName],this.consts.READ_WRITE);d.oncomplete=function(){(g?c:b)(g)};d.onabort= | ||
b;d.onerror=b;var f=a.length,e=!1,g=!1,h=function(){f--;0===f&&!e&&(g=e=!0)};a.forEach(function(a){var c=a.type,f=a.key,g=a.value,a=function(a){d.abort();e||(e=!0,b(a,c,f))};if("remove"==c)g=d.objectStore(this.storeName)["delete"](f),g.onsuccess=h,g.onerror=a;else if("put"==c)"undefined"==typeof g[this.keyPath]&&!this.features.hasAutoIncrement&&(g[this.keyPath]=this._getUID()),g=d.objectStore(this.storeName).put(g),g.onsuccess=h,g.onerror=a},this)},getAll:function(a,c){c||(c=function(a){console.error("Could not read data.", | ||
a)});a||(a=i);var b=this.db.transaction([this.storeName],this.consts.READ_ONLY),d=b.objectStore(this.storeName);d.getAll?this._getAllNative(b,d,a,c):this._getAllCursor(b,d,a,c)},_getAllNative:function(a,c,b,d){var f=!1,e=null;a.oncomplete=function(){(f?b:d)(e)};a.onabort=d;a.onerror=d;a=c.getAll();a.onsuccess=function(a){f=!0;e=a.target.result};a.onerror=d},_getAllCursor:function(a,c,b,d){var f=[],e=!1,g=null;a.oncomplete=function(){(e?b:d)(g)};a.onabort=d;a.onerror=d;a=c.openCursor();a.onsuccess= | ||
function(a){(a=a.target.result)?(f.push(a.value),a["continue"]()):(e=!0,g=f)};a.onError=d},clear:function(a,c){c||(c=function(a){console.error("Could not clear store.",a)});a||(a=i);var b=!1,d=null,f=this.db.transaction([this.storeName],this.consts.READ_WRITE);f.oncomplete=function(){(b?a:c)(d)};f.onabort=c;f.onerror=c;f=f.objectStore(this.storeName).clear();f.onsuccess=function(a){b=!0;d=a.target.result};f.onerror=c},_getUID:function(){return this._insertIdCount++ +Date.now()},getIndexList:function(){return this.store.indexNames}, | ||
hasIndex:function(a){return this.store.indexNames.contains(a)},normalizeIndexData:function(a){a.keyPath=a.keyPath||a.name;a.unique=!!a.unique;a.multiEntry=!!a.multiEntry},indexComplies:function(a,c){return["keyPath","unique","multiEntry"].every(function(b){return"multiEntry"==b&&void 0===a[b]&&!1===c[b]?!0:c[b]==a[b]})},iterate:function(a,c){var c=k({index:null,order:"ASC",filterDuplicates:!1,keyRange:null,writeAccess:!1,onEnd:null,onError:function(a){console.error("Could not open cursor.",a)}},c|| | ||
{}),b="desc"==c.order.toLowerCase()?"PREV":"NEXT";c.filterDuplicates&&(b+="_NO_DUPLICATE");var d=!1,f=this.db.transaction([this.storeName],this.consts[c.writeAccess?"READ_WRITE":"READ_ONLY"]),e=f.objectStore(this.storeName);c.index&&(e=e.index(c.index));f.oncomplete=function(){if(d)if(c.onEnd)c.onEnd();else a(null);else c.onError(null)};f.onabort=c.onError;f.onerror=c.onError;b=e.openCursor(c.keyRange,this.consts[b]);b.onerror=c.onError;b.onsuccess=function(b){(b=b.target.result)?(a(b.value,b,f), | ||
b["continue"]()):d=!0}},query:function(a,c){var b=[],c=c||{};c.onEnd=function(){a(b)};this.iterate(function(a){b.push(a)},c)},count:function(a,c){var c=k({index:null,keyRange:null},c||{}),b=c.onError||function(a){console.error("Could not open cursor.",a)},d=!1,f=null,e=this.db.transaction([this.storeName],this.consts.READ_ONLY);e.oncomplete=function(){(d?a:b)(f)};e.onabort=b;e.onerror=b;e=e.objectStore(this.storeName);c.index&&(e=e.index(c.index));e=e.count(c.keyRange);e.onsuccess=function(a){d=!0; | ||
f=a.target.result};e.onError=b},makeKeyRange:function(a){var c="undefined"!=typeof a.lower,b="undefined"!=typeof a.upper;switch(!0){case c&&b:a=this.keyRange.bound(a.lower,a.upper,a.excludeLower,a.excludeUpper);break;case c:a=this.keyRange.lowerBound(a.lower,a.excludeLower);break;case b:a=this.keyRange.upperBound(a.upper,a.excludeUpper);break;default:throw Error('Cannot create KeyRange. Provide one or both of "lower" or "upper" value.');}return a}};var i=function(){},l={},k=function(a,c){var b,d; | ||
for(b in c)d=c[b],d!==l[b]&&d!==a[b]&&(a[b]=d);return a};h.version=h.prototype.version;return h},this); | ||
multiEntry:a.multiEntry})},this)}.bind(this)},deleteDatabase:function(){this.idb.deleteDatabase&&this.idb.deleteDatabase(this.dbName)},put:function(a,c,b,d){null!==this.keyPath&&(d=b,b=c,c=a);d||(d=function(a){console.error("Could not write data.",a)});b||(b=i);var f=!1,e=null,g=this.db.transaction([this.storeName],this.consts.READ_WRITE);g.oncomplete=function(){(f?b:d)(e)};g.onabort=d;g.onerror=d;null!==this.keyPath?(this._addIdPropertyIfNeeded(c),a=g.objectStore(this.storeName).put(c)):a=g.objectStore(this.storeName).put(c, | ||
a);a.onsuccess=function(a){f=!0;e=a.target.result};a.onerror=d},get:function(a,c,b){b||(b=function(a){console.error("Could not read data.",a)});c||(c=i);var d=!1,f=null,e=this.db.transaction([this.storeName],this.consts.READ_ONLY);e.oncomplete=function(){(d?c:b)(f)};e.onabort=b;e.onerror=b;a=e.objectStore(this.storeName).get(a);a.onsuccess=function(a){d=!0;f=a.target.result};a.onerror=b},remove:function(a,c,b){b||(b=function(a){console.error("Could not remove data.",a)});c||(c=i);var d=!1,f=null, | ||
e=this.db.transaction([this.storeName],this.consts.READ_WRITE);e.oncomplete=function(){(d?c:b)(f)};e.onabort=b;e.onerror=b;a=e.objectStore(this.storeName)["delete"](a);a.onsuccess=function(a){d=!0;f=a.target.result};a.onerror=b},batch:function(a,c,b){b||(b=function(a){console.error("Could not apply batch.",a)});c||(c=i);"[object Array]"!=Object.prototype.toString.call(a)&&b(Error("dataArray argument must be of type Array."));var d=this.db.transaction([this.storeName],this.consts.READ_WRITE);d.oncomplete= | ||
function(){(g?c:b)(g)};d.onabort=b;d.onerror=b;var f=a.length,e=!1,g=!1,h=function(){f--;0===f&&!e&&(g=e=!0)};a.forEach(function(a){var c=a.type,f=a.key,g=a.value,a=function(a){d.abort();e||(e=!0,b(a,c,f))};if("remove"==c)g=d.objectStore(this.storeName)["delete"](f),g.onsuccess=h,g.onerror=a;else if("put"==c)null!==this.keyPath?(this._addIdPropertyIfNeeded(g),g=d.objectStore(this.storeName).put(g)):g=d.objectStore(this.storeName).put(g,f),g.onsuccess=h,g.onerror=a},this)},getAll:function(a,c){c|| | ||
(c=function(a){console.error("Could not read data.",a)});a||(a=i);var b=this.db.transaction([this.storeName],this.consts.READ_ONLY),d=b.objectStore(this.storeName);d.getAll?this._getAllNative(b,d,a,c):this._getAllCursor(b,d,a,c)},_getAllNative:function(a,c,b,d){var f=!1,e=null;a.oncomplete=function(){(f?b:d)(e)};a.onabort=d;a.onerror=d;a=c.getAll();a.onsuccess=function(a){f=!0;e=a.target.result};a.onerror=d},_getAllCursor:function(a,c,b,d){var f=[],e=!1,g=null;a.oncomplete=function(){(e?b:d)(g)}; | ||
a.onabort=d;a.onerror=d;a=c.openCursor();a.onsuccess=function(a){(a=a.target.result)?(f.push(a.value),a["continue"]()):(e=!0,g=f)};a.onError=d},clear:function(a,c){c||(c=function(a){console.error("Could not clear store.",a)});a||(a=i);var b=!1,d=null,f=this.db.transaction([this.storeName],this.consts.READ_WRITE);f.oncomplete=function(){(b?a:c)(d)};f.onabort=c;f.onerror=c;f=f.objectStore(this.storeName).clear();f.onsuccess=function(a){b=!0;d=a.target.result};f.onerror=c},_addIdPropertyIfNeeded:function(a){!this.features.hasAutoIncrement&& | ||
"undefined"==typeof a[this.keyPath]&&(a[this.keyPath]=this._insertIdCount++ +Date.now())},getIndexList:function(){return this.store.indexNames},hasIndex:function(a){return this.store.indexNames.contains(a)},normalizeIndexData:function(a){a.keyPath=a.keyPath||a.name;a.unique=!!a.unique;a.multiEntry=!!a.multiEntry},indexComplies:function(a,c){return["keyPath","unique","multiEntry"].every(function(b){return"multiEntry"==b&&void 0===a[b]&&!1===c[b]?!0:c[b]==a[b]})},iterate:function(a,c){var c=k({index:null, | ||
order:"ASC",autoContinue:!0,filterDuplicates:!1,keyRange:null,writeAccess:!1,onEnd:null,onError:function(a){console.error("Could not open cursor.",a)}},c||{}),b="desc"==c.order.toLowerCase()?"PREV":"NEXT";c.filterDuplicates&&(b+="_NO_DUPLICATE");var d=!1,f=this.db.transaction([this.storeName],this.consts[c.writeAccess?"READ_WRITE":"READ_ONLY"]),e=f.objectStore(this.storeName);c.index&&(e=e.index(c.index));f.oncomplete=function(){if(d)if(c.onEnd)c.onEnd();else a(null);else c.onError(null)};f.onabort= | ||
c.onError;f.onerror=c.onError;b=e.openCursor(c.keyRange,this.consts[b]);b.onerror=c.onError;b.onsuccess=function(b){if(b=b.target.result){if(a(b.value,b,f),c.autoContinue)b["continue"]()}else d=!0}},query:function(a,c){var b=[],c=c||{};c.onEnd=function(){a(b)};this.iterate(function(a){b.push(a)},c)},count:function(a,c){var c=k({index:null,keyRange:null},c||{}),b=c.onError||function(a){console.error("Could not open cursor.",a)},d=!1,f=null,e=this.db.transaction([this.storeName],this.consts.READ_ONLY); | ||
e.oncomplete=function(){(d?a:b)(f)};e.onabort=b;e.onerror=b;e=e.objectStore(this.storeName);c.index&&(e=e.index(c.index));e=e.count(c.keyRange);e.onsuccess=function(a){d=!0;f=a.target.result};e.onError=b},makeKeyRange:function(a){var c="undefined"!=typeof a.lower,b="undefined"!=typeof a.upper;switch(!0){case c&&b:a=this.keyRange.bound(a.lower,a.upper,a.excludeLower,a.excludeUpper);break;case c:a=this.keyRange.lowerBound(a.lower,a.excludeLower);break;case b:a=this.keyRange.upperBound(a.upper,a.excludeUpper); | ||
break;default:throw Error('Cannot create KeyRange. Provide one or both of "lower" or "upper" value.');}return a}};var i=function(){},l={},k=function(a,c){var b,d;for(b in c)d=c[b],d!==l[b]&&d!==a[b]&&(a[b]=d);return a};h.version=h.prototype.version;return h},this); |
{ | ||
"name": "idb-wrapper", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A cross-browser wrapper for IndexedDB", | ||
@@ -13,3 +13,4 @@ "keywords": [], | ||
"Raynos <raynos2@gmail.com> (http://raynos.org)", | ||
"Chad Engler <chad@pantherdev.com> http://chad.pantherdev.com" | ||
"Chad Engler <chad@pantherdev.com> (http://chad.pantherdev.com)", | ||
"Max Ogden <max+ogden@maxogden.com> (http://www.maxogden.com)" | ||
], | ||
@@ -16,0 +17,0 @@ "bugs": { |
@@ -52,3 +52,3 @@ About | ||
``` | ||
//cdnjs.cloudflare.com/ajax/libs/idbwrapper/1.0.0/idbstore.min.js | ||
//cdnjs.cloudflare.com/ajax/libs/idbwrapper/1.1.0/idbstore.min.js | ||
``` | ||
@@ -120,6 +120,8 @@ | ||
'keyPath' is the name of the property to be used as key index. If 'autoIncrement' is set to true, | ||
'keyPath' is the name of the property to be used as key index. If `autoIncrement` is set to true, | ||
the database will automatically add a unique key to the keyPath index when storing objects missing | ||
that property. 'indexes' contains objects defining indexes (see below for details on indexes). | ||
that property. If you want to use out-of-line keys, you must set this property to `null` (see below for details on out-of-line keys). | ||
'indexes' contains objects defining indexes (see below for details on indexes). | ||
'autoIncrement' is a boolean and toggles, well, auto-increment on or off. You | ||
@@ -138,2 +140,6 @@ can leave it to true, even if you do provide your own ids. | ||
### Out-of-line Keys | ||
IDBWrapper supports working with out-of-line keys. This is a feature of IndexedDB, and it means that an object's identifier is not kept on the object itself. Usually, you'll want to go with the default way, using in-line keys. If you, however, want to use out-of-line keys, note that the `put()` and `batch()` methods behave differently, and that the `autoIncrement` property has no effect – you MUST take care of the ids yourself! | ||
Methods | ||
@@ -165,2 +171,12 @@ ======= | ||
**Out-of-line Keys** | ||
If you use out-of-line keys in your store, you must provide a key as first argument to the put method: | ||
```javascript | ||
put(/*Anything*/ key, /*Object*/ dataObj, /*Function?*/onSuccess, /*Function?*/onError) | ||
``` | ||
The `onSuccess` and `onError` arguments remain optional. | ||
___ | ||
@@ -268,2 +284,13 @@ | ||
**Out-of-line Keys** | ||
If you use out-of-line keys, you must also provide a key to put operations: | ||
```javascript | ||
{ type: "put", value: dataObj, key: 12345 } // also add a `key` property containing the object's identifier | ||
``` | ||
Index Operations | ||
@@ -354,3 +381,2 @@ ---------------- | ||
The `index` property contains the name of the index to operate on. If you omit this, IDBWrapper will use the store's keyPath as index. | ||
@@ -362,2 +388,4 @@ | ||
The `autoContinue` property defaults to true. If you set this to false, IDBWrapper will not automatically advance the cursor to next result, but instead pause after it obtained a result. To move the cursor to the next result, you need to call the cursor object's `continue()` method (you get the cursor object as second argument to the `onItem` callback). | ||
The `filterDuplicates` property is an interesting one: If you set this to true (it defaults to false), and have several objects that have the same value in their key, the store will only fetch the first of those. It is not about objects being the same, it's about their key being the same. For example, in the customers database are a couple of guys having 'Smith' as last name. Setting filterDuplicates to true in the above example will make `iterate()` call the onItem callback only for the first of those. | ||
@@ -364,0 +392,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5503124
35
3454
460