Skip to content

Commit 9a508fa

Browse files
committed
[do] SQL docs
1 parent 944112b commit 9a508fa

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

site/guides/01_the_basics/9_architectural_options.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ A reliable all-in-one solution is to run both synchronization and storage on
164164
Cloudflare. Check out the Cloudflare Durable Objects guide and the dedicated
165165
[Vite starter
166166
template](https://github.com/tinyplex/vite-tinybase-ts-react-sync-durable-object)
167-
to see how to set this up.
167+
to see how to set this up. This approach can use either the
168+
DurableObjectStoragePersister (for KV-based storage) or the
169+
DurableObjectSqlStoragePersister (for SQLite-based storage) to persist data in a
170+
Durable Object.
168171

169172
## 6. Third-Party Synchronization
170173

site/guides/04_persistence/1_an_intro_to_persistence.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ is available.
5454

5555
See the Database Persistence guide for details on how to work with databases.
5656

57+
### Durable Object Persisters
58+
59+
These Persisters are designed to work with Durable Objects, which are a
60+
specialized type of server-side storage provided by CloudFlare. In conjunction
61+
with a WsServerDurableObject, they allow you to synchronize clients and then
62+
also persist data in a Durable Object, either in its key-value, or SQlite
63+
storage form.
64+
65+
| Persister | Storage |
66+
| -------------------------------- | ------------------------------------------- |
67+
| DurableObjectStoragePersister | Cloudflare Durable Object key-value storage |
68+
| DurableObjectSqlStoragePersister | Cloudflare Durable Object SQLite storage |
69+
5770
### Third-Party CRDT & Socket Persisters
5871

5972
These Persisters can bind your Store into third-party CRDT frameworks, or

site/guides/15_releases.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,55 @@ highlighted features.
55

66
---
77

8+
# v6.3
9+
10+
This release includes the new persister-durable-object-sql-storage module, which
11+
allows you to persist data in a Cloudflare Durable Object's SQLite-based storage
12+
in conjunction with websocket-based synchronization (using the
13+
WsServerDurableObject class).
14+
15+
```js yolo
16+
import {createMergeableStore} from 'tinybase';
17+
import {createDurableObjectSqlStoragePersister} from 'tinybase/persisters/persister-durable-object-sql-storage';
18+
import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
19+
20+
const config = {
21+
mode: 'fragmented',
22+
storagePrefix: 'my_app_',
23+
};
24+
25+
export class MyDurableObject extends WsServerDurableObject {
26+
createPersister() {
27+
const store = createMergeableStore();
28+
const persister = createDurableObjectSqlStoragePersister(
29+
store,
30+
this.ctx.storage.sql,
31+
config,
32+
);
33+
return persister;
34+
}
35+
}
36+
```
37+
38+
Prior to this release, the only way to persist data in a Durable Object was to
39+
use the persister-durable-object-storage module, which uses CloudFlare's
40+
key-value storage backend behind the scenes.
41+
42+
However, Cloudflare's SQLite storage backend for Durable Objects offers
43+
significantly better pricing compared to the key-value storage backend. The
44+
SQLite storage backend is Cloudflare's recommended storage option for new
45+
Durable Object namespaces.
46+
47+
Note that, before using this persister, you must configure your Durable Object
48+
class to use SQLite storage by adding a migration to your `wrangler.toml` or
49+
`wrangler.json` configuration file. Use `new_sqlite_classes` in your migration
50+
configuration to enable SQLite storage for your Durable Object class. See the
51+
module documentation for more information.
52+
53+
This release also addresses a local-storage persistence issue, #[257](https://github.com/tinyplex/tinybase/issues/257).
54+
55+
---
56+
857
# v6.2
958

1059
This release contains various packaging improvements and exposes some internal
@@ -60,6 +109,8 @@ generated in TinyBase MergeableStore objects.
60109
The rarely-used GetNow and Hash types have been moved from the mergeable-store
61110
module into the common module.
62111

112+
---
113+
63114
# v6.1
64115

65116
## In Summary
@@ -188,6 +239,8 @@ base Persister interface have been marked asynchronous and return Promises. The
188239
stopSync method in the Synchronizer interface and the destroy method in the
189240
Synchronizer server interfaces should also be considered asynchronous.
190241

242+
---
243+
191244
# v6.0
192245

193246
This major release is about updating dependencies and infrastructure rather than
@@ -225,6 +278,8 @@ to upgrade as soon as you can.
225278
Please let us know how these changes find you, and please file an issue on
226279
GitHub if you need help adapting to any of them.
227280

281+
---
282+
228283
# v5.4
229284

230285
## Durable Objects synchronization

src/@types/persisters/docs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Many entry points are provided (in separately installed modules), each of
88
* which returns different types of Persister that can load and save a Store.
99
* Between them, these allow you to store your TinyBase data locally, remotely,
10-
* to SQLite and PostgreSQL databases, and across synchronization boundaries
11-
* with CRDT frameworks.
10+
* to a Durable Object, to SQLite and PostgreSQL databases, and across
11+
* synchronization boundaries with CRDT frameworks.
1212
*
1313
* |Persister|Storage|Store|MergeableStore
1414
* |-|-|-|-|
@@ -17,6 +17,8 @@
1717
* |FilePersister|Local file (where possible)|Yes|Yes
1818
* |IndexedDbPersister|Browser IndexedDB|Yes|No
1919
* |RemotePersister|Remote server|Yes|No
20+
* |DurableObjectStoragePersister|Cloudflare Durable Object (KV)|No|Yes
21+
* |DurableObjectSqlStoragePersister|Cloudflare Durable Object (SQLite)|No|Yes
2022
* |Sqlite3Persister|SQLite in Node, via [sqlite3](https://github.com/TryGhost/node-sqlite3)|Yes|Yes*
2123
* |SqliteBunPersister| SQLite in Bun, via [bun:sqlite](https://bun.sh/docs/api/sqlite)|Yes|Yes*
2224
* |SqliteWasmPersister|SQLite in a browser, via [sqlite-wasm](https://github.com/tomayac/sqlite-wasm)|Yes|Yes*

0 commit comments

Comments
 (0)