TinyBase logoTinyBase

setParamValues

The setParamValues method sets multiple param values for a parameterized query at once, causing the query to re-evaluate with the new param values.

setParamValues(
  queryId: string,
  paramValues: ParamValues,
): Queries
TypeDescription
queryIdstring

The Id of the query to update the params for.

paramValuesParamValues

An object containing the param Ids and values to set.

returnsQueries

A reference to the Queries object for convenient chaining.

Example

This example creates a parameterized query and then updates multiple parameters at once.

import {createQueries, createStore} from 'tinybase';

const store = createStore().setTable('pets', {
  fido: {species: 'dog', color: 'brown', age: 5},
  felix: {species: 'cat', color: 'black', age: 3},
  cujo: {species: 'dog', color: 'black', age: 7},
});

const queries = createQueries(store);
queries.setQueryDefinition(
  'query',
  'pets',
  ({select, where, param}) => {
    select('color');
    where('species', param('species'));
    where((getTableCell) => getTableCell('age') >= param('minAge'));
  },
  {species: 'dog', minAge: 5},
);

console.log(queries.getResultTable('query'));
// -> {fido: {color: 'brown'}, cujo: {color: 'black'}}

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

Since

v7.2.0