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| Type | Description | |
|---|---|---|
queryId | string | The |
paramId | string | The |
value | ParamValue | The value to set for the param. |
| returns | Queries | A reference to the |
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