1

Is it possible to use two or more JSON stores in a Worklight app at the same time (without switching back and forth)? When I initialize a second JSON store with a username/password, collections in the "default" JSON store that were initialized properly become inaccessible.

Given that many functions in the JSON store api does not let you specify a target store, I am guessing that using multiple stores concurrently is not possible. If this is true, then how does one address the use case where it is necessary to:

  1. Encrypt sensitive user data, and
  2. Need access to non-sensitive data before user is authenticated.

1 Answers1

2

The username field you pass to init is basically the file name for the store, for example:

WL.JSONStore.init(..., {username: 'store1'})

You will have store1.sqlite on disk, no encryption. If you want to switch to another store simply call:

WL.JSONStore.closeAll()

The closeAll function will kill all database accessors. Then you can start a second store with a password, for example:

WL.JSONStore.init(..., {username: 'store2', password: '123'})

That will create a store2.sqlite file encrypted with 256-bit AES encryption.

If you want to switch back to store1, simply call WL.JSONStore.closeAll() and then WL.JSONStore.init(..., {username: 'store1'}).

Currently you can not access store1 and store2 at the same time. You can open a feature request here.

The .sqlite files are mentioned here if you want to see them on the file system, and a bit of their internal structure is mentioned here. The code snippets above don't show it, but make sure you take into account that most JSONStore API functions are async, read more here.

cnandreu
  • 5,113
  • 3
  • 25
  • 50
  • Thanks for the detailed answer. I think this kind of information should be in the official documentation, and there needs to be more examples. – user2956676 Nov 09 '13 at 00:15
  • @user2956676 It would be helpful if you explain what confused you or what you didn't understand from reading the official documentation. Did you read it all? There's [general docs](http://pic.dhe.ibm.com/infocenter/wrklight/v6r0m0/topic/com.ibm.worklight.help.doc/devref/c_jsonstore_overview.html), [API docs](http://pic.dhe.ibm.com/infocenter/wrklight/v6r0m0/topic/com.ibm.worklight.help.doc/devref/c_wl_jsonstore_core_api.html) and [example code](http://www.ibm.com/developerworks/mobile/worklight/getting-started.html#advanced-client-side-development). Feedback is appreciated. – cnandreu Nov 09 '13 at 02:00