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| Type | Description | |
|---|---|---|
queryId | string | The |
paramValues | ParamValues | An object containing the param |
| returns | Queries | A reference to the |
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