brianleroux / lawnchair

A lightweight clientside JSON document store,
http://brianleroux.github.com/lawnchair
MIT License
2.14k stars 245 forks source link

Callback after Creating Lawnchair Object #16

Closed ckpoon closed 12 years ago

ckpoon commented 13 years ago

Hi,

Thanks for the powerful db adapter first I tried to use this on both web-based and phonegap based application. It works great in my web-based(chrome, safari...) application with webkit sqlite :)

for my phonegap project, I tried to build an android application with the same source code, phonegap and lawnchair. There are 2 cases:

  1. If the app is 1st installed and launched, the script will be dead when there is any function call, let's use store as the object. e.g. store.get(....) store.all(......) store.save(...)
  2. Close the apps, and restart the apps, everything fine.

Did I miss something before calling .get .all? or did I miss something after new Lawnchair? Thanks.

bryfox commented 13 years ago

Sounds like the problem was that the table had not yet been created when the call to all() was made. (Which is why subsequent loads of the app succeed.)

The way the webkit SQLite adaptor is currently written, there's no way to provide a callback to be notified when the table has been created. You can provide an onError callback when instantiating a Lawnchair, but I'm not sure how reliably you can handle all of your error cases in the same callback. For example:

@@@ App.Users = new Lawnchair({table:'users', onError:function (o,e){debug.log("SQL error [" + e.code + "]: " + e.message)}}); @@@

@@@ [INFO] SQL error [1]: no such table: users @@@

Is the code for "no such table" always 1, cross-platform on devices using this adaptor? Seems like there should be a better way to handle this... maybe the adaptor supports an onCreate option?

brianleroux commented 12 years ago

check out 0.6.x api