Skip to content

Commit a9cd580

Browse files
committed
[params] Release notes
1 parent 8bf83ab commit a9cd580

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

site/guides/16_releases.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1062
This release introduces **Schematizers**, a new system for converting schemas
@@ -18,7 +70,6 @@ Instead of manually writing TinyBase schemas, you can now convert existing
1870
schemas at runtime:
1971

2072
```js
21-
import {createStore} from 'tinybase';
2273
import {createZodSchematizer} from 'tinybase/schematizers/schematizer-zod';
2374
import {z} from 'zod';
2475

@@ -67,7 +118,6 @@ valid Cell and Value type, alongside `string`, `number`, and `boolean`.
67118
You can now set Cells and Values to `null`:
68119

69120
```js
70-
const store = createStore();
71121
store.setCell('pets', 'fido', 'species', 'dog');
72122
store.setCell('pets', 'fido', 'color', null);
73123

site/home/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</h2>
77
</section>
88

9-
<a href='/guides/releases/#v7-1'><em>NEW!</em> v7.1 release</a>
9+
<a href='/guides/releases/#v7-2'><em>NEW!</em> v7.2 release</a>
1010

11-
<span id="one-with">"The one with Schematizers!"</span>
11+
<span id="one-with">"The one with parameterized queries!"</span>
1212

1313
<a class='start' href='/guides/the-basics/getting-started/'>Get started</a>
1414

@@ -465,7 +465,7 @@ await sessionStorage.clear();
465465
> "which is the highest-priced species, and in which state?"
466466
>
467467
> Needless to say, the results are reactive too! You can add listeners to
468-
> queries just as easily as you do to raw tables.
468+
> queries, and since v7.2, even parameterize them.
469469
>
470470
> Read more about Queries in the [v2.0 Release Notes](/guides/releases/#v2-0),
471471
> the Using Queries guide, and the Car Analysis demo and Movie Database demo.

0 commit comments

Comments
 (0)