TinyBase logoTinyBase beta

forEachResultCell

The forEachResultCell method takes a function that it will then call for each Cell in the result Row of a query.

forEachResultCell(
  queryId: string,
  rowId: string,
  cellCallback: CellCallback,
): void
TypeDescription
queryIdstring

The Id of a query.

rowIdstring

The Id of a Row in the query's result Table.

cellCallbackCellCallback

The function that should be called for every Cell of the query's result Row.

returnsvoid

This has no return value.

This method is useful for iterating over each Cell of the result Row of the query in a functional style. The cellCallback parameter is a CellCallback function that will be called with the Id and value of each result Cell.

Example

This example iterates over each Cell in a query's result Row.

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('species');
    select('color');
    where('species', 'dog');
  },
);

queries.forEachResultCell('dogColors', 'fido', (cellId, cell) => {
  console.log(`${cellId}: ${cell}`);
});
// -> 'species: dog'
// -> 'color: brown'

Since

v2.0.0