@@ -7,6 +7,53 @@ highlighted features.
77
88# v8.0
99
10+ ## Object And Array Types
11+
12+ This release also extends the range of types that a Cell or Value can hold.
13+ Previously, TinyBase supported ` string ` , ` number ` , ` boolean ` , and (since v7.0)
14+ ` null ` . Now you can also store plain JavaScript ** objects** and ** arrays**
15+ directly in a Store.
16+
17+ ``` js
18+ const richStore = createStore ().setRow (' pets' , ' fido' , {
19+ species: ' dog' ,
20+ traits: {friendly: true , energetic: true },
21+ vaccinations: [' rabies' , ' distemper' , ' parvovirus' ],
22+ });
23+
24+ console .log (richStore .getCell (' pets' , ' fido' , ' traits' ));
25+ // -> {friendly: true, energetic: true}
26+
27+ console .log (richStore .getCell (' pets' , ' fido' , ' vaccinations' ));
28+ // -> ['rabies', 'distemper', 'parvovirus']
29+ ```
30+
31+ Internally, objects and arrays are stored as JSON-encoded strings with a special
32+ prefix character, so they round-trip transparently through persistence layers.
33+ But in and out of your application code, the Store API always expects or returns
34+ them as native JavaScript values.
35+
36+ Schemas also gain ` object ` and ` array ` as valid types:
37+
38+ ``` js
39+ const richSchemaStore = createStore ().setTablesSchema ({
40+ pets: {
41+ species: {type: ' string' },
42+ traits: {type: ' object' , default: {}},
43+ vaccinations: {type: ' array' , default: []},
44+ },
45+ });
46+
47+ richSchemaStore .setRow (' pets' , ' fido' , {species: ' dog' });
48+ console .log (richSchemaStore .getRow (' pets' , ' fido' ));
49+ // -> {species: 'dog', traits: {}, vaccinations: []}
50+ ```
51+
52+ Note that TinyBase does not deeply validate the contents of objects or arrays
53+ when a schema is applied - it simply checks that the value is of the right
54+ top-level type. For deeper validation, consider combining with a
55+ [ Middleware] ( /guides/the-basics/using-middleware/ ) callback. On which note...
56+
1057## Introducing Middleware
1158
1259This release introduces a powerful new system for intercepting and transforming
0 commit comments