Worklight v6: use multiple JSON stores concurrently in app

陌路散爱 提交于 2019-12-24 15:31:22

问题


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:


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.



来源:https://stackoverflow.com/questions/19850287/worklight-v6-use-multiple-json-stores-concurrently-in-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!