kunii
Workers-native ORM docs for Cloudflare D1 and Durable Object SQLite
SQLite for the runtime you already have
kunii is a lightweight ORM for Cloudflare D1 and Durable Object SQLite. It keeps the API Worker-safe, uses a compact schema DSL, and stays close to SQL instead of hiding the database behind a large abstraction layer.
What it gives you
- Schema DSL: Define tables, mixins, indexes, JSON columns, enums, and foreign keys with a compact object format.
- Chainable queries:
Query with
where,orderBy,limit,offset,count, anddistinctwithout leaving SQL-shaped concepts behind. - Relations and JSON: Load related rows, filter by relation existence, and query JSON columns with dotted paths.
- Write helpers:
Use
returning,upsert, anddb.batch()for common write workflows and atomic commits. - D1 and DO support: Use the same ORM across D1 bindings and Durable Object SQLite storage.
- Framework adapters: Initialize D1 migrations and clients in Cloudflare-hosted SvelteKit, Next, Nuxt, Astro, and Koze apps.
- Migration helpers: Generate initial SQL, diff schemas, and run tracked runtime migrations when needed.
Design constraints
The ORM is built around a few hard constraints:
- No Node-only runtime assumptions
- No dependency-heavy query layer
- SQL semantics stay visible
- Same mental model across D1 and Durable Object SQLite