Stumbled upon this question while looking for something else, but I think I have template code that will make you start wrapping webSql queries in jQuery Promises.
This is a sample sqlProviderBase to $.extend on your own provider. I have an example with taskProvider and a page that is called on taskProvider on the show page event. This is pretty rare, but I hope this helps others in the right direction wrap their requests in the promise of better governance.
var sqlProviderBase = { _executeSql: function (sql, parms) { parms = parms || []; var def = new $.Deferred(); // TODO: Write your own getDb(), see http://www.html5rocks.com/en/tutorials/webdatabase/todo/ var db = getDb(); db.transaction(function (tx) { tx.executeSql(sql, parms, // On Success function (itx, results) { // Resolve with the results and the transaction. def.resolve(results, itx); }, // On Error function (etx, err) { // Reject with the error and the transaction. def.reject(err, etx); }); }); return def.promise(); } }; var taskProvider = $.extend({}, sqlProviderBase, { getAllTasks: function() { return this._executeQuery("select * from Tasks"); } }); var pageThatGetsTasks = { show: function() { taskProvider.getAllTasks() .then(function(tasksResult) { for(var i = 0; i < tasksResult.rows.length; i++) { var task = tasksResult.rows.item(i); // TODO: Do some crazy stuff with the task... renderTask(task.Id, task.Description, task.IsComplete); } }, function(err, etx) { alert("Show me your error'd face: ;-[ "); }); } };
Jacob source share