Created
November 13, 2012 14:03
-
-
Save jensarps/4065904 to your computer and use it in GitHub Desktop.
Code for IDBWrapper Tutorial, Part 2
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
customers.iterate(onItem, { | |
index: 'lastname', | |
keyRange: myKeyRange, | |
order: 'ASC', | |
filterDuplicates: false, | |
writeAccess: false, | |
onEnd: onEndCallback, | |
onError: onErrorCallback | |
}); |
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
customers.iterate(onItem, { | |
index: 'lastname', | |
keyRange: IDBKeyRange, | |
order: 'ASC', | |
filterDuplicates: false, | |
writeAccess: false, | |
onEnd: onEndCallback, | |
onError: onErrorCallback | |
}); |
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
var myKeyRange = customers.makeKeyRange({ | |
upper: 'M', | |
excludeUpper: true | |
}); |
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
var myKeyRange = customers.makeKeyRange({ | |
lower: 'A', | |
excludeLower: false, | |
upper: 'M', | |
excludeUpper: true | |
}); |
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
indexes: [ | |
{ name: 'lastname' } | |
] |
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
customers = new IDBStore({ | |
dbVersion: 1, | |
storeName: 'customer-index', | |
keyPath: 'customerid', | |
autoIncrement: true, | |
onStoreReady: refreshTable, | |
indexes: [ | |
{ name: 'lastname', keyPath: 'lastname', unique: false, multiEntry: false } | |
] | |
}); |
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
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