TinyBase logoTinyBase

getParamValues

The getParamValues method returns all the param values currently set for a parameterized query.

getParamValues(queryId: string): ParamValues
TypeDescription
queryIdstring

The Id of the query to get the params for.

returnsParamValues

An object containing all param Ids and their values, or an empty object if the query doesn't exist.

Example

This example creates a parameterized query and retrieves 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'));
    where((getTableCell) => getTableCell('age') >= param('minAge'));
  },
  {species: 'dog', minAge: 5},
);

console.log(queries.getParamValues('query'));
// -> {species: 'dog', minAge: 5}

queries.setParamValue('query', 'species', 'cat');
console.log(queries.getParamValues('query'));
// -> {species: 'cat', minAge: 5}

Since

v7.2.0