Home Reference Source
import {DataStore} from './core/datastore/datastore.doc.js'
public class | source

DataStore

The DataStore class is used to find, create, update, remove, count and group entities in a collection.

Static Method Summary

Static Public Methods
public static

Clear the cache.

public static

collection(collection: string, type: DataStoreType): DataStore

Returns an instance of th DataStore class based on the type provided.

Method Summary

Public Methods
public

clear(query: Query): Promise

Remove all entities in the collection that are stored in the local cache.

public

Clear pending sync items from the sync queue.

public

count(query: Query, options: Object): Observable

Count all entities in the collection.

public

create(entity: Object): Promise

Create a single entity on the collection.

public

find(query: Query, options: Object): Observable

Find all entities in the collection.

public

findById(id: string, options: Object): Observable

Find a single entity in the collection by id.

public

group(aggregationQuery: Aggregation): Observable

Group entities.

public

Count the number of entities waiting to be pushed to the backend.

public

Retrieve the entities waiting to be pushed to the backend.

public

pull(query: Query, options: Object): Promise<number>

Pull entities from the backend and save them to the local cache

public

push(query: Query, options: Object): Promise

Push pending sync items to the backend.

public

remove(query: Query): Promise

Remove all entities in the data store.

public

Remove a single entity in the data store by id.

public

save(entity: Object): Promise

Save a single entity on the data store.

public

sync(query: Query, options: Object): Promise<{push: [], pull: number}>

Sync items with the backend.

public

update(entity: Object): Promise

Update a single entity on the data store.

Static Public Methods

public static clearCache(): Promise<Object> source

Clear the cache. This will delete all data in the cache.

Return:

Promise<Object>

The result of clearing the cache.

public static collection(collection: string, type: DataStoreType): DataStore source

Returns an instance of th DataStore class based on the type provided.

Params:

NameTypeAttributeDescription
collection string
  • optional

Name of the collection.

type DataStoreType
  • optional
  • default: DataStoreType.Cache

Type of store to return.

Return:

DataStore

DataStore instance.

Public Methods

public clear(query: Query): Promise source

Remove all entities in the collection that are stored in the local cache.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query used to filter entities.

Return:

Promise

Number of entities removed.

public clearSync(query: Query): Promise source

Clear pending sync items from the sync queue.

Params:

NameTypeAttributeDescription
query Query

Query used to clear a subset of pending sync items

Return:

Promise

public count(query: Query, options: Object): Observable source

Count all entities in the collection. A query can be optionally provided to return a subset of all entities in a collection or omitted to return all entities in a collection. The number of entities returned adheres to the limits specified at http://devcenter.kinvey.com/rest/guides/datastore#queryrestrictions.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query used to filter entities.

options Object
  • optional

Options

options.properties Properties
  • optional

Custom properties to send with the request.

options.timeout Number
  • optional

Timeout for the request.

Return:

Observable

Observable.

public create(entity: Object): Promise source

Create a single entity on the collection.

Params:

NameTypeAttributeDescription
entity Object

Entity that you want to create on the collection.

Return:

Promise

Created entity.

Throw:

KinveyError

Unable to create an array of entities.

public find(query: Query, options: Object): Observable source

Find all entities in the collection. A query can be optionally provided to return a subset of all entities in a collection or omitted to return all entities in a collection. The number of entities returned adheres to the limits specified at http://devcenter.kinvey.com/rest/guides/datastore#queryrestrictions.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query used to filter entities.

options Object
  • optional

Options

options.useDeltaSet Boolean
  • optional

Turn on or off the use of delta set.

Return:

Observable

Observable.

public findById(id: string, options: Object): Observable source

Find a single entity in the collection by id.

Params:

NameTypeAttributeDescription
id string

Entity by id to find.

options Object
  • optional

Options

options.useDeltaSet Boolean
  • optional

Turn on or off the use of delta set.

Return:

Observable

Observable.

public group(aggregationQuery: Aggregation): Observable source

Group entities.

Params:

NameTypeAttributeDescription
aggregationQuery Aggregation

Aggregation used to group entities.

Return:

Observable

Observable.

public pendingSyncCount(query: Query): Promise source

Count the number of entities waiting to be pushed to the backend.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query to count a subset of entities.

Return:

Promise

Pending sync entities

public pendingSyncEntities(query: Query): Promise source

Retrieve the entities waiting to be pushed to the backend.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query to count a subset of entities.

Return:

Promise

Pending sync entities

public pull(query: Query, options: Object): Promise<number> source

Pull entities from the backend and save them to the local cache

IMPORTANT: This method is not intended to be used to make concurrent requests. If you wish to pull multiple pages, please use the autoPagination option

Params:

NameTypeAttributeDescription
query Query
  • optional

Query to pull a subset of items.

options Object

Options

options.properties Properties
  • optional

Custom properties to send with the request.

options.timeout Number
  • optional

Timeout for the request.

Return:

Promise<number>

Number of entities pulled

public push(query: Query, options: Object): Promise source

Push pending sync items to the backend.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query to push a subset of items.

options Object

Options

options.properties Properties
  • optional

Custom properties to send with the request.

options.timeout Number
  • optional

Timeout for the request.

Return:

Promise

Push result

public remove(query: Query): Promise source

Remove all entities in the data store. A query can be optionally provided to remove a subset of all entities in a collection or omitted to remove all entities in a collection. The number of entities removed adheres to the limits specified at http://devcenter.kinvey.com/rest/guides/datastore#queryrestrictions.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query used to filter entities.

Return:

Promise

Number of entities removed.

public removeById(id: string): Promise source

Remove a single entity in the data store by id.

Params:

NameTypeAttributeDescription
id string

Entity by id to remove.

Return:

Promise

Number of entities removed.

public save(entity: Object): Promise source

Save a single entity on the data store.

Params:

NameTypeAttributeDescription
entity Object

Entity that you want to save on the collection.

Return:

Promise

Promise.

public sync(query: Query, options: Object): Promise<{push: [], pull: number}> source

Sync items with the backend. This will push pending sync items first and then pull items from the backend and save them to the local cache.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query used to pull a subset of entities.

options Object

Options

options.properties Properties
  • optional

Custom properties to send with the request.

options.timeout Number
  • optional

Timeout for the request.

Return:

Promise<{push: [], pull: number}>

Sync result

public update(entity: Object): Promise source

Update a single entity on the data store.

Params:

NameTypeAttributeDescription
entity Object

Entity that you want to update on the collection.

Return:

Promise

Updated entity.

Throw:

KinveyError

Unable to update an array of entities.

KinveyError

The entity provided does not contain an _id. An _id is required to update the entity.