TinyBase logoTinyBase

getResultRowIds

The getResultRowIds method returns the Ids of every ResultRow in the ResultTable of the given query.

getResultRowIds(queryId: string): Ids
TypeDescription
queryIdstring

The Id of a query.

returnsIds

An array of the Ids of every ResultRow in the result of the query.

This has the same behavior as a Store's getRowIds method. For example, if the query Id is invalid, the method returns an empty array. Similarly, it returns a copy of, rather than a reference to the list of Ids, so changes made to the list 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 ResultRow Ids.

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.getResultRowIds('dogColors'));
// -> ['fido', 'cujo']

console.log(queries.getResultRowIds('catColors'));
// -> []

Since

v2.0.0