DpcFragmented
The DpcFragmented
type represents the configuration for fragmented persistence mode in a DurableObjectSqlStoragePersister
.
{
mode: "fragmented";
storagePrefix?: string;
}
Type | Description | |
---|---|---|
mode | "fragmented" | The mode property must be set to 'fragmented' to enable fragmented persistence mode. |
storagePrefix? | string | The storagePrefix property lets you specify an optional prefix for the database table names used in fragmented mode. |
This mode stores each table, row, cell, and value as separate database rows, avoiding Cloudflare's 2MB row limit that can be hit with large stores in JSON mode. While this creates more database writes, it provides better scalability for larger datasets.
Example
This example shows how to configure a DurableObjectSqlStoragePersister
to use fragmented mode with a custom storage prefix.
import {createMergeableStore} from 'tinybase';
import {createDurableObjectSqlStoragePersister} from 'tinybase/persisters/persister-durable-object-sql-storage';
import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
const config = {
mode: 'fragmented',
storagePrefix: 'my_app_',
};
export class MyDurableObject extends WsServerDurableObject {
createPersister() {
const store = createMergeableStore();
const persister = createDurableObjectSqlStoragePersister(
store,
this.ctx.storage.sql,
config,
);
return persister;
}
}
Since
v6.3.0