Skip to content

Commit 670a52a

Browse files
committed
[objarr] Update guides
1 parent 6777149 commit 670a52a

5 files changed

Lines changed: 54 additions & 38 deletions

File tree

‎site/guides/01_the_basics/3_writing_to_stores.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ hierarchical structure:
1515
Once you have created a Store, you can write data to it with one of its setter
1616
methods, according to the level of the hierarchy that you want to set.
1717

18-
For example, you can set the data for the keyed value structure of Store with the setValues
19-
method:
18+
For example, you can set the data for the keyed value structure of Store with
19+
the setValues method:
2020

2121
```js
2222
import {createStore} from 'tinybase';
@@ -25,8 +25,8 @@ const store = createStore();
2525
store.setValues({employees: 3, open: true});
2626
```
2727

28-
Similarly, you can set the data for the tabular structure of Store with the setTables
29-
method:
28+
Similarly, you can set the data for the tabular structure of Store with the
29+
setTables method:
3030

3131
```js
3232
store.setTables({pets: {fido: {species: 'dog'}}});
@@ -66,7 +66,9 @@ console.log(store.getTables());
6666
// -> {pets: {fido: {species: 'dog', color: 'brown'}}, species: {dog: {price: 5}, cat: {price: 4}}}
6767
```
6868

69-
The data in a Value or a Cell can be a string, a number, or a boolean type.
69+
The data in a Value or a Cell can be a string, a number, a boolean, or `null`.
70+
You can also store richer data as plain JavaScript objects or arrays, which
71+
TinyBase encodes internally as JSON strings.
7072

7173
It's worth mentioning here that there are two extra methods to manipulate Row
7274
objects. The addRow method is like the setRow method but automatically assigns

‎site/guides/01_the_basics/8_tinybase_and_typescript.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ use with TinyBase.
77

88
Out of the box, TinyBase has complete type coverage for all of its modules. So
99
for example, setting and getting tabular and key-value data will obey the
10-
system's constraints. A Cell or a Value can only be a number, string, or
11-
boolean, for example:
10+
system's constraints. A Cell or a Value can be a number, string, boolean,
11+
`null`, or a plain JavaScript object or array, for example:
1212

1313
```ts yolo
1414
import {createStore} from 'tinybase';
1515

1616
const store = createStore();
1717

18-
store.setValues({employees: 3}); // OK
19-
store.setValues({employees: true}); // OK
20-
store.setValues({employees: ['Alice', 'Bob']}); // TypeScript error
18+
store.setValues({employees: 3}); // OK
19+
store.setValues({employees: true}); // OK
20+
store.setValues({employees: ['Alice', 'Bob']}); // OK since v8.0
21+
store.setValues({employees: () => 3}); // TypeScript error
2122
```
2223

2324
This basic typing of the API is comprehensively described throughout in the API

‎site/guides/03_schemas/1_using_schemas.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ As you can see, when a Values object is used that doesn't quite match those
3232
constraints, the data is corrected. The `website` Value is ignored, and the
3333
missing `open` Value gets defaulted to `false`.
3434

35-
TinyBase supports four primitive types: `string`, `number`, `boolean`, and
36-
`null`. You can also allow `null` values for a specific Cell or Value by adding
37-
the `allowNull` property:
35+
TinyBase supports four primitive types in schemas: `string`, `number`,
36+
`boolean`, and `null`. It also supports `object` and `array` types for richer
37+
structured data, which are stored internally as JSON-encoded strings. You can
38+
also allow `null` values for a specific Cell or Value by adding the `allowNull`
39+
property:
3840

3941
```js
4042
const store2 = createStore().setValuesSchema({
@@ -139,8 +141,8 @@ console.log(store.getTables());
139141
// -> {}
140142
```
141143

142-
When no longer needed, you can also completely removes existing schemas
143-
with the delValuesSchema method or the delTablesSchema method.
144+
When no longer needed, you can also completely removes existing schemas with the
145+
delValuesSchema method or the delTablesSchema method.
144146

145147
## Summary
146148

‎site/guides/05_persistence/2_database_persistence.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ structure of your Store.
377377
### SQL NULL is TinyBase null
378378

379379
In TinyBase v7.0, `null` became a valid Cell and Value type alongside `string`,
380-
`number`, and `boolean`. When a database persister loads data from a SQL table,
381-
any SQL `NULL` values are loaded as TinyBase `null` values.
380+
`number`, and `boolean`. From v8.0, `object` and `array` types are also allowed;
381+
these are stored as JSON-encoded strings in SQL columns. When a database
382+
persister loads data from a SQL table, any SQL `NULL` values are loaded as
383+
TinyBase `null` values, and JSON-encoded columns are decoded back to objects or
384+
arrays.
382385

383386
This is the natural and correct behavior: SQL `NULL` represents an explicit null
384387
value, which maps directly to TinyBase's `null` type.

