TinyBase logoTinyBase

setParamValue

The setParamValue method sets a single param value for a parameterized query, causing the query to re-evaluate with the new param value.

setParamValue(
  queryId: string,
  paramId: string,
  value: ParamValue,
): Queries
TypeDescription
queryIdstring

The Id of the query to update the param for.

paramIdstring

The Id of the param to set.

valueParamValue

The value to set for the param.

returnsQueries

A reference to the Queries object for convenient chaining.

Example

This example creates a parameterized query and then updates one of its params.

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.getResultTable('query'));
// -> {fido: {color: 'brown'}, cujo: {color: 'black'}}

queries.setParamValue('query', 'species', 'cat');
console.log(queries.getResultTable('query'));
// -> {felix: {color: 'black'}}

Since

v7.2.0