Created
November 20, 2011 23:55
-
-
Save buley/1381200 to your computer and use it in GitHub Desktop.
Generalized cursor update
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
InDB.cursor.update = function (store, index, keyRange, data, direction, on_success, on_error, on_abort) { | |
var request, transaction, tx, transaction_index, update_request, cursor, value, attr; | |
try { | |
tx = InDB.db.transaction([database], type, timeout); | |
transaction = request.objectStore(database); | |
} catch (event) { | |
throw ('Transaction error'); | |
}; | |
if ('undefined' !== typeof index && null !== index) { | |
transaction_index = transaction.index(index); | |
request = transaction_index.openCursor(keyRange, direction); | |
} else { | |
request = transaction.openCursor(keyRange, direction); | |
} | |
request.onsuccess = function (open_event) { | |
cursor = open_event.target.result; | |
value = open_event.target.result.value; | |
for (attr in data) { | |
if (data.hasOwnProperty(attr)) { | |
value[attr] = data[attr]; | |
} | |
} | |
if ("undefined" !== typeof cursor && null !== cursor && "undefined" !== typeof result && null !== result) { | |
update_request = cursor.update(data); | |
update_request.on_success = function (event) { | |
on_success(context); | |
if ('function' === typeof cursor.continue) { | |
cursor.continue(); | |
} | |
} | |
} | |
} | |
request.onerror = function (open_event) { | |
on_error(open_event); | |
} | |
request.onabort = function (open_event) { | |
on_abort(open_event); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment