Class WL.JSONStore.JSONStoreInstance
WL.JSONStore.JSONStoreInstance
Method Summary
Method Attributes |
Method Name and Description |
|
Stores data as documents inside a collection.
|
|
Locates a document inside a collection by using query parts.
|
|
Used to load data when existing data exists in the store.
|
|
Clears a collection for reuse.
|
|
Returns the number of documents inside a collection.
|
|
Returns the number of documents with local-only changes (that is, dirty documents).
|
|
The enhance function allows developers to extend the core API to better fit their needs.
|
|
Deletes a document from the collection.
|
|
Locates a document inside a collection using a query.
|
|
Returns all of the documents stored in a collection.
|
|
Returns one or more documents that match the _id that is supplied to the function.
|
|
Returns all documents that are marked dirty.
|
|
Returns a boolean that is true if the document is dirty, false otherwise.
|
|
Gets data that is defined in the load portion of the adapter.
|
|
Marks an array of documents as clean.
|
|
Pushes documents inside the collection that have local-only changes to an IBM® MobileFirst® adapter
that is linked during the init function.
|
|
Pushes only the selected documents.
|
|
Replaces a document with another document.
|
|
Marks a document as deleted inside a collection.
|
|
Deletes all the documents that are stored inside a collection.
|
|
Overwrites a document with a given document.
|
|
Writes data to a collection.
|
|
Prints the contents of the collection by using WL.Logger.debug asynchronously.
|
Method Detail
add
{Promise}
add(data, options)
Stores data as documents inside a collection.
- Parameters:
-
{array|object}
data
- Data to be added the collection.
-
{object}
options
Optional
-
{object}
options.additionalSearchFields
Optional
- Search fields that are not part of the data passed.
-
{boolean}
options.markDirty
Optional
- Default value is true, determines if the data will be marked as dirty.
-
{boolean}
options.push
Optional
- Deprecated. Default value is true, determines if the data will be marked as needed to be pushed to an adapter.
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns the number of documents added.
Rejected when there is a failure.
advancedFind
{Promise}
advancedFind(query, options)
Locates a document inside a collection by using query parts.
The ability to search using between, inside, lessThan, greaterThan, etc. in your query search. Consider using the following helper
WL.JSONStore.QueryPart
.
- Parameters:
-
{array}
query
- Defines what to search for in the collection.
-
{object}
options
Optional
-
{integer}
options.limit
Optional
- Maximum number of documents to return, the default behavior is to return everything.
-
{integer}
options.offset
Optional
- Number of documents to skip from the results, depends on the limit.
-
{array}
options.filter
Optional
- Return only the specified search fields, by default return
_id
and json
.
-
{array}
options.sort
Optional
- Sort documents based on their search fields, either ascending or descending.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an array of results.
Rejected when there is a failure.
change
{Promise}
change(data, options)
Used to load data when existing data exists in the store. Internally it is an alias for a targeted replace and add.
- Parameters:
-
{array|object}
data
- Data to be added the collection.
-
{object}
options
Optional
-
{boolean}
options.addNew
Optional
- Default value is false, determines if the data will added if data is not in collection.
-
{boolean}
options.markDirty
Optional
- Default value is false, determines if the data will be marked as dirty.
-
{array}
options.replaceCriteria
Optional
- Determines which documents will be replaced based on the given search field or search fields.
If the parameter is not specified or is an empty array, then the data will not be replaced.
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns the number of documents replaced or added.
Rejected when there is a failure.
clear
{Promise}
clear()
Clears a collection for reuse.
- Parameters:
-
{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.
count
{Promise}
count(query, options)
Returns the number of documents inside a collection.
- Parameters:
-
{object}
query
Optional
- Defines what to search for in the collection. If it is not passed, it will count everything in the collection.
-
{object}
options
Optional
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an integer.
Rejected when there is a failure.
countAllDirty
{Promise}
countAllDirty(options)
Returns the number of documents with local-only changes (that is, dirty documents).
This function was previously called JSONStoreIntance.pushRequiredCount.
- 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, returns an integer.
Rejected when there is a failure.
enhance
{integer}
enhance(name, fn)
The enhance function allows developers to extend the core API to better fit their needs.
- Parameters:
-
{string}
name
- Function name.
-
{function}
fn
- Function to add to the JSONStoreInstance prototype for a specific collection.
- Returns:
- {integer} 0 return code for success or an error code for failure.
erase
erase(doc, options)
Deletes a document from the collection.
- Parameters:
-
{array|object|integer}
doc
- Document, array of documents, query object or
_id
.
-
{object}
options
Optional
-
{boolean}
options.push
Optional
- Default value is false, determines if the data will be marked as needed to be pushed to an adapter.
-
{function}
options.onSuccess
Optional
- Success callback.
-
{function}
options.onFailure
Optional
- Failure callback.
- Deprecated:
-
Since IBM® Worklight® V5.0.6, it is no longer needed if you use
WL.JSONStore.JSONStoreInstance.remove
with {push: false}
.
find
{Promise}
find(query, options)
Locates a document inside a collection using a query.
- Parameters:
-
{array|object}
query
- Defines what to search for in the collection.
-
{object}
options
Optional
-
{boolean}
options.exact
Optional
- Default is false and will do fuzzy searches, true will do exact searches.
-
{integer}
options.limit
Optional
- Maximum amount of documents to return, the default behavior is to return everything.
-
{integer}
options.offset
Optional
- Amount of documents to skip from the results, depends on the limit.
-
{array}
options.filter
Optional
- Return only the specified search fields, by default return
_id
and json
.
-
{array}
options.sort
Optional
- Sort documents based on their search fields, either ascending or descending.
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an array of results.
Rejected when there is a failure.
findAll
{Promise}
findAll(options)
Returns all of the documents stored in a collection.
- Parameters:
-
{object}
options
Optional
-
{integer}
options.limit
Optional
- Maximum amount of documents to return, the default behavior is to return everything.
-
{integer}
options.offset
Optional
- Amount of documents to skip from the results, depends on the limit.
-
{array}
options.filter
Optional
- Filter and select document's specified searchfields. If no filter array is passed, all searchfields are returned.
-
{array}
options.sort
Optional
- Sort documents based on their searchfields, either ascending or descending.
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an array of results.
Rejected when there is a failure.
findById
{Promise}
findById(data, options)
Returns one or more documents that match the _id
that is supplied to the function.
- Parameters:
-
{array}
data
- An array of
_id
-
{object}
options
Optional
-
{array}
options.filter
Optional
- Return only the specified search fields, by default return
_id
and json
.
-
{array}
options.sort
Optional
- Sort documents based on their search fields, either ascending or descending.
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an array of results.
Rejected when there is a failure.
getAllDirty
{Promise}
getAllDirty(options)
Returns all documents that are marked dirty. This function was previously called JSONStoreIntance.getPushRequired
.
- 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, returns array of documents.
Rejected when there is a failure.
isDirty
{Promise}
isDirty(doc, options)
Returns a boolean that is true if the document is dirty, false otherwise.
This function was previously called JSONStoreIntance.isPushRequired.
- Parameters:
-
{object|integer}
doc
- JSONStore style document or
_id
-
{object}
options
Optional
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, return a boolean.
Rejected when there is a failure.
load
{Promise}
load(options)
Gets data that is defined in the load portion of the adapter.
- 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, returns number of documents loaded.
Rejected when there is a failure.
- Deprecated:
-
Since IBM® Worklight® V6.2.0.
markClean
{Promise}
markClean(docs)
Marks an array of documents as clean. Takes input from JSONStoreIntance.getAllDirty,
which returns documents that have: _operation, _dirty, _id,
json, and _deleted.
- Parameters:
-
{array}
docs
- array of documents
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns number of clean documents.
Rejected when there is a failure.
push
{Promise}
push(options)
Pushes documents inside the collection that have local-only changes to an IBM® MobileFirst® adapter
that is linked during the init function.
- Parameters:
-
{array|object|integer}
options
Optional
- Options object, array of documents, single document or an
_id
.
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an array.
Array returned is either empty (everything worked) or full of error responses.
Rejected when there is a failure.
- Deprecated:
-
Since IBM® Worklight® V6.2.0.
pushSelected
{Promise}
pushSelected(doc, options)
Pushes only the selected documents.
- Parameters:
-
{object|array}
doc
- Document or array of documents.
-
{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.
- Deprecated:
-
Since IBM Worklight v5.0.6, it is no longer needed if you use
WL.JSONStore.JSONStoreInstance.push
.
refresh
refresh(doc, options)
Replaces a document with another document.
- Parameters:
-
{array|object}
doc
- Document or array of documents.
-
{object}
options
Optional
-
{boolean}
options.push
Optional
- Default value is false, determines if the data will be marked as needed to be pushed to an adapter.
-
{function}
options.onSuccess
Optional
- Success callback.
-
{function}
options.onFailure
Optional
- Failure callback.
- Deprecated:
-
Since IBM® Worklight® V5.0.6, it is no longer needed if you use
WL.JSONStore.JSONStoreInstance.replace
with {push: false}
.
remove
{Promise}
remove(doc, options)
Marks a document as deleted inside a collection.
- Parameters:
-
{array|object|integer}
doc
- Document, array of documents, query object or
_id
.
-
{object}
options
Optional
-
{boolean}
options.markDirty
Optional
- Default value is true, determines if the data will be marked as dirty.
-
{boolean}
options.push
Optional
- Deprecated. Default value is true, determines if the data will be marked as needed to be pushed to an adapter.
-
{boolean}
options.exact
Optional
- Default is false and will do fuzzy searches, true will do exact searches.
-
{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.
removeCollection
{Promise}
removeCollection(options)
Deletes all the documents that are stored inside a collection.
- 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.
replace
{Promise}
replace(doc, options)
Overwrites a document with a given document.
- Parameters:
-
{array|object}
doc
- Document or array of documents.
-
{object}
options
Optional
-
{boolean}
options.markDirty
Optional
- Default value is true, determines if the data will be marked as dirty.
-
{boolean}
options.push
Optional
- Deprecated. Default value is true, determines if the data will be marked as needed to be pushed to an adapter.
-
{function}
options.onSuccess
Optional
- Deprecated. Success callback.
-
{function}
options.onFailure
Optional
- Deprecated. Failure callback.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an integer.
Rejected when there is a failure.
store
store(data, options)
Writes data to a collection.
- Parameters:
-
{object|array}
data
- Data to store in the collection.
-
{object}
options
Optional
-
{object}
options.additionalSearchFields
Optional
- Search fields that are not part of the data that is passed.
-
{boolean}
options.push
Optional
- Default value is false, determines if the data will be marked as needed to be pushed to an adapter.
-
{function}
options.onSuccess
Optional
- Success callback.
-
{function}
options.onFailure
Optional
- Failure callback.
- Deprecated:
-
Since IBM® Worklight® V5.0.6, it is no longer needed if you use
WL.JSONStore.JSONStoreInstance.add
with {push: false}
.
toString
{Promise}
toString(limit, offset)
Prints the contents of the collection by using WL.Logger.debug asynchronously.
- Parameters:
-
{integer}
limit
Optional
- Maximum amount of documents to show. Use 0 for no documents,
if limit is missing it will print up to the first 100 documents.
-
{integer}
offset
Optional
- Number of documents to skip. Requires a valid limit.
- Returns:
- {Promise} Resolved when the operation succeeds, returns an integer.
Rejected when there is a failure.
© Copyright IBM Corp. 2011, 2016.