TinyBase logoTinyBase

getParamValue

The getParamValue method returns a single param value currently set for a parameterized query.

getParamValue(
  queryId: string,
  paramId: string,
): undefined | ParamValue
TypeDescription
queryIdstring

The Id of the query to get the param for.

paramIdstring

The Id of the param to get.

returnsundefined | ParamValue

The value of the param, or undefined if the query or param doesn't exist.

Example

This example creates a parameterized query and retrieves one of its param values.

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);
queries.setQueryDefinition(
  'query',
  'pets',
  ({select, where, param}) => {
    select('color');
    where('species', param('species'));
  },
  {species: 'dog'},
);

console.log(queries.getParamValue('query', 'species'));
// -> 'dog'

queries.setParamValue('query', 'species', 'cat');
console.log(queries.getParamValue('query', 'species'));
// -> 'cat'

Since

v7.2.0