Class WL.JSONStore

WL.JSONStore

Description:

Descriptions and reference information for the JSONStore API functions.

For an overview and more descriptive information, see the JSONStore overview section in the IBM® MobileFirst® user documentation.


Method Summary
Method Attributes Method Name and Description
 
changePassword(oldPassword, newPassword, username, options)
Changes the password for the internal storage.
 
Removes the password from memory.
 
closeAll(options)
Locks access to all the collections until WL.JSONStore.init is called.
 
Commit a transaction.
 
destroy(username, options)
Completely wipes data for all users, destroys the internal storage, and clears security artifacts.
 
documentify(id, data)
Takes an _id and a JSON object and creates a JSONStore document.
 
Returns information about the file that is used to persist data in the store.
 
get(collectionName)
Provides an accessor to the collection if the collection exists, otherwise it returns undefined.
 
getErrorMessage(errorCode)
Returns the message that is associated with a JSONStore error code.
 
init(collections, options)
Starts one or more collections.
 
initCollection(name, searchFields, options)
Returns an accessor (also known a JSONStoreInstance) to a single collection.
 
Creates a query for advanced find.
 
Roll back a transaction.
 
Initiates a transaction.
 
Sets the password that is used to generate keys to encrypt data that is stored locally on the device.
Method Detail
changePassword
{Promise} changePassword(oldPassword, newPassword, username, options)
Changes the password for the internal storage. You must have an initialized collection before calling WL.JSONStore.changePassword.
Parameters:
{string} oldPassword - The old password. Must be alphanumeric ([a-z, A-Z, 0-9]), begin with a letter and have least 1 character.
{string} newPassword - The new password Must be alphanumeric ([a-z, A-Z, 0-9]), begin with a letter and have least 1 character.
{string} username Optional - Default user name is 'jsonstore'. Must be alphanumeric ([a-z, A-Z, 0-9]), begin with a letter and have least 1 character.
{object} options Optional
{function} options.onSuccess Optional - Deprecated. Success callback.
{function} options.onFailure Optional - Deprecated. Failure callback.
{integer} options.pbkdf2Iterations Optional - Change the number of iterations used by the Password-Based Key Derivation Function 2 (PBKDF2) algorithm used to secure the password. The default is 10,000 iterations. This is currently only supported on Android, and will be ignored in other versions, using 10,000 in those.
Returns:
{Promise} Resolved when the operation succeeds. Rejected when there is a failure.

clearPassword
{boolean} clearPassword()
Removes the password from memory.
Returns:
{boolean} Returns true if the password that is stored in memory was set to null, false if there was no password in memory or if it was not set to null.
Deprecated:
Since IBM® Worklight® V5.0.6, it is no longer needed if you use WL.JSONStore.init

closeAll
{Promise} closeAll(options)
Locks access to all the collections until WL.JSONStore.init is called.
Parameters:
{object} options Optional
{function} options.onSuccess Optional - Deprecated. Success callback.
{function} options.onFailure Optional - Deprecated. Failure callback.
Returns:
{Promise} Resolved when the operation succeeds. Rejected when there is a failure.

commitTransaction
{Promise} commitTransaction()
Commit a transaction.
Returns:
{Promise} Resolved when the operation succeeds, returns an integer. Rejected when there is a failure.

destroy
{Promise} destroy(username, options)
Completely wipes data for all users, destroys the internal storage, and clears security artifacts.
Parameters:
{string} username Optional - Only removes data that is related to the specific username that is passed.
{object} options Optional - Deprecated.
{function} options.onSuccess Optional - Deprecated. Success callback.
{function} options.onFailure Optional - Deprecated. Failure callback.
Returns:
{Promise} Resolved when the operation succeeds. Rejected when there is a failure.

documentify
{object} documentify(id, data)
Takes an _id and a JSON object and creates a JSONStore document.
Parameters:
{integer} id - _id for the Document
{object} data - JSON data for the Document
Returns:
{object} JSONStore document.
Deprecated:
Since IBM® Worklight® V6.2.0.

fileInfo
{Promise} fileInfo()
Returns information about the file that is used to persist data in the store. The following key value pairs are returned: name - name of the store, size - the total size, in bytes, of the store, and isEncrypted - boolean that is true when encrypted and false otherwise.
Returns:
{Promise} Resolved when the operation succeeds. Rejected when there is a failure.

