@@ -5,6 +5,58 @@ highlighted features.
55
66---
77
8+ # v7.2
9+
10+ This release introduces ** parameterized queries** to TinyQL - finally!
11+
12+ These allow you to define queries using named 'params' that you can then easily
13+ update to change the query's results - without redefining the whole query each
14+ time.
15+
16+ Let's take a look with a simple example:
17+
18+ ``` js
19+ import {createStore , createQueries } from ' tinybase' ;
20+
21+ const store = createStore ().setTable (' pets' , {
22+ fido: {age: 2 , species: ' dog' },
23+ felix: {age: 1 , species: ' cat' },
24+ cujo: {age: 3 , species: ' dog' },
25+ });
26+
27+ const queries = createQueries (store).setQueryDefinition (
28+ ' petsBySpecies' ,
29+ ' pets' ,
30+ ({select, where, param}) => {
31+ select (' age' );
32+ where (' species' , param (' species' ));
33+ },
34+ {species: ' dog' }, // Initial param value
35+ );
36+
37+ console .log (queries .getResultTable (' petsBySpecies' ));
38+ // -> {fido: {age: 2}, cujo: {age: 3}}
39+
40+ // Update the 'species' param to 'cat' to change the results:
41+ queries .setParamValue (' petsBySpecies' , ' species' , ' cat' );
42+ console .log (queries .getResultTable (' petsBySpecies' ));
43+ // -> {felix: {age: 1}}
44+ ```
45+
46+ You can of course have multiple params in a query definition, and use them in
47+ any part of the query definition that you would like. Listeners also work as
48+ expected - if you are listening to a query's results, and you change a param
49+ that affects those results, your listener will be called accordingly.
50+
51+ For React users, We also shipped the useSetParamValue hook and the
52+ useSetParamValues hook, which let you easily update param values from, say, an
53+ event handler in your application.
54+
55+ We know this has been a long-awaited feature, so we hope you enjoy it! See the
56+ TinyQL guide for more details, and please let us know how it goes!
57+
58+ ---
59+
860# v7.1
961
1062This release introduces ** Schematizers** , a new system for converting schemas
@@ -18,7 +70,6 @@ Instead of manually writing TinyBase schemas, you can now convert existing
1870schemas at runtime:
1971
2072``` js
21- import {createStore } from ' tinybase' ;
2273import {createZodSchematizer } from ' tinybase/schematizers/schematizer-zod' ;
2374import {z } from ' zod' ;
2475
@@ -67,7 +118,6 @@ valid Cell and Value type, alongside `string`, `number`, and `boolean`.
67118You can now set Cells and Values to ` null ` :
68119
69120``` js
70- const store = createStore ();
71121store .setCell (' pets' , ' fido' , ' species' , ' dog' );
72122store .setCell (' pets' , ' fido' , ' color' , null );
73123
0 commit comments