d1zzle: a type-safe ORM built only for Cloudflare D1 (open source)

Drizzle's API, rebuilt to target Cloudflare D1 and Workers and nothing else. It cuts the bundle by 43% when minified.

Period
Published and maintained
Stack
TypeScript Cloudflare D1 Cloudflare Workers vitest

Why write another ORM

When you build on Cloudflare D1, the layer a general-purpose ORM carries so that it can also speak to other databases ends up in your Worker bundle. The dialect indirection, the transaction and savepoint subsystem, the prepared-statement abstraction that covers both sync and async drivers: all of it is reachable from the SQLite entry point, so no bundler can drop it. Tree-shaking removes code that cannot be reached, not code that is merely general.

d1zzle removes that layer at the source instead. The API is inherited from Drizzle, so what you already know still applies.

import { drizzle, eq, integer, sqliteTable, text } from 'd1zzle';

export const users = sqliteTable('users', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  email: text('email').notNull().unique(),
  name: text('name'),
});

const db = drizzle(env.DB);
const one = await db.select().from(users).where(eq(users.id, 1)).get();

What it buys you

The comparison below bundles a Worker with esbuild that contains the driver, the schema DSL and a single select().from().where().

minifiedgzipped
drizzle-orm/d1 + drizzle-orm/sqlite-core77.8 kB22.2 kB
d1zzle44.1 kB15.3 kB
−43%−31%

Narrowing the target to one database does more than let you delete code. It also means the features that have no counterpart in other databases can be treated as first class. D1’s positional read path, its bind-parameter limit, the Sessions API and the billing counters surface in the API rather than sitting behind an abstraction.

Used in production

d1zzle is not a library that was published and left alone. It runs the whole data layer of arukutomaru in production, and Better Auth sits on the same ORM through d1zzle’s native adapter (d1zzle/better-auth). Rough edges found while using it are written up in the consuming repository’s notes and fed back into the library itself.

Contact us