Skip to content

Cloudflare Workers

This page is the canonical reference for working with Cloudflare Workers in TomeTrove. For the rationale behind choosing Workers, see ADR 0002. For coding conventions including the commands below, see Coding style.

STOP. Your knowledge of Cloudflare Workers APIs and limits may be outdated. Always retrieve current documentation before any Workers, KV, R2, D1, Durable Objects, Queues, Vectorize, AI, or Agents SDK task.

Docs

For all limits and quotas, retrieve from the product's /platform/limits/ page. eg. /workers/platform/limits

Commands

Command Purpose
npx wrangler dev Local development
npx wrangler deploy Deploy to Cloudflare
npx wrangler types Generate TypeScript types
npx drizzle-kit generate Generate SQL migration from TS schema
npx drizzle-kit migrate Apply migrations to database
npx vitest Run tests (Vitest + Workers runtime)
npx tsc --noEmit Type check (static analysis)
npx biome check --write Format + lint + fix (Biome)

Run wrangler types after changing bindings in wrangler.jsonc. Run drizzle-kit generate after changing schema in src/db/schema.ts.

Node.js Compatibility

Node.js compatibility in Workers

Errors

Product Docs

Retrieve API references and limits from: /kv/ · /r2/ · /d1/ · /durable-objects/ · /queues/ · /vectorize/ · /workers-ai/ · /agents/

Relevant ADRs: ADR 0003 (TiDB Cloud Starter via serverless driver), ADR 0005 (R2), ADR 0008 (Hono on Workers).

TiDB Cloud integration

TomeTrove connects to TiDB Cloud Starter using the @tidbcloud/serverless driver, which works over HTTP (Workers cannot make TCP connections). See the coding style guide for setup and usage, and the official PingCAP integration docs.

Best Practices (conditional)

If the application uses Durable Objects or Workflows, refer to the relevant best practices: