TinyBase logoTinyBase

getResultRowCount

The getResultRowCount method returns the count of the ResultRow objects in the ResultTable of the given query.

getResultRowCount(queryId: Id): number
TypeDescription
queryIdId

The Id of a query.

returnsnumber

The number of ResultRow objects in the result of the query.

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.

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