Registry /
database / cojson-storage-do-sqlite
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.
createInstance
✓ import { createInstance } from 'cojson-storage-do-sqlite'
✗ const createInstance = require('cojson-storage-do-sqlite')
Package is ESM only. Use named import.
CojsonStorageDoSqlite
✓ import type { CojsonStorageDoSqlite } from 'cojson-storage-do-sqlite'
✗ import { CojsonStorageDoSqlite } from 'cojson-storage-do-sqlite'
CojsonStorageDoSqlite is a class exported as a type; for runtime usage you need the default export or other named exports. Use type import to avoid bundling issues.
default
✓ import CojsonStorageDoSqlite from 'cojson-storage-do-sqlite'
✗ import { default as CojsonStorageDoSqlite } from 'cojson-storage-do-sqlite'
Default export is the main class. Named default import is unnecessary.
Shows how to instantiate CojsonStorageDoSqlite inside a Cloudflare Durable Object, using the DurableObjectStorage from the constructor.
import CojsonStorageDoSqlite from 'cojson-storage-do-sqlite';
// In your Durable Object class
export class MyDO {
private storage: DurableObjectStorage;
constructor(ctx: DurableObjectState, env: Env) {
this.storage = ctx.storage;
}
async fetch(request: Request): Promise<Response> {
const store = new CojsonStorageDoSqlite(this.storage);
// Use store methods...
return new Response('OK');
}
}
Debug
Known issues
gotchaOnly works with Durable Objects SQLite storage; other storage backends will break.fixEnsure you have enabled SQLite storage in your wrangler.toml: [durable_objects] bindings = [{ name = "MY_DO", class_name = "MyDO" }] and set sqlite = true in the DO's migration. affects: >=0.0.0
breakingIn v0.20.0, the constructor signature changed from (storage, options?) to (storage).fixRemove second argument if any; pass all options via storage's own scoping.
affects: >=0.20.0
deprecatedThe old default export 'CojsonStorageDoSqlite' is deprecated in favor of 'createInstance' factory function.fixUse createInstance(storage) instead of new CojsonStorageDoSqlite(storage).
affects: >=0.19.0 <0.20.0
Errors
Common errors & fixes
TypeError: DurableObjectStorage is not a constructor
Using CojsonStorageDoSqlite outside of a Durable Object context, or forgetting to pass ctx.storage.
fixEnsure you instantiate inside a Durable Object class and pass ctx.storage (the DurableObjectState's storage property).
Cannot find module 'cojson-storage-do-sqlite' or its corresponding type declarations
Package not installed or not compatible with tsconfig (missing moduleResolution: bundler or node16).
fixRun npm install cojson-storage-do-sqlite, and ensure tsconfig.json has "moduleResolution": "bundler" or "node16" and "module": "esnext".
Error: No SQLite storage available. You may need to enable durable_objects and sqlite in wrangler.toml.
Durable Object not configured with SQLite.
fixAdd sqlite = true in the [durable_objects] migrations in wrangler.toml.
Audit
Dependencies
@cloudflare/workers-typesoptionalRequired for TypeScript typings when running in Cloudflare Workers environment