get
{WL.JSONStore.JSONStoreInstance} get(collectionName)
Provides an accessor to the collection if the collection exists, otherwise it returns undefined.
Parameters:
{string} collectionName - Name of the collection.
Returns:
{WL.JSONStore.JSONStoreInstance} Allows access to the collection by name.

getErrorMessage
{string} getErrorMessage(errorCode)
Returns the message that is associated with a JSONStore error code.
Parameters:
{integer} errorCode - The error code.
Returns:
{string} The Error Message that is associated with the status code or 'Not Found' if you pass an invalid value (non-integer) or a nonexistent status code.

init
{Promise} init(collections, options)
Starts one or more collections.
Parameters:
{object} collections - Metadata about the collections.
{string} collections.collectionName - Name of the the collection, must be an alphanumeric string ([a-z, A-Z, 0-9]) that starts with a letter.
{object} collections.collectionName.searchFields - The key value pairs in the data that will be indexed, by default nothing is indexed.
{object} collections.collectionName.additionalSearchFields Optional - The additional key value pairs that will be indexed, by default nothing is indexed.
{object} collections.collectionName.adapter Optional - Metadata about the adapter that will be linked to the collection.
{string} collections.collectionName.adapter.name - Name of the Adapter.
{string} collections.collectionName.adapter.add Optional - Name of the add procedure.
{string} collections.collectionName.adapter.remove Optional - Name of remove procedure.
{object} collections.collectionName.adapter.load Optional - Metadata about the load procedure.
{string} collections.collectionName.adapter.load.procedure - Name of the load procedure.
{array} collections.collectionName.adapter.load.params - Parameters that are sent to the load procedure.
{string} collections.collectionName.adapter.load.key - Key in the response object containing objects to add.
{function} collections.collectionName.adapter.accept Optional - Called after push with the response from the adapter, must return a boolean.
{integer} collections.collectionName.adapter.timeout Optional - Timeout for the adapter call.
{object} options Optional - Options that apply to the store.
{string} options.username Optional - Name of the file that is created to store data for the collections, must be an alphanumeric string ([a-z, A-Z, 0-9]) and start with a letter. The default one is 'jsonstore'.
{string} options.password Optional - Password that is used to secure the contents of the store, by default there is no data encryption.
{boolean} options.clear Optional - Clears accessors without removing its contents from the store.
{boolean} options.localKeyGen Optional - Flag that determines if key generation uses a local (false) or remote (true) random number generator.
{boolean} options.analytics Optional - Enable the collection of analytics information for Android and iOS.
{integer} options.pbkdf2Iterations Optional - Change the number of iterations used by the Password-Based Key Derivation Function 2 (PBKDF2) algorithm used to secure the password. The default is 10,000 iterations. This is currently only supported on Android, and will be ignored in other versions, using 10,000 in those.
Returns:
{Promise} Resolved when all collections have been initialized. Rejected when there is a failure (no accessors created).

initCollection
{WL.JSONStore.JSONStoreInstance} initCollection(name, searchFields, options)
Returns an accessor (also known a JSONStoreInstance) to a single collection.
Parameters:
{string} name - Name of the the collection, must be an alphanumeric string ([a-z, A-Z, 0-9]) that starts with a letter.
{object} searchFields - The key value pairs in the data that will be indexed, by default nothing is indexed.
{options} options - Options that you can pass to WL.JSONStore.init.
Returns:
{WL.JSONStore.JSONStoreInstance} Accessor to a single collection.
Deprecated:
Since IBM® Worklight® V5.0.6, it is no longer needed if you use WL.JSONStore.init

QueryPart
QueryPart()
Creates a query for advanced find. See WL.JSONStore.QueryPart for more information.
Example:
WL.JSONStore.QueryPart();

rollbackTransaction
{Promise} rollbackTransaction()
Roll back a transaction.
Returns:
{Promise} Resolved when the operation succeeds, returns an integer. Rejected when there is a failure.

startTransaction
{Promise} startTransaction()
Initiates a transaction.
Returns:
{Promise} Resolved when the operation succeeds, returns an integer. Rejected when there is a failure.

usePassword
{boolean} usePassword(pwd)
Sets the password that is used to generate keys to encrypt data that is stored locally on the device.
Parameters:
{string} pwd - String that contains the password.
Returns:
{boolean} Returns true if the password is a valid string, false otherwise.
Deprecated:
Since IBM® Worklight® V5.0.6, it is no longer needed if you use WL.JSONStore.init

© Copyright IBM Corp. 2011, 2016.