getResultRowCount
The getResultRowCount
method returns the count of the ResultRow
objects in the ResultTable
of the given query.
getResultRowCount(queryId: string): number
Type | Description | |
---|---|---|
queryId | string | The |
returns | number | The number of |
This has the same behavior as a Store
's getRowCount
method. For example, if the query Id
is invalid, the method returns zero.
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 ResultRow
count.
import {createQueries, createStore} from 'tinybase';
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.getResultRowCount('dogColors'));
// -> 2
console.log(queries.getResultRowCount('catColors'));
// -> 0
Since
v4.1.0