QueryResult <T>
Index
Constructors
constructor
Type parameters
- T: CloudObject | CloudObject[]
Returns QueryResult<T>
Methods
[iterator]
Symbol iterator for
for…in
syntactic sugarReturns 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
Get an iterable iterator over the key-value pairs of this
QueryResult
Returns IterableIterator<[string, T]>
iterator
filter
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
Returns the first value matching the predicate,
null
otherwise.find
callspredicate
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
Execute the specified callback function for each value of this
QueryResult
Parameters
callback: (entry: T, index: number) => void
Returns void
get
Get the value corresponding to a given key
Parameters
key: string
tag or composite tag
Returns T
matching tuple or
null
getAt
Get the value at the specified index
Parameters
index: number
Returns T
value at position
index
ornull
if index is out of bounds
getFirst
Get the first value
Returns T
first value or
null
if empty
has
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
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 thisQueryResult
.If the key is not a string, get the index from the
CloudObject
tuplesParameters
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
Get an iterable iterator over the keys of this
QueryResult
Returns IterableIterator<string>
iterator
map
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
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
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
Return a reduced value for this QueryResult.
The specified
reducer
callback reduces the QueryResult values. Similar toArray.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
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
Get the number of key-value pairs this
QueryResult
containsReturns number
size of this
QueryResult
sort
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
Get an array containing the values of this
QueryResult
Returns T[]
array of this
QueryResult
‘s values
values
Get an iterable iterator over the values of this
QueryResult
Returns IterableIterator<T>
iterator
staticempty
Returns QueryResult<any>
empty
QueryResult
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 aCloudObject
(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 ofCloudObjects
(e.g.[cloudObj1, cloudObj2, cloudObj3]
). Such a QueryResult can be obtained via: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.