Skip to content

ORM

The Kuratchi ORM is a minimal runtime query builder designed for Cloudflare D1 and Workers. It provides a fluent API with standard SQL semantics and leverages native database APIs for optimal performance.

import { createOrmClient } from '@kuratchi/sdk';
// With explicit adapter (recommended)
const db = await createOrmClient({
schema: mySchema,
databaseName: 'my-database',
bindingName: 'MY_DB',
adapter: 'd1' // or 'rpc'
});
// Query examples
const users = await db.users.many();
const user = await db.users.where({ id: '123' }).first();
await db.users.where({ id: '123' }).update({ name: 'New Name' });
  • Native API optimization - Uses first(), batch(), exec() when available
  • Adapter-aware - Works with D1, RPC, and HTTP adapters
  • Standard SQL semantics - where, orderBy, limit, offset
  • Interchangeable chaining - .update(values).where({...}) or .where({...}).update(values)
  • JSON column handling - Auto-serialize/deserialize JSON columns
  • Type-safe - Full TypeScript support with schema inference
  • Lightweight - No heavy dependencies, safe for Workers runtime

The ORM automatically uses native APIs based on the adapter:

Adapterfirst()many()Migrations
D1stmt.first()stmt.all()db.exec()
RPCbinding.first()binding.run()binding.exec()
HTTPPOST /api/firstPOST /api/runPOST /api/exec