JSONStoreCollection
This class represents a single JSONStore collection. Operations on the collection can be done by using the API for this class.
Static Member Summary
Static Public Members | ||
public static get |
|
|
public static get |
|
|
public static get |
|
|
public static get |
|
Constructor Summary
Public Constructor | ||
public |
constructor(name: string) |
Method Summary
Public Methods | ||
public |
Add data and create a new document in the collection. |
|
public |
async changeData(dataList: Array, jsonStoreChangeOptions: JSONStoreChangeOptions): Promise<number, JSON> Change a list of documents in the collection. |
|
public |
async clearCollection(): Promise<string, JSON> Removes all documents from a collection, but does not destroy the collection. |
|
public |
async countAllDirtyDocuments(): Promise<number, JSON> Count the number of dirty documents in the collection. |
|
public |
async countAllDocuments(): Promise<number, JSON> Count the number of documents in the collection. |
|
public |
async countDocuments(query: Array<JSONStoreQueryPart>, includeDeleted: boolean): Promise<number, JSON> Count the number of documents in the collection that are based on the given query. |
|
public |
async findAllDirtyDocuments(): Promise<Array, JSON> Find all the dirty documents in the collection. |
|
public |
async findAllDocuments(options: JSONStoreFindOptions): Promise<Array, JSON> Find all documents in the collection. |
|
public |
async findDocumentById(id: number): Promise<object, JSON> Find a document in the collection based on the given ID. |
|
public |
async findDocuments(query: Array<JSONStoreQueryPart>, options: JSONStoreFindOptions): Promise<Array, JSON> Find documents in the collection that are based on the given query. |
|
public |
async findDocumentsById(ids: Array): Promise<Array, JSON> Find all documents in the collection that have the given ids. |
|
public |
async getAdditionalSearchFields(): Promise<object> Get a map of the additional search fields for this collection. |
|
public |
async getSearchFields(): Promise<object> Get a map of all search fields for this collection. |
|
public |
async hasAdditionalSearchField(searchField: string): Promise<boolean, JSON> Determines if the collection contains the given additional search field. |
|
public |
async hasSearchField(searchField: string): Promise<boolean, JSON> The name of the search field to check for existence. |
|
public |
async isDocumentDirty(id: number): Promise<boolean, JSON> Determine if a document is dirty or not. |
|
public |
async markDocumentClean(document: JSON): Promise<number, JSON> Mark a document in the collection clean. |
|
public |
async markDocumentsClean(documents: Array): Promise<number, JSON> Mark an array of documents in the collection clean. |
|
public |
async removeCollection(): Promise<string, JSON> Permanently deletes all the documents that are stored in a collection and destroys the collection. |
|
public |
Remove a document from the collection that is based on the given id. |
|
public |
Remove array of documents from the collection, based on the given ids. |
|
public |
Replace a document in the collection. |
|
public |
Replace an array of documents in the collection. |
|
public |
setAdditionalSearchField(key: string, searchFieldType: string): * Set an additional search field for the collection. |
|
public |
setSearchField(key: string, searchFieldType: string): * Set a search field for the collection. |
|
public |
sync() Sync this collection based on Sync policy set when the collection was opened. |
|
public |
async wasReopened(): Promise<boolean, JSON> Determine if the collection was reopened when it was initialized. |
Static Public Members
Public Constructors
Public Methods
public async addData(data: JSON, options: JSONStoreAddOptions): Promise<string, JSON> source
Add data and create a new document in the collection.
Params:
Name | Type | Attribute | Description |
data | JSON | New JSON data to be added to the collection |
|
options | JSONStoreAddOptions |
|
Options to be applied while adding the object |
Return:
Promise<string, JSON> | This function returns an empty string in case of success and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async changeData(dataList: Array, jsonStoreChangeOptions: JSONStoreChangeOptions): Promise<number, JSON> source
Change a list of documents in the collection.
Params:
Name | Type | Attribute | Description |
dataList | Array | List of JSON documents |
|
jsonStoreChangeOptions | JSONStoreChangeOptions |
|
Options to be applied while changing the objects |
Return:
Promise<number, JSON> | This function returns a number indicative of number of documents affected and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async clearCollection(): Promise<string, JSON> source
Removes all documents from a collection, but does not destroy the collection.
Return:
Promise<string, JSON> | This function returns an empty string in case of success. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async countAllDirtyDocuments(): Promise<number, JSON> source
Count the number of dirty documents in the collection.
Return:
Promise<number, JSON> | This function returns a number indicative of the count of all dirty documents. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async countAllDocuments(): Promise<number, JSON> source
Count the number of documents in the collection.
Return:
Promise<number, JSON> | This function returns a number indicative of the count of all documents. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async countDocuments(query: Array<JSONStoreQueryPart>, includeDeleted: boolean): Promise<number, JSON> source
Count the number of documents in the collection that are based on the given query.
Params:
Name | Type | Attribute | Description |
query | Array<JSONStoreQueryPart> | An array of JSONStoreQueryPart objects that limits the count scope. Every query part in the arrayare joined by an OR operation. |
|
includeDeleted | boolean |
|
Additional options to modify the count operation. |
Return:
Promise<number, JSON> | This function returns a number indicative of the count of documents based on given query and whether to include deleted documents. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async findAllDirtyDocuments(): Promise<Array, JSON> source
Find all the dirty documents in the collection.
Return:
Promise<Array, JSON> | This function returns an array of documents that are found dirty in the collection. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async findAllDocuments(options: JSONStoreFindOptions): Promise<Array, JSON> source
Find all documents in the collection.
Params:
Name | Type | Attribute | Description |
options | JSONStoreFindOptions |
|
The find query that restricts the search. |
Return:
Promise<Array, JSON> | This function returns an array of documents that are found in the collection with the given Find Options. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async findDocumentById(id: number): Promise<object, JSON> source
Find a document in the collection based on the given ID.
Params:
Name | Type | Attribute | Description |
id | number | The unique id that is associated with a document in the database (the _id search field). |
Return:
Promise<object, JSON> | This function returns a document that is found for this given id. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async findDocuments(query: Array<JSONStoreQueryPart>, options: JSONStoreFindOptions): Promise<Array, JSON> source
Find documents in the collection that are based on the given query.
Params:
Name | Type | Attribute | Description |
query | Array<JSONStoreQueryPart> | An array of JSONStoreQueryPart objects that limits the count scope. Every query part in the arrayare joined by an OR operation. |
|
options | JSONStoreFindOptions |
|
Additional options to modify the count operation. |
Return:
Promise<Array, JSON> | This function returns an array of all the documents that are found for this given query and find options. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async findDocumentsById(ids: Array): Promise<Array, JSON> source
Find all documents in the collection that have the given ids.
Params:
Name | Type | Attribute | Description |
ids | Array | An array of unique ids that are associated with a document in the database (the _id search field). |
Return:
Promise<Array, JSON> | This function returns an array of all the documents that are found for this given ids. In case of any error this function returns a JSON. |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async getAdditionalSearchFields(): Promise<object> source
Get a map of the additional search fields for this collection.
public async getSearchFields(): Promise<object> source
Get a map of all search fields for this collection.
public async hasAdditionalSearchField(searchField: string): Promise<boolean, JSON> source
Determines if the collection contains the given additional search field.
Params:
Name | Type | Attribute | Description |
searchField | string | The name of the additional search field to check for existence. |
Return:
Promise<boolean, JSON> | This function returns a boolean value indicative of whether the collection contains the given additional search field or not, and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async hasSearchField(searchField: string): Promise<boolean, JSON> source
The name of the search field to check for existence.
Params:
Name | Type | Attribute | Description |
searchField | string | The name of the additional search field to check for existence. |
Return:
Promise<boolean, JSON> | This function returns a boolean value indicative of whether the collection contains the given search field or not, and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async isDocumentDirty(id: number): Promise<boolean, JSON> source
Determine if a document is dirty or not.
Params:
Name | Type | Attribute | Description |
id | number | ID of the document to be checked. |
Return:
Promise<boolean, JSON> | This function returns a boolean value indicative of whether the document is dirty or not, and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async markDocumentClean(document: JSON): Promise<number, JSON> source
Mark a document in the collection clean.
Params:
Name | Type | Attribute | Description |
document | JSON | JSON document to be marked as clean. |
Return:
Promise<number, JSON> | This function returns a number indicative of number of documents affected and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async markDocumentsClean(documents: Array): Promise<number, JSON> source
Mark an array of documents in the collection clean.
Params:
Name | Type | Attribute | Description |
documents | Array | An Array of JSON documents to be marked as clean. |
Return:
Promise<number, JSON> | This function returns a number indicative of number of documents affected and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async removeCollection(): Promise<string, JSON> source
Permanently deletes all the documents that are stored in a collection and destroys the collection.
Return:
Promise<string, JSON> | This function returns an empty string in case of success and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async removeDocumentById(id: number, markDirty: boolean): Promise<number, JSON> source
Remove a document from the collection that is based on the given id.
Return:
Promise<number, JSON> | This function returns a number indicative of number of documents affected and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async removeDocumentsById(ids: number, markDirty: boolean): Promise<number, JSON> source
Remove array of documents from the collection, based on the given ids.
Return:
Promise<number, JSON> | This function returns a number indicative of number of documents affected and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async replaceDocument(document: JSON, markDirty: boolean): Promise<number, JSON> source
Replace a document in the collection.
Return:
Promise<number, JSON> | This function returns a number indicative of number of documents affected and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public async replaceDocuments(documents: Array, markDirty: boolean): Promise<number, JSON> source
Replace an array of documents in the collection.
Params:
Name | Type | Attribute | Description |
documents | Array | A List that contains JSONObjects that represent the documents to update in the collection. The document's '_id' is used to determine which document to replace. If all documents could not be updated, a rollback is performed to a state where no documents were updated. |
|
markDirty | boolean |
|
Mark the document as dirty using this flag. Default is false. |
Return:
Promise<number, JSON> | This function returns a number indicative of number of documents affected and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}
public setAdditionalSearchField(key: string, searchFieldType: string): * source
Set an additional search field for the collection.
Return:
* |
public setSearchField(key: string, searchFieldType: string): * source
Set a search field for the collection.
Return:
* |
public async wasReopened(): Promise<boolean, JSON> source
Determine if the collection was reopened when it was initialized.
Return:
Promise<boolean, JSON> | This function returns a boolean value and it returns a JSON in case of any error |
Example:
- If the promise is rejected, an error JSON in the following format is available with more information.
{
errorMsg: "Error adding data to collection: favourites",
reason: "Collection is not initialized."
}