‎src/@types/store/docs.js‎

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
* `null` since v7.0, or `object` or `array` since v8.0), and what the default
113113
* value can be when an explicit value is not specified.
114114
*
115-
* For `object` and `array` types, TinyBase automatically serializes values
116-
* to and from JSON when storing and retrieving them.
115+
* For `object` and `array` types, TinyBase automatically serializes values to
116+
* and from JSON when storing and retrieving them.
117117
*
118118
* If a default value is provided (and its type is correct), you can be certain
119119
* that the Value will always be present in a Store.
@@ -289,7 +289,8 @@
289289
*
290290
* A Cell is used when setting a cell with the setCell method, and when getting
291291
* it back out again with the getCell method. A Cell is a JavaScript string,
292-
* number, boolean; or null since v7.0.
292+
* number, boolean, or null (since v7.0), or a plain JavaScript object or array
293+
* (since v8.0).
293294
* @example
294295
* ```js
295296
* import type {Cell} from 'tinybase';
@@ -335,7 +336,8 @@
335336
*
336337
* A Value is used when setting a value with the setValue method, and when
337338
* getting it back out again with the getValue method. A Value is a JavaScript
338-
* string, number, boolean; or null since v7.0.
339+
* string, number, boolean, or null (since v7.0), or a plain JavaScript object
340+
* or array (since v8.0).
339341
* @example
340342
* ```js
341343
* import type {Value} from 'tinybase';
@@ -1222,8 +1224,8 @@
12221224
* transaction, primarily used so that you can indicate whether the transaction
12231225
* should be rolled back.
12241226
*
1225-
* It provides both the old and new Values in a two-part array. These
1226-
* describe the state of the changed Value in the Store at the _start_ of the
1227+
* It provides both the old and new Values in a two-part array. These describe
1228+
* the state of the changed Value in the Store at the _start_ of the
12271229
* transaction, and by the _end_ of the transaction.
12281230
*
12291231
* Hence, an `undefined` value for the first item in the array means that the
@@ -1511,14 +1513,17 @@
15111513
*
15121514
* The keyed value support is best thought of as a flat JavaScript object. The
15131515
* Store contains a number of Value objects, each with a unique ID, and which is
1514-
* a string, boolean, number; or null since v7.0.
1516+
* a string, boolean, number, null (since v7.0), or a plain JavaScript object or
1517+
* array (since v8.0).
15151518
*
15161519
* ```json
1517-
* { // Store
1518-
* "value1": "one", // Value (string)
1519-
* "value2": true, // Value (boolean)
1520-
* "value3": 3, // Value (number)
1521-
* "value4": null, // Value (null since v7.0)
1520+
* { // Store
1521+
* "value1": "one", // Value (string)
1522+
* "value2": true, // Value (boolean)
1523+
* "value3": 3, // Value (number)
1524+
* "value4": null, // Value (null since v7.0)
1525+
* "value5": {"x": 1}, // Value (object since v8.0)
1526+
* "value6": [1, 2, 3], // Value (array since v8.0)
15221527
* ...
15231528
* }
15241529
* ```
@@ -1535,7 +1540,8 @@
15351540
* - Each Table contains a number of Row objects.
15361541
* - Each Row contains a number of Cell objects.
15371542
*
1538-
* A Cell is a string, boolean, number; or null since v7.0.
1543+
* A Cell is a string, boolean, number, null (since v7.0), or a plain JavaScript
1544+
* object or array (since v8.0).
15391545
*
15401546
* The members of each level of this hierarchy are identified with a unique Id
15411547
* (which is a string). In other words you can naively think of a Store as a
@@ -1549,6 +1555,8 @@
15491555
* "cell2": true, // Cell (boolean)
15501556
* "cell3": 3, // Cell (number)
15511557
* "cell4": null, // Cell (null since v7.0)
1558+
* "cell5": {"x": 1}, // Cell (object since v8.0)
1559+
* "cell6": [1, 2, 3], // Cell (array since v8.0)
15521560
* ...
15531561
* },
15541562
* ...
@@ -3069,10 +3077,10 @@
30693077
* does not match a TablesSchema associated with the Store), will be ignored
30703078
* silently.
30713079
*
3072-
* As well as string, number, or boolean Cell types, this method can also take
3073-
* a MapCell function that takes the current Cell value as a parameter and
3074-
* maps it. This is useful if you want to efficiently increment a value
3075-
* without fetching it first, for example.
3080+
* As well as string, number, boolean, null, object, and array Cell types,
3081+
* this method can also take a MapCell function that takes the current Cell
3082+
* value as a parameter and maps it. This is useful if you want to efficiently
3083+
* increment a value without fetching it first, for example.
30763084
*
30773085
* The method returns a reference to the Store so that subsequent operations
30783086
* can be chained in a fluent style.
@@ -3234,10 +3242,10 @@
32343242
* If the Value is invalid (either because of its type, or because it does not
32353243
* match a ValuesSchema associated with the Store), will be ignored silently.
32363244
*
3237-
* As well as string, number, or boolean Value types, this method can also
3238-
* take a MapValue function that takes the current Value as a parameter and
3239-
* maps it. This is useful if you want to efficiently increment a value
3240-
* without fetching it first, for example.
3245+
* As well as string, number, boolean, null, object, and array Value types,
3246+
* this method can also take a MapValue function that takes the current Value
3247+
* as a parameter and maps it. This is useful if you want to efficiently
3248+
* increment a value without fetching it first, for example.
32413249
*
32423250
* The method returns a reference to the Store so that subsequent operations
32433251
* can be chained in a fluent style.

0 commit comments

Comments
 (0)