Enables grouping writeItem
, getItems
and
runQuery
calls to the Client Store API into a batch to be executed
as a single transaction.
This method can be called no earlier than after the getOfflineStorageCount
method's onSuccess
callback is invoked during the first application start. Otherwise, the function fails with
onFailure
callback invoked.
Name | Description | Type | Use |
---|---|---|---|
onCollectQueries | A callback function, which allows to define queries as part of the
batch parameter. It passes an object that defines functions,
whose signatures match those given in the getItems, writeItem and runQuery articles. |
function |
required |
onSuccess | A callback function, which passes a |
function |
optional |
onFailure | A callback function, called if any of the queries forming the batch fails. It passes an error code, as defined in the Constants table in the Client Store article. | function |
optional |
The onCollectQueries
callback can be implemented as
follows:
function(batch) { batch.writeItem("type of item 1", "handle of item 1", "data of item 1"); batch.writeItem("type of item 2", "handle of item 2", "data of item 2"); batch.getItems("type of item 3", "handle of item 3"); }
The writeItem
and runQuery
calls
cannot exist in a single batch.
As its call parameter, the onSuccess
callback returns an array of
objects passed to the onSuccess
callback of their respective
functions. For the writeItem
method, the object is null, which
denotes that no parameter is passed.