TinyBase

getResultCellIds

The getResultCellIds method returns the Ids of every Cell in a given Row, in the result Table of the given query.

getResultCellIds(
  queryId: string,
  rowId: string,
): Ids
TypeDescription
queryIdstring

The Id of a query.

rowIdstring

The Id of the Row in the result Table.

returnsIds

An array of the Ids of every Cell in the Row in the result of the query.

This has the same behavior as a Store's getCellIds method. For example, if the query Id or Row 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 Row Id) to get the result Cell Ids.

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

console.log(queries.getResultCellIds('dogColors', 'felix'));
// -> []

Since

v2.0.0