Search code examples
iossqlitecore-datacordovalawnchair

Phonegap iOS DB Query


I am using Phonegap 1.3.0, and want to develop an app which uses local storage. Some googling brought me to sqlite, but i have had no success in implementing it in my app.

https://github.com/davibe/Phonegap-SQLitePlugin

I tried this link but i am really not sure what this lawnchair.js is all about. Sqlite is my priority but I can try other options too. I also tried window.opendatabase() but it doesnt work in my app.

Thanks in advance!


Solution

  • Lawnchair is a wrapper over many storage methods. There is localstorage, sqlite, blackberry specific, and others.
    There are many adapters in lawnchair to store stuff.
    http://westcoastlogic.com/lawnchair/adapters/
    The way lawnchair works is, if an adapter is specified, it will use that, or if no adapter is specified and if the code of all adapters is appended to lawnchair.js file, then lawnchair checks which one to use in the order of they are appended and picks the first one it finds suitable.

    What makes lawnchair easy to use is that we don't have to deal with sql syntaxs (assuming u want to use sqlite adapter.) You just store and retrieve your data in JSON by

    table.save(key:"obj", name:{a:"aaaa", b:"bbbb"})
    
    table.get(key:"obj", function(ob){
      //callback
    })
    

    and internally lawnchair will save data in sqlite.
    You can use any adapter, but all u have to use is the above syntax. easy. lawnchair is a powerful wrapper over many storage options. check it out