|
18 | 18 | /// persister-durable-object-sql-storage |
19 | 19 |
|
20 | 20 | /** |
21 | | - * The DpcKeyValue type represents the configuration for key-value persistence mode |
| 21 | + * The DpcFragmented type represents the configuration for fragmented persistence mode |
22 | 22 | * in a DurableObjectSqlStoragePersister. |
23 | 23 | * |
24 | 24 | * This mode stores each table, row, cell, and value as separate database rows, |
|
28 | 28 | * |
29 | 29 | * @example |
30 | 30 | * This example shows how to configure a DurableObjectSqlStoragePersister to use |
31 | | - * key-value mode with a custom storage prefix: |
| 31 | + * fragmented mode with a custom storage prefix: |
32 | 32 | * |
33 | 33 | * ```js |
34 | 34 | * const config = { |
35 | | - * mode: 'key-value', |
| 35 | + * mode: 'fragmented', |
36 | 36 | * storagePrefix: 'my_app_' |
37 | 37 | * }; |
38 | 38 | * |
|
46 | 46 | * @category Configuration |
47 | 47 | * @since v6.2.0 |
48 | 48 | */ |
49 | | -/// DpcKeyValue |
| 49 | +/// DpcFragmented |
50 | 50 | { |
51 | 51 | /** |
52 | | - * The mode property must be set to 'key-value' to enable key-value persistence mode. |
| 52 | + * The mode property must be set to 'fragmented' to enable fragmented persistence mode. |
53 | 53 | * @since v6.2.0 |
54 | 54 | */ |
55 | | - /// DpcKeyValue.mode |
| 55 | + /// DpcFragmented.mode |
56 | 56 | /** |
57 | 57 | * The storagePrefix property lets you specify an optional prefix for the database |
58 | | - * table names used in key-value mode. |
| 58 | + * table names used in fragmented mode. |
59 | 59 | * |
60 | 60 | * This is useful when you have multiple stores or applications sharing the same |
61 | 61 | * Durable Object SQL storage and want to avoid table name conflicts. |
|
71 | 71 | * // Creates tables: user_data_tinybase_tables, user_data_tinybase_values |
72 | 72 | * |
73 | 73 | * const config = { |
74 | | - * mode: 'key-value', |
| 74 | + * mode: 'fragmented', |
75 | 75 | * storagePrefix: 'user_data_' |
76 | 76 | * }; |
77 | 77 | * ``` |
78 | 78 | * |
79 | 79 | * @since v6.2.0 |
80 | 80 | */ |
81 | | - /// DpcKeyValue.storagePrefix |
| 81 | + /// DpcFragmented.storagePrefix |
82 | 82 | } |
83 | 83 |
|
84 | 84 | /** |
|
87 | 87 | * |
88 | 88 | * This allows the persister to support multiple persistence modes: |
89 | 89 | * - JSON mode (via DpcJson): Stores the entire Store as JSON in a single row |
90 | | - * - Key-value mode (via DpcKeyValue): Stores each piece of data as separate rows |
91 | | - * - Tabular mode (via DpcTabular): Maps TinyBase tables to database tables |
| 90 | + * - Fragmented mode (via DpcFragmented): Stores each piece of data as separate rows |
92 | 91 | * |
93 | 92 | * @example |
94 | 93 | * This example shows the different configuration options: |
|
100 | 99 | * storeTableName: 'my_store' |
101 | 100 | * }; |
102 | 101 | * |
103 | | - * // Key-value mode |
104 | | - * const kvConfig = { |
105 | | - * mode: 'key-value', |
| 102 | + * // Fragmented mode |
| 103 | + * const fragmentedConfig = { |
| 104 | + * mode: 'fragmented', |
106 | 105 | * storagePrefix: 'app_' |
107 | 106 | * }; |
108 | 107 | * |
109 | | - * // Tabular mode |
110 | | - * const tabularConfig = { |
111 | | - * mode: 'tabular', |
112 | | - * tables: { |
113 | | - * load: {pets: 'pets_table'}, |
114 | | - * save: {pets: 'pets_table'} |
115 | | - * } |
116 | | - * }; |
117 | 108 | * ``` |
118 | 109 | * |
119 | 110 | * @category Configuration |
|
208 | 199 | * For more details on Durable Object migrations, see the |
209 | 200 | * {@link https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/ | Cloudflare documentation}. |
210 | 201 | * |
211 | | - * A DurableObjectSqlStoragePersister supports both regular Store objects and |
212 | | - * MergeableStore objects. When used with a MergeableStore, it can persist the |
213 | | - * complete CRDT metadata required for proper merging operations. |
214 | | - * |
215 | | - * A database Persister uses one of three modes: either a JSON serialization of |
216 | | - * the whole Store stored in a single row of a table (the default), a key-value |
| 202 | + * A database Persister uses one of two modes: either a JSON serialization of |
| 203 | + * the whole Store stored in a single row of a table (the default), a fragmented |
217 | 204 | * mode that stores each piece of data separately to avoid Cloudflare's 2MB row |
218 | | - * limit, or a tabular mapping of Table Ids to database table names and vice-versa). |
| 205 | + * limit. |
219 | 206 | * |
220 | 207 | * **JSON Mode (Default)**: Stores the entire Store as JSON in a single database |
221 | 208 | * row. This is efficient for smaller stores but may hit Cloudflare's 2MB row |
222 | 209 | * limit for very large stores. Uses fewer database writes. |
223 | 210 | * |
224 | | - * **Key-Value Mode**: Stores each table, row, cell, and value as separate database |
| 211 | + * **Fragmented Mode**: Stores each table, row, cell, and value as separate database |
225 | 212 | * rows. Use this mode if you're concerned about hitting Cloudflare's 2MB row |
226 | 213 | * limit with large stores in JSON mode. This mode creates more database writes |
227 | 214 | * but avoids row size limitations. |
228 | 215 | * |
229 | | - * **Tabular Mode**: Maps TinyBase tables directly to database tables for |
230 | | - * traditional relational database usage. |
231 | | - * |
232 | 216 | * The third argument is a DatabasePersisterConfig object that configures which |
233 | 217 | * of those modes to use, and settings for each. If the third argument is simply |
234 | 218 | * a string, it is used as the `storeTableName` property of the JSON |
235 | | - * serialization. If it is the string 'key-value', it enables key-value mode. |
| 219 | + * serialization. If it is the string 'fragmented', it enables fragmented mode. |
236 | 220 | * |
237 | | - * See the documentation for the DpcJson, DpcKeyValue, and DpcTabular types for more |
| 221 | + * See the documentation for the DpcJson, DpcFragmented, and DpcTabular types for more |
238 | 222 | * information on how all of those modes can be configured. |
239 | 223 | * |
240 | 224 | * As well as providing a reference to the Store or MergeableStore to persist, you must |
|
244 | 228 | * @param sqlStorage The Durable Object SQL storage to persist the Store to. |
245 | 229 | * @param configOrStoreTableName A DatabasePersisterConfig to configure the |
246 | 230 | * persistence mode (or a string to set the `storeTableName` property of the |
247 | | - * JSON serialization, or 'key-value' to enable key-value mode). |
| 231 | + * JSON serialization). |
248 | 232 | * @param onSqlCommand An optional handler called every time the Persister |
249 | 233 | * executes a SQL command or query. This is suitable for logging persistence |
250 | 234 | * behavior in a development environment. |
|
298 | 282 | * } |
299 | 283 | * ``` |
300 | 284 | * @example |
301 | | - * This example creates a DurableObjectSqlStoragePersister object using key-value |
| 285 | + * This example creates a DurableObjectSqlStoragePersister object using fragmented |
302 | 286 | * mode to avoid Cloudflare's 2MB row limit for large stores. |
303 | 287 | * |
304 | 288 | * ```js yolo |
|
312 | 296 | * const persister = createDurableObjectSqlStoragePersister( |
313 | 297 | * store, |
314 | 298 | * this.ctx.storage.sql, |
315 | | - * 'key-value', |
| 299 | + * {mode: 'fragmented'}, |
316 | 300 | * ); |
317 | 301 | * return persister; |
318 | 302 | * } |
319 | 303 | * } |
320 | 304 | * ``` |
321 | 305 | * @example |
322 | | - * This example creates a DurableObjectSqlStoragePersister object using key-value |
| 306 | + * This example creates a DurableObjectSqlStoragePersister object using fragmented |
323 | 307 | * mode with a custom storage prefix. |
324 | 308 | * |
325 | 309 | * ```js yolo |
|
333 | 317 | * const persister = createDurableObjectSqlStoragePersister( |
334 | 318 | * store, |
335 | 319 | * this.ctx.storage.sql, |
336 | | - * {mode: 'key-value', storagePrefix: 'my_app_'}, |
337 | | - * ); |
338 | | - * return persister; |
339 | | - * } |
340 | | - * } |
341 | | - * ``` |
342 | | - * @example |
343 | | - * This example creates a DurableObjectSqlStoragePersister object with tabular |
344 | | - * mapping configuration for direct table-to-table persistence. |
345 | | - * |
346 | | - * ```js yolo |
347 | | - * import {createMergeableStore} from 'tinybase'; |
348 | | - * import {createDurableObjectSqlStoragePersister} from 'tinybase/persisters/persister-durable-object-sql-storage'; |
349 | | - * import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object'; |
350 | | - * |
351 | | - * export class MyDurableObject extends WsServerDurableObject { |
352 | | - * createPersister() { |
353 | | - * const store = createMergeableStore(); |
354 | | - * const persister = createDurableObjectSqlStoragePersister( |
355 | | - * store, |
356 | | - * this.ctx.storage.sql, |
357 | | - * { |
358 | | - * mode: 'tabular', |
359 | | - * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}}, |
360 | | - * }, |
| 320 | + * {mode: 'fragmented', storagePrefix: 'my_app_'}, |
361 | 321 | * ); |
362 | 322 | * return persister; |
363 | 323 | * } |
|
0 commit comments