forEachResultTable

The forEachResultTable method takes a function that it will then call for each result Table in the Queries object.

forEachResultTable(tableCallback: TableCallback): void
TypeDescription
tableCallbackTableCallback

The function that should be called for every query's result Table.

returnsvoid

This has no return value.

This method is useful for iterating over all the result Tables of the queries in a functional style. The tableCallback parameter is a TableCallback function that will be called with the Id of each result Table, and with a function that can then be used to iterate over each Row of the result Table, should you wish.

Example

This example iterates over each query's result Table in a Queries object.

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');
  })
  .setQueryDefinition('catColors', 'pets', ({select, where}) => {
    select('color');
    where('species', 'cat');
  });

queries.forEachResultTable((queryId, forEachRow) => {
  console.log(queryId);
  forEachRow((rowId) => console.log(`- ${rowId}`));
});
// -> 'dogColors'
// -> '- fido'
// -> '- cujo'
// -> 'catColors'
// -> '- felix'

Since

v2.0.0