|
16 | 16 | * @since v6.2.0 |
17 | 17 | */ |
18 | 18 | /// persister-durable-object-sql-storage |
| 19 | + |
| 20 | +/** |
| 21 | + * The DpcKeyValue type represents the configuration for key-value persistence mode |
| 22 | + * in a DurableObjectSqlStoragePersister. |
| 23 | + * |
| 24 | + * This mode stores each table, row, cell, and value as separate database rows, |
| 25 | + * avoiding Cloudflare's 2MB row limit that can be hit with large stores in JSON mode. |
| 26 | + * While this creates more database writes, it provides better scalability for |
| 27 | + * larger datasets. |
| 28 | + * |
| 29 | + * @example |
| 30 | + * This example shows how to configure a DurableObjectSqlStoragePersister to use |
| 31 | + * key-value mode with a custom storage prefix: |
| 32 | + * |
| 33 | + * ```js |
| 34 | + * const config = { |
| 35 | + * mode: 'key-value', |
| 36 | + * storagePrefix: 'my_app_' |
| 37 | + * }; |
| 38 | + * |
| 39 | + * const persister = createDurableObjectSqlStoragePersister( |
| 40 | + * store, |
| 41 | + * ctx.storage.sql, |
| 42 | + * config |
| 43 | + * ); |
| 44 | + * ``` |
| 45 | + * |
| 46 | + * @category Configuration |
| 47 | + * @since v6.2.0 |
| 48 | + */ |
| 49 | +/// DpcKeyValue |
| 50 | +{ |
| 51 | + /** |
| 52 | + * The mode property must be set to 'key-value' to enable key-value persistence mode. |
| 53 | + * @since v6.2.0 |
| 54 | + */ |
| 55 | + /// DpcKeyValue.mode |
| 56 | + /** |
| 57 | + * The storagePrefix property lets you specify an optional prefix for the database |
| 58 | + * table names used in key-value mode. |
| 59 | + * |
| 60 | + * This is useful when you have multiple stores or applications sharing the same |
| 61 | + * Durable Object SQL storage and want to avoid table name conflicts. |
| 62 | + * |
| 63 | + * The prefix will be sanitized to only include alphanumeric characters and underscores. |
| 64 | + * For example, a prefix of 'my-app!' becomes 'my_app_'. |
| 65 | + * |
| 66 | + * @example |
| 67 | + * This example shows how the storagePrefix affects table names: |
| 68 | + * |
| 69 | + * ```js |
| 70 | + * // With storagePrefix: 'user_data_' |
| 71 | + * // Creates tables: user_data_tinybase_tables, user_data_tinybase_values |
| 72 | + * |
| 73 | + * const config = { |
| 74 | + * mode: 'key-value', |
| 75 | + * storagePrefix: 'user_data_' |
| 76 | + * }; |
| 77 | + * ``` |
| 78 | + * |
| 79 | + * @since v6.2.0 |
| 80 | + */ |
| 81 | + /// DpcKeyValue.storagePrefix |
| 82 | +} |
| 83 | + |
| 84 | +/** |
| 85 | + * The DurableObjectSqlDatabasePersisterConfig type represents the union of all |
| 86 | + * possible configuration types for a DurableObjectSqlStoragePersister. |
| 87 | + * |
| 88 | + * This allows the persister to support multiple persistence modes: |
| 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 |
| 92 | + * |
| 93 | + * @example |
| 94 | + * This example shows the different configuration options: |
| 95 | + * |
| 96 | + * ```js |
| 97 | + * // JSON mode (default) |
| 98 | + * const jsonConfig = { |
| 99 | + * mode: 'json', |
| 100 | + * storeTableName: 'my_store' |
| 101 | + * }; |
| 102 | + * |
| 103 | + * // Key-value mode |
| 104 | + * const kvConfig = { |
| 105 | + * mode: 'key-value', |
| 106 | + * storagePrefix: 'app_' |
| 107 | + * }; |
| 108 | + * |
| 109 | + * // Tabular mode |
| 110 | + * const tabularConfig = { |
| 111 | + * mode: 'tabular', |
| 112 | + * tables: { |
| 113 | + * load: {pets: 'pets_table'}, |
| 114 | + * save: {pets: 'pets_table'} |
| 115 | + * } |
| 116 | + * }; |
| 117 | + * ``` |
| 118 | + * |
| 119 | + * @category Configuration |
| 120 | + * @since v6.2.0 |
| 121 | + */ |
| 122 | +/// DurableObjectSqlDatabasePersisterConfig |
| 123 | + |
19 | 124 | /** |
20 | 125 | * The DurableObjectSqlStoragePersister interface represents a Persister that lets |
21 | 126 | * you save and load Store data to and from Cloudflare Durable Object SQL storage. |
|
0 commit comments