Question about SQLlite / implementation within Cordova projects

Hey there,

Got a question about SQLlite, and how to implement this in a Ionic based Cordova project.

I’ve noticed there are quite a few modules available to do that. You could roll your own implementation, or you could use a wrapper that exposes SQLlite features through an API such as Lawnchair or PouchDB. PouchDB even has an Angular module available: https://github.com/wspringer/angular-pouchdb.

Now I noticed there is also a Cordova plugin for SQLlite: https://github.com/brodysoft/Cordova-SQLitePlugin and some people are already asking for this plugin to be included in NgCordova.

My question is, why would you use a Cordova plugin for SQLlite? Doesn’t Cordova’s webview already support SQLlite by default? What would be the upside of using a Cordova plugin for this instead of a js library on top of the Cordova webview?

SQLite web database, known as WebSQL, was deprecated and is not part of the HTML/JS specification anymore. It was replaced by IndexedDB as the default database for complex applications on the web (for political and bureocratic reasons, one could say). However it’s important to note that although it was deprecated, it wasn’t removed from browsers that had already implemented it. It’s just not part of the specification anymore (so don’t count on support for the future).

The current state of the WebSQL support is very good still, and was better than IndexedDB until the leak that IDB will be on Safari 8. See this for the full support table.

Also good to note that for many WebSQL was/is a better fit for really complex apps than IndexedDB, as it has more features and a somewhat cleaner API.

Plugins like SQLitePlugin and Couchbase Lite aims to bring WebSQL support to every main cordova platform, specially those that doesn’t support WebSQL by default like Windows Phone 8 and FirefoxOS. It’s also known that plugins that bring the core DB to the native side via plugins have some performance advantages over the direct web alternative.

1 Like

If you want a 100% working example that works either on Device or Browser, refer to this app template: http://codecanyon.net/item/quizionic-a-quiz-app-template-for-ionic-framework-with-sqlite-database/14205904