-
-
Save jonjenkins/927981 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
Original: A simple stratified wrapper over the asynchronous webdatabase api (webkit) | |
from http://gist.github.com/613526 | |
Existing openDatabase and executeSql methods | |
Added executeBulkSql as a method to group sql statements prior to transaction-level commit; | |
this is much faster for bulk transactions as opposed to individual transaction executions | |
from http://gist.github.com/927981 | |
*/ | |
exports.openDatabase = function (name, version, desc, size) { | |
var db = openDatabase(name, version, desc, size); | |
return { | |
executeBulkSql: function (arrSql, params) { | |
var rv; | |
this.transaction(function(tx){ | |
for (var i = 0, l = arrSql.length; i < l; i++) | |
rv = tx.executeSql(arrSql[i], params); | |
}); | |
return rv; | |
}, | |
executeSql: function (sql, params) { | |
var rv; | |
this.transaction(function(tx){ | |
rv = tx.executeSql(sql, params); | |
}); | |
return rv; | |
}, | |
transaction: function (cb) { | |
var error; | |
waitfor() { | |
db.transaction(function(t) { | |
var tx = { | |
executeSql: function (sql, params) { | |
waitfor(var dummytx, rv) { | |
t.executeSql(sql, params, resume); | |
} | |
return rv; | |
} | |
} | |
cb(tx); | |
resume(); | |
}, function (f) { | |
error = f; | |
resume(); | |
}); | |
} | |
if (error) throw error; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment