Skip to content

Instantly share code, notes, and snippets.

@jensarps
Created November 13, 2012 14:03
Show Gist options
  • Save jensarps/4065904 to your computer and use it in GitHub Desktop.
Save jensarps/4065904 to your computer and use it in GitHub Desktop.
Code for IDBWrapper Tutorial, Part 2
customers.iterate(onItem, {
index: 'lastname',
keyRange: myKeyRange,
order: 'ASC',
filterDuplicates: false,
writeAccess: false,
onEnd: onEndCallback,
onError: onErrorCallback
});
customers.iterate(onItem, {
index: 'lastname',
keyRange: IDBKeyRange,
order: 'ASC',
filterDuplicates: false,
writeAccess: false,
onEnd: onEndCallback,
onError: onErrorCallback
});
var myKeyRange = customers.makeKeyRange({
upper: 'M',
excludeUpper: true
});
var myKeyRange = customers.makeKeyRange({
lower: 'A',
excludeLower: false,
upper: 'M',
excludeUpper: true
});
indexes: [
{ name: 'lastname' }
]
customers = new IDBStore({
dbVersion: 1,
storeName: 'customer-index',
keyPath: 'customerid',
autoIncrement: true,
onStoreReady: refreshTable,
indexes: [
{ name: 'lastname', keyPath: 'lastname', unique: false, multiEntry: false }
]
});
var onItem = function(dataObj, cursor, transaction){
if(dataObj.age < 18){
var deleteRequest = cursor.delete(); // request deletion of current object
deleteRequest.onsuccess = function(evt){ /* ... */ };
deleteRequest.onerror = function(err){ /* ... */ };
}
if (dataObj.age >= 50) {
dataObj.isSenior = true;
var updateRequest = cursor.update(dataObj); // request to overwrite object with object passed to update() method
updateRequest.onsuccess = function(evt){ /* ... */ };
updateRequest.onerror = function(err){ /* ... */ };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment