getResultTable
The getResultTable
method returns an object containing the entire data of the ResultTable
of the given query.
getResultTable(queryId: Id): ResultTable
Type | Description | |
---|---|---|
queryId | Id | The |
returns | ResultTable | An object containing the entire data of the |
This has the same behavior as a Store
's getTable
method. For example, if the query Id
is invalid, the method returns an empty object. Similarly, it returns a copy of, rather than a reference to the underlying data, so changes made to the returned object are not made to the query results themselves.
Example
This example creates a Queries
object, a single query definition, and then calls this method on it (as well as a non-existent definition) to get the ResultTable
.
const store = createStore().setTable('pets', {
fido: {species: 'dog', color: 'brown'},
felix: {species: 'cat', color: 'black'},
cujo: {species: 'dog', color: 'black'},
});
const queries = createQueries(store).setQueryDefinition(
'dogColors',
'pets',
({select, where}) => {
select('color');
where('species', 'dog');
},
);
console.log(queries.getResultTable('dogColors'));
// -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
console.log(queries.getResultTable('catColors'));
// -> {}
Since
v2.0.0