Registry / database / durable-utils

durable-utils

JSON →
library0.3.5jsnpmunverified

Utilities for Cloudflare Durable Objects and Workers, including SQL migration management, static sharding, and retry helpers. Current stable version 0.3.5. Released as needed; API still in design phase for sharding. Key differentiator: provides SQL schema migrations that track state in DO storage, and a static sharding abstraction for horizontally scaling Durable Objects without data loss.

npm install durable-utils
INSTALL
IMPORT
SIG · DURABLE-UTILS
D
durable-utils
databasejavascriptv0.3.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SQLSchemaMigration
import { SQLSchemaMigration } from 'durable-utils/sql-migrations'
import { SQLSchemaMigration } from 'durable-utils'
Exported from subpath 'durable-utils/sql-migrations', not package root.
SQLSchemaMigrations
import { SQLSchemaMigrations } from 'durable-utils/sql-migrations'
const { SQLSchemaMigrations } = require('durable-utils/sql-migrations')
Package is ESM-only; CommonJS require not supported.
StaticShardedDO
import { StaticShardedDO } from 'durable-utils/sharded-do'
import { StaticShardedDO } from 'durable-utils'
Exported from 'durable-utils/sharded-do', not package root.
retry
import { retry } from 'durable-utils/retry'
import { retry } from 'durable-utils'
Retry utilities in subpath 'durable-utils/retry'.

Shows how to define SQL migrations and use SQLSchemaMigrations in a Durable Object.

import { SQLSchemaMigration, SQLSchemaMigrations } from 'durable-utils/sql-migrations'; const migrations: SQLSchemaMigration[] = [ { idMonotonicInc: 1, description: 'init', sql: 'CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY, name TEXT);' }, { idMonotonicInc: 2, description: 'add email', sql: 'ALTER TABLE users ADD email TEXT;' }, ]; export class MyDO extends DurableObject { private sql: SqlStorage; private migrator: SQLSchemaMigrations; constructor(ctx: DurableObjectState, env: Env) { super(ctx, env); this.sql = ctx.storage.sql; this.migrator = new SQLSchemaMigrations({ doStorage: ctx.storage, migrations }); } async handleRequest() { await this.migrator.runAll(); return this.sql.exec('SELECT * FROM users;').toArray(); } }
Debug
Known issues
gotchaStaticShardedDO API is in design phase and may change. The static shard count guarantee will not change to avoid data loss.
fix
Monitor changelog for API changes; shard count is safe.
affects: >=0.0.0
gotchaSubpath exports must be used; importing from package root may not include utilities.
fix
Import from specific subpaths: 'durable-utils/sql-migrations', 'durable-utils/sharded-do', 'durable-utils/retry'.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'durable-utils' or its corresponding type declarations.
Importing from package root instead of subpath.
fix
Use specific subpath imports, e.g., 'durable-utils/sql-migrations'.
ERR_REQUIRE_ESM: require() of ES Module ... not supported.
Package is ESM-only, CommonJS require not supported.
fix
Use dynamic import() or convert project to ESM, e.g., "type": "module" in package.json.
Upgrade
Version history
0.3.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
4
Bingbot
2
Resources
durable-utils — npm install durable-utils · libregistry