TinyBase logoTinyBase

getResultCell

The getResultCell method returns the value of a single ResultCell in a given ResultRow, in the ResultTable of the given query.

getResultCell(
  queryId: string,
  rowId: string,
  cellId: string,
): ResultCellOrUndefined
TypeDescription
queryIdstring

The Id of a query.

rowIdstring

The Id of the ResultRow in the ResultTable.

cellIdstring

The Id of the ResultCell in the ResultRow.

returnsResultCellOrUndefined

The value of the ResultCell, or undefined.

This has the same behavior as a Store's getCell method. For example, if the query, or ResultRow, or ResultCell Id is invalid, the method returns undefined.

Example

This example creates a Queries object, a single query definition, and then calls this method on it (as well as a non-existent ResultCell Id) to get the ResultCell.

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.getResultCell('dogColors', 'fido', 'color'));
// -> 'brown'

console.log(queries.getResultCell('dogColors', 'fido', 'species'));
// -> undefined

Since

v2.0.0