MS Open Tech brings a new WebSQL plugin for Apache Cordova and enhancements to the popular Contacts plugin

pluggyMicrosoft Open Technologies is publishing the new open source WebSQL plugin for Apache Cordova and PhoneGap. This plugin allows developers to integrate a persistent SQL-based local storage solution in their Cordova apps using the exact same JavaScript code across Android, iOS, Windows Phone and Windows Store. MS Open Tech is also contributing new features inspired by Windows to the popular Contacts plugin as well as a better Windows Store apps support.

Apache Cordova is a popular open source platform to build native mobile applications with HTML5, JavaScript and CSS. It supports all major mobile platforms and comes with a set of plugins bridging the Web world of HTML and JavaScript with the native world of mobile platforms. If you want to develop the same application across iOS, Android, Windows Phone, with the same JavaScript code that takes advantage of OS resources such as contacts, accelerometer, camera, local storage… then Apache Cordova is for you.

MS Open Tech is a long time contributor to the open source Apache Cordova project, helping on the Windows Phone 8 and Windows 8 support and more recently on the addition of new features to popular plugins with the goal of helping Cordova developers extend their reach to Windows devices. The Contacts plugin is amongst the most used plugins in Cordova applications, and the need for a cross-platform solution for local database storage is in the top list of requests from developers.

These new features contributed by MS Open Tech accrue to Apache Cordova’s goal to allow developers to build immersive native-like experiences with Web technologies across mobile platforms. MS Open Tech wants to help developer who chose web technologies to build mobile apps across platforms to be able to reuse as much code as possible and extend their reach to Windows devices. With these contributions, developers can now have their Cordova Web app pick a contact directly from the native contact app, make searching contacts faster, and deliver an offline persistence storage experience using the same Web code across Android, iOS, Windows Store and Windows Phone apps.

New cross platform WebSQL plugin for Cordova apps on iOS, Android, WP8 and Windows Store

The new WebSQL plugin developed by MS Open Tech allows Cordova apps to store data on devices that will persist across restarts of the app and reboots of the device using a SQL interface. MS Open Tech has developed the WebSQL plugin with support for Android, iOS, Windows Phone 8 and Windows Store. Under the hood, the plugin is using WebSQL on iOS and Android, and the open source SQLite library on Windows devices. SQLite happens to be easily usable across Windows devices using the SQLitePCL portable Class Library published recently.

As you can see in the demo below, you can now easily build an Apache Cordova app that will store data in a local database running the same code on Android, iOS, Windows Phone 8 or Windows 8.

The plugin can be found on the Apache Cordova plugins registry

Creating or opening a DataBase is as simple as one line of code in your Cordova app:

  1. app.db = openDatabase("Todo", "", "Todo manager", dbSize,
  2. function() {
  3. console.log('db successfully opened or created');
  4. });

Then all consequent calls are in the form of SQL transactions. For example, creating or opening a table consists in the following:

  1. app.db.transaction(function (tx) {
  2. tx.executeSql("CREATE TABLE IF NOT EXISTS todo(ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on DATETIME)", [], app.onSuccess, app.onError);
  3. });

The popular Contacts Plugin gets some of Windows mojo

Accessing the Contacts list from a mobile app is very common and Cordova developers use the Cordova Contacts plugin maintained by the Cordova community to add this functionality to their apps.

MS Open Tech is enhancing the Contacts plugin’s Windows Store apps support that was partial so far and is working at adding some features inspired by the way Windows makes Contacts available to native Windows Store apps.

One thing that was missing from the Contacts plugin API was the ability to leverage the native contacts list UI to pick contacts. So far, in order to pick a contact from the phone contacts list, you had to pull the full list of contacts in your own app and expose it yourself to the user for him to pick one.

Now, with MS Open Tech’s contribution, you have a new API called pickContact that mirrors the Windows 8 Contact mechanism for native apps. This new API allows you to pick a single contact directly from the phone’s native Contacts user interface on Android, iOS, Windows Phone, and Windows 8. The single line below will invoke the native Contacts UI and will return the selected contact back to your Cordova app calling back the contactPicked function:

  1.  
  2. navigator.contacts.pickContact(app.contactPicked, app.onError);

We also brought a new feature to the contacts plugin API. When searching for specific info in the contacts list, there was no way to define specific fields you were interested in. Even if you only wanted one field back, you still had to pull the whole contacts info, making the process longer and heavier memory wise. Now, when using the findContacts API, you can determine which fields you want to retrieve like shown below:

  1. var options = new ContactFindOptions();
  2. options.filter = 'bob';
  3. options.multiple = true;
  4. var desiredFields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name]; navigator.contacts.find(app.onSuccess, app.onError, desiredFields, options);

While we are working on merging our contribution into the main Cordova Contacts plugin repository, you can find MS Open Tech’s work here.

More coming soon

These new contributions for Apache Cordova developers are only the first of a series MS Open Tech plans to do in addition to the continuous development for Windows device support. As MS Open Tech’s developers are working on more new features for existing Cordova plugins and brand new plugins, you should feel free to send us your feedback commenting on this post or commenting/contributing on GitHub.


12 thoughts on “MS Open Tech brings a new WebSQL plugin for Apache Cordova and enhancements to the popular Contacts plugin

  1. Pingback: Dew Drop – May 6, 2014 (#1770) | Morning Dew

    • Hey Raymond. Thanks for the heads up on the typo. I am struggling with the tag in WordPress, seems to not like code lines starting with “n”… weird…

  2. The WebSQL plugin is amazing – would really help us with our customers who want to use Windows Phone, and adds enormous value to the web app community!

    …However, I notice it doesn’t currently support transactions (inc. having transaction callbacks at all according to an issue on github?) – this is a real shame since, certainly with iOS/Android we’ve found it necessary to batch up large numbers of SQL statements into a single transaction to get acceptable performance (aside from other robustness motivations for using transactions), so (assuming that raised issue is correct) we couldn’t use the plugin with our code “as is”.

    Any idea if this gap will be closed at any point?

  3. Pingback: Novo plugin WebSQL facilita desenvolvimento multiplataforma no Apache Cordova |

  4. Am I right in thinking the transaction implementation is fudged in the WebSQL plugin? The transaction is a no-op and simply provides an object that provided an executeSql() method that runs the supplied SQL statement in its own transaction. So basically it does not support multi statement transactions. This is causing issues when trying to perform concurrent SQLs which works fine in browser implementations.

  5. Will this plugin work without installing cordova ?
    My project is a port from a webSQL application, but does not require cordova (native store app is fine)

    • The plugin is dedicated to Cordova, and will not work as is.
      However you can extract the code from it (it is open source !) to make it work without Cordova

  6. Pingback: free followers on instagram

Leave a Reply