I’m building an app with offline functionality and am working with with WebSQL (I know it’s deprecated, but it’s what comes with PhoneGap)
I want to create an SQL find function that parses results and then calls a function that I’m passing to the findAll function.
This is coffeescript, but I can translate into Javascript if that will get me an answer!
class window.TimeTravelDB
findAll: (tableName, callback) ->
@db.transaction (tx) ->
tx.executeSql("Select * from #{tableName}", [], @db.querySuccess, @db.onError)
querySuccess: (tx, results) ->
rows = results.rows
results = (JSON.parse(rows.item(i).data) for i in [0...rows.length])
callback(results)
return @results
How can I specify the callback for the querySuccess function in the findAll function?
You could try using an intermediate callback rather than going directly to
querySuccess, with=>to keep context for@db:This will allow it to forward on the
callbackpassed tofindAll:Then adjust
querySuccessfor the argument: