Class: PersistenceStore

QuickNav

PersistenceStore

Abstract class that all Persistence Store implmenetation extends from. Defines the basic operations every persistence store should support.

Methods

delete(findExpression)

Delete the keys that satisfy the findExpression.
Parameters:
Name Type Description
findExpression {selector: Object} The expression to find matching documents to delete. The syntax of the expression follows standard MangoDB syntax. If undefined, all documents in this store will be deleted.
  • findExpression.selector The search criteria to find matching document.

find(findExpression) → {Promise}

This is query and sort support for persistence store.
Parameters:
Name Type Description
findExpression {selector: Object, fields: Object, sort: Object} The expression to query/sort the store. The syntax of the expression follows standard MangoDB syntax.
  • findExpression.selector search criteria
  • findExpression.fields lists of fields to be included in the return value
  • findExpression.sort name of the field to be sorted against and the order to sort with.
Returns:
Returns a Promise that resolves to an array of entries that satisfy the selector expression in the specified sorted order that contains the specified fields. The promise should resolve to an emtpy array if no entries are found.
Type
Promise

findByKey(key) → {Promise}

Convenient method to retrieve the document with the specified key. This is equivalent to find({selector: {key: {$eq: keyValue}}, fields: [value]});
Parameters:
Name Type Description
key string The key part of the composite key in the store to search for store entry.
Returns:
Returns a Promise that resolves to the store entry identified by the specified key
Type
Promise

getName() → {string}

Retrieves the name of the store.
Returns:
Returns the name of this store.
Type
string

getVersion() → {string}

Retrieves the version of the store.
Returns:
Returns the version of this store.
Type
string

Init(options) → {Promise}

Initializes the store.
Parameters:
Name Type Description
options {index: Array, version: string} Optional options to tune the store.
  • options.index array of fields to create index for
  • options.version The version of the store.
Returns:
Returns a Promise when resolved the store is ready to be used.
Type
Promise

keys() → {Promise}

Returns all the keys of the documents in this store.
Returns:
Returns a Promise that resolves to an array where each element is the key of an entry in this store. The Promise should resolve to an empty array if there is no entries in the store.
Type
Promise

removeByKey(key) → {Promise}

Convenient method to delete a document identified by the specified key. This is equivalent to delete({selector: {key: {$eq: keyValue}}});
Parameters:
Name Type Description
key string The key to identify the store entry that needs to be deleted.
Returns:
Returns a Promise that is resolved when the store entry is deleted.
Type
Promise

updateKey(currentKey, newKey) → {Promise}

Update the key value for the row referenced by the current key value.
Parameters:
Name Type Description
currentKey string The current key used to identify this resource
newKey string The new key used to identify this resource
Returns:
Returns a Promise that resolves when the key is updated.
Type
Promise

upsert(key, metadata, value, expectedVersionIdentifier) → {Promise}

Insert a resource if it does not already exist, update otherwise.
Parameters:
Name Type Description
key string The unique key used to identify this resource
metadata Object The metadata portion of this resource
value Object The value portion of this resource
expectedVersionIdentifier string Optional, the new version identifier value of this resource.
Returns:
Returns a Promise that for insert, resolves to undefined, while for update, resolves to the old value of the resource associated with the key.
Type
Promise

upsertAll(values) → {Promise}

Bulk operation of upsert.
Parameters:
Name Type Description
values Array An array of document to be bulk operated. Each item in the array is of {key, metadata, value, expectedVersionIdentifier} format.
Returns:
Returns a Promise that resolves to an array where each element in the array is the status of upsert of the corresponding resource.
Type
Promise