Skip to main content
Version: 2.6

QueryResult <T>

A QueryResult is a list of key-value pairs that has been generated as a result of a Query. It contains the result of a query at a specific time.

The keys are tags (e.g. myTag) that correspond to a CloudObject (e.g. myCloudObject). When the Query contains more than one Query.andReturn() clause, keys are composite tags (e.g. 'tag1.tag2.tag3') and values are tuples of CloudObjects (e.g. [cloudObj1, cloudObj2, cloudObj3]). Such a QueryResult can be obtained via:

Query.instancesOf(myModel1).andReturn.follow(myRelation1).andReturn.follow(myRelation2).andReturn().execute().

When a query is subscribed, the returned observable generates multiple QueryResults over time.

A QueryResult can be easily manipulated and transformed to a standard Array.

Index

Constructors

constructor

Methods

[iterator]

  • [iterator](): IterableIterator<[string, T]>
  • Symbol iterator for for…in syntactic sugar


    Returns IterableIterator<[string, T]>

    iterator over the key-values pairs of this QueryResult

concat

  • Return a new QueryResult that contains the concatenation of two or more QueryResults.

    Concatenating two QueryResults results in a new QueryResult with the following:

    • the keys of the QueryResults are concatenated
    • the values of the QueryResults are concatenated
    • the arrays returned by QueryResult.getAdded are concatenated
    • the arrays returned by QueryResult.getRemoved are concatenated

    Example :

    ``javascript
    const result1 = Query.fromInstances(myModel1).executeFromCache();
    // result1 is {tag1: cloudObj1, tag2: cloudObj2}
    const result2 = Query.fromInstances(myModel2).executeFromCache();
    // result2 is {tag3: cloudObj3}
    const concatenatedResult = result2.concat(result1);
    // concatenatedResult is {tag3: cloudObj3, tag1: cloudObj1, tag2: cloudObj2}
    ``


    Parameters

    • rest...others: QueryResult<T>[]

      QueryResults to append to this QueryResult

    Returns QueryResult<T>

    concatenated query results

entries

  • entries(): IterableIterator<[string, T]>
  • Get an iterable iterator over the key-value pairs of this QueryResult


    Returns IterableIterator<[string, T]>

    iterator

filter

  • filter(predicate: (entry: T, index: number) => boolean): T[]
  • Returns an array containing the values matching the provided filter predicate.


    Parameters

    • predicate: (entry: T, index: number) => boolean

      filter Predicate

    Returns T[]

    array of matching values

find

  • find(predicate: (entry: T, index: number) => boolean): T
  • Returns the first value matching the predicate, null otherwise.

    find calls predicate once for each element of the array until it returns true. If such an element is found, find immediately returns that element value.


    Parameters

    • predicate: (entry: T, index: number) => boolean

    Returns T

    the first value evaluating to true or null

forEach

  • forEach(callback: (entry: T, index: number) => void): void
  • Execute the specified callback function for each value of this QueryResult


    Parameters

    • callback: (entry: T, index: number) => void

    Returns void

get

  • get(key: string): T
  • Get the value corresponding to a given key


    Parameters

    • key: string

      tag or composite tag

    Returns T

    matching tuple or null

getAt

  • getAt(index: number): T
  • Get the value at the specified index


    Parameters

    • index: number

    Returns T

    value at position index or null if index is out of bounds

getFirst

  • getFirst(): T
  • Get the first value


    Returns T

    first value or null if empty

has

  • has(key: string | T): boolean
  • Check whether a key / value is contained in this QueryResult.

    Returns true if the cloud array contains an element with the specified key.

    If no corresponding key is found, returns true if the cloud array contains an element with the specified value.


    Parameters

    • key: string | T

      the value to search for

    Returns boolean

    true if the value key is found

indexOf

  • indexOf(key: string | T): number
  • Get index of a value in the keys or values of this QueryResult.

    If the key is a string, retrieve the index from the string keys of this QueryResult.

    If the key is not a string, get the index from the CloudObject tuples


    Parameters

    • key: string | T

      the value to find the index of

    Returns number

    index of the argument value or -1 if the value is not found

keys

  • keys(): IterableIterator<string>
  • Get an iterable iterator over the keys of this QueryResult


    Returns IterableIterator<string>

    iterator

map

  • map<S>(callback: (entry: T, index: number) => S): S[]
  • Execute the specified callback function for each value of this QueryResult. It returns a new array that contains the results of the callback execution.


    Type parameters

    • S

    Parameters

    • callback: (entry: T, index: number) => S

    Returns S[]

    new array of transformed values

pop

  • pop(): T[]
  • Returns the QueryResult values as an array whose last value has been removed.

    If QueryResult.size is 0 or 1, this method returns an empty array.

    This operation returns a new array and does not modify this QueryResult.


    Returns T[]

    new values array with last element removed

push

  • push(...object: T[]): T[]
  • Returns an array equivalent to this.toArray().push(…object)

    This operation returns a new array and does not modify this QueryResult.


    Parameters

    • rest...object: T[]

      new values to push in the values array.

    Returns T[]

    new values array with new elements appended

reduce

  • reduce<S>(reducer: (accumulator: S, entry: T, index: number) => S, initial: S): S
  • Return a reduced value for this QueryResult.

    The specified reducer callback reduces the QueryResult values. Similar to Array.reduce().


    Type parameters

    • S

    Parameters

    • reducer: (accumulator: S, entry: T, index: number) => S

      callback

    • initial: S

      initial value of the accumulator

    Returns S

    accumulated result applying the reducer function iteratively

shift

  • shift(): T[]
  • Returns the QueryResult values as an array whose first value has been removed.

    If QueryResult.size is 0 or 1, this method returns an empty array.

    This operation returns a new array and does not modify this QueryResult.


    Returns T[]

    new values array with first element removed

size

  • size(): number
  • Get the number of key-value pairs this QueryResult contains


    Returns number

    size of this QueryResult

sort

  • sort(comparator: (b1: T, b2: T) => number): QueryResult<T>
  • Return a sorted copy of this QueryResult.

    The specified comparator used to determine the order of the QueryResult key-value pairs. It compares two QueryResult values and should return a negative number if the first value shall be present before the second, zero if they’re at the same position, and a positive number otherwise.


    Parameters

    • comparator: (b1: T, b2: T) => number

      comparator returning a negative, zero or positive number

    Returns QueryResult<T>

    sorted copy of this QueryResult

toArray

  • toArray(): T[]
  • Get an array containing the values of this QueryResult


    Returns T[]

    array of this QueryResult‘s values

values

  • values(): IterableIterator<T>
  • Get an iterable iterator over the values of this QueryResult


    Returns IterableIterator<T>

    iterator

staticempty