A simple, strictly typed ORM for Cloudflare's D1 SQLite database. Version 0.9.2 provides a TypeScript-first API with inferred types, supporting CRUD operations, migrations, and query building. It differentiates from raw D1 usage by offering model-based schema definition, automatic type inference via Infer, and common ORM patterns like first/all/insert/update/delete. Designed for Cloudflare Workers, it requires @cloudflare/workers-types v3.16.0+ and is actively maintained with a focus on type safety.
npm install d1-ormNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Defines a User model with automatic type inference and retrieves the first record matching a condition.
Update constructor call: new D1Orm(env.DB) instead of new D1Orm({ D1: env.DB }).Replace createTable calls with migrate method on Model.
Ensure Model is declared using 'const' and not 'let' to preserve literal types for inference.
Use DataTypes constants (e.g., DataTypes.STRING) instead of 'STRING' string.
Replace find with First({ where: ... }) for single result or All({ where: ... }) for multiple.Replace 'const D1Orm = require("d1-orm")' with 'import { D1Orm } from "d1-orm"' in an ESM context.Update to d1-orm@0.9 or later, or use 'find' in older versions.
Use DataTypes constants: DataTypes.INTEGER instead of 'INTEGER'.
Install @cloudflare/workers-types and add 'types': ['@cloudflare/workers-types'] to tsconfig.json.