Skip to content

Commit 98ae615

Browse files
committed
[docs] v4.2
1 parent d5fceec commit 98ae615

File tree

5 files changed

+61
-20
lines changed

5 files changed

+61
-20
lines changed

site/guides/03_schemas_and_persistence/4_persisting_data.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ databases, and across synchronization boundaries with CRDT frameworks.
2020
| ------------------------ | --------------------------- | ------------------------------------------------------------------------------------------------------ |
2121
| persister-browser | createSessionPersister | Browser session storage |
2222
| persister-browser | createLocalPersister | Browser local storage |
23+
| persister-indexed-db | createIndexedDbPersister | Browser IndexedDB |
2324
| persister-remote | createRemotePersister | Remote server |
2425
| persister-file | createFilePersister | Local file (where possible) |
2526
| persister-sqlite3 | createSqlite3Persister | SQLite in Node, via [sqlite3](https://github.com/TryGhost/node-sqlite3) |

site/guides/10_releases.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@
33
This is a reverse chronological list of the major TinyBase releases, with
44
highlighted features.
55

6+
## v4.2
7+
8+
This release adds support for persisting TinyBase to a browser's IndexedDB
9+
storage. The API is the same as for all the other Persister APIs:
10+
11+
```js
12+
const store = createStore()
13+
.setTable('pets', {fido: {species: 'dog'}})
14+
.setTable('species', {dog: {price: 5}})
15+
.setValues({open: true});
16+
const indexedDbPersister = createIndexedDbPersister(store, 'petStore');
17+
18+
await indexedDbPersister.save();
19+
// IndexedDB ->
20+
// database petStore:
21+
// objectStore t:
22+
// object 0:
23+
// k: "pets"
24+
// v: {fido: {species: dog}}
25+
// object 1:
26+
// k: "species"
27+
// v: {dog: {price: 5}}
28+
// objectStore v:
29+
// object 0:
30+
// k: "open"
31+
// v: true
32+
33+
indexedDbPersister.destroy();
34+
```
35+
36+
Note that it is not possible to reactively detect changes to a browser's
37+
IndexedDB storage. A polling technique is used to load underlying changes if you
38+
choose to 'autoLoad' your data into TinyBase.
39+
640
## v4.1
741

842
This release introduces the new ui-react-dom module. This provides pre-built
@@ -34,7 +68,7 @@ const App = ({store}) => (
3468
<SortedTableInHtmlTable tableId="pets" cellId="species" store={store} />
3569
);
3670

37-
const store = createStore().setTables({
71+
store.setTables({
3872
pets: {
3973
fido: {species: 'dog'},
4074
felix: {species: 'cat'},
@@ -48,13 +82,13 @@ console.log(app.innerHTML);
4882
// ->
4983
`
5084
<table>
51-
<thead>
52-
<tr><th>Id</th><th class="sorted ascending">↑ species</th></tr>
53-
</thead>
54-
<tbody>
55-
<tr><th>felix</th><td>cat</td></tr>
56-
<tr><th>fido</th><td>dog</td></tr>
57-
</tbody>
85+
<thead>
86+
<tr><th>Id</th><th class="sorted ascending">↑ species</th></tr>
87+
</thead>
88+
<tbody>
89+
<tr><th>felix</th><td>cat</td></tr>
90+
<tr><th>fido</th><td>dog</td></tr>
91+
</tbody>
5892
</table>
5993
`;
6094

@@ -122,21 +156,21 @@ for the 'pets' table:
122156
const sqlite3 = await sqlite3InitModule();
123157
const db = new sqlite3.oo1.DB(':memory:', 'c');
124158
store.setTables({pets: {fido: {species: 'dog'}}});
125-
const persister = createSqliteWasmPersister(store, sqlite3, db, {
159+
const sqlitePersister = createSqliteWasmPersister(store, sqlite3, db, {
126160
mode: 'tabular',
127161
tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
128162
});
129163

130-
await persister.save();
164+
await sqlitePersister.save();
131165
console.log(db.exec('SELECT * FROM pets;', {rowMode: 'object'}));
132166
// -> [{_id: 'fido', species: 'dog'}]
133167

134168
db.exec(`INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`);
135-
await persister.load();
169+
await sqlitePersister.load();
136170
console.log(store.getTables());
137171
// -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
138172

139-
persister.destroy();
173+
sqlitePersister.destroy();
140174
```
141175

142176
### CRDT Frameworks

site/home/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</p>
6363
</section>
6464

65-
<a id='new' href='/guides/releases/#v4-1'><em>NEW!</em> v4.1 release</a>
65+
<a id='new' href='/guides/releases/#v4-2'><em>NEW!</em> v4.2 release</a>
6666

6767
---
6868

src/types/docs/persisters.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* |-|-|-|
1414
* |persister-browser|createSessionPersister|Browser session storage|
1515
* |persister-browser|createLocalPersister|Browser local storage|
16+
* |persister-indexed-db|createIndexedDbPersister|Browser IndexedDB|
1617
* |persister-remote|createRemotePersister|Remote server|
1718
* |persister-file|createFilePersister|Local file (where possible)|
1819
* |persister-sqlite3|createSqlite3Persister|SQLite in Node, via [sqlite3](https://github.com/TryGhost/node-sqlite3)|

src/types/docs/persisters/persister-indexed-db.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* key-value data respectively, using 'k' and 'v' to store the key and value of
2020
* each entry, as shown in the example.
2121
*
22-
* Note that it is not possible to reactively detect changes to a browser
22+
* Note that it is not possible to reactively detect changes to a browser's
2323
* IndexedDB. If you do choose to enable automatic loading for the Persister
2424
* (with the startAutoLoad method), it needs to poll the database for changes.
2525
* The `autoLoadIntervalSeconds` method is used to indicate how often to do
@@ -30,7 +30,7 @@
3030
* 'autoLoad' mode.
3131
* @param onIgnoredError An optional handler for the errors that the Persister
3232
* would otherwise ignore when trying to save or load data. This is suitable for
33-
* debugging persistence issues in a development environment, since v4.0.4.
33+
* debugging persistence issues in a development environment.
3434
* @returns A reference to the new Persister object.
3535
* @example
3636
* This example creates a Persister object and persists the Store to the
@@ -39,24 +39,29 @@
3939
* ```js
4040
* const store =
4141
* createStore()
42-
* .setTables({pets: {fido: {species: 'dog'}}})
42+
* .setTable('pets', {fido: {species: 'dog'}})
43+
* .setTable('species', {dog: {price: 5}})
4344
* .setValues({open: true});
4445
* const persister = createIndexedDbPersister(store, 'petStore');
4546
*
4647
* await persister.save();
47-
* // IndexedDB:
48+
* // IndexedDB ->
4849
* // database petStore:
4950
* // objectStore t:
5051
* // object 0:
51-
* // k: pets
52-
* // v: {"fido":{"species":"dog"}}}
52+
* // k: "pets"
53+
* // v: {fido: {species: dog}}
54+
* // object 1:
55+
* // k: "species"
56+
* // v: {dog: {price: 5}}
5357
* // objectStore v:
5458
* // object 0:
55-
* // k: open
59+
* // k: "open"
5660
* // v: true
5761
*
5862
* persister.destroy();
5963
* ```
6064
* @category Creation
65+
* @since v4.2.0
6166
*/
6267
/// createIndexedDbPersister

0 commit comments

Comments
 (0)