forEachResultRow
The forEachResultRow
method takes a function that it will then call for each Row
in the result Table
of a query.
forEachResultRow(
queryId: string,
rowCallback: RowCallback,
): void
Type | Description | |
---|---|---|
queryId | string | The |
rowCallback | RowCallback | The function that should be called for every |
returns | void | This has no return value. |
This method is useful for iterating over each Row
of the result Table
of the query in a functional style. The rowCallback
parameter is a RowCallback
function that will be called with the Id
of each result Row
, and with a function that can then be used to iterate over each Cell
of the result Row
, should you wish.
This example iterates over each Row
in a query's result Table
.
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');
},
);
queries.forEachResultRow('dogColors', (rowId, forEachCell) => {
console.log(rowId);
forEachCell((cellId) => console.log(`- ${cellId}`));
});
// -> 'fido'
// -> '- color'
// -> 'cujo'
// -> '- color'
v2.0.0