Registry / database / cl-orm

cl-orm

JSON →
library2.1.3jsnpmunverified

CL ORM is a lightweight ORM for Cloudflare Workers, supporting both D1 and Durable Objects SQL Storage. Version 2.1.3 is the latest stable release, with a rapid release cadence. It provides a unified Connection interface across different database drivers, automatic prepared statements, and user-friendly query building with operators like eq, ne, gt, lt, gte, lte. It is designed to be intuitive and productive, focusing on essential functionality without the overhead of larger ORMs like Prisma or Drizzle.

npm install cl-orm
INSTALL
IMPORT
SIG · CL-ORM
C
cl-orm
databasejavascriptv2.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useD1
import { useD1 } from 'cl-orm'
import { useD1 } from 'cl-orm/lib'
ESM-only. useD1 is for Cloudflare D1 binding.
useDO
import { useDO } from 'cl-orm'
const useDO = require('cl-orm').useDO
ESM-only. useDO is for Durable Objects SQL Storage.
OP
import { OP } from 'cl-orm'
import OP from 'cl-orm'
Named export, not default. OP contains operators like eq, ne, gt, lt, gte, lte.
Connection
import type { Connection } from 'cl-orm'
import { Connection } from 'cl-orm'
Connection is a TypeScript interface, import as type to avoid runtime issues.

Shows how to connect to D1, create a table, insert a row, and select using an operator in a Cloudflare Worker.

import { useD1 } from 'cl-orm'; import { OP } from 'cl-orm'; export default { async fetch(request: Request, env: Env): Promise<Response> { const db = useD1(env.DB); // Create table await db.query(`CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)`); // Insert await db.insert({ into: 'users', values: { name: 'John', age: 30 } }); // Select with operators const user = await db.select({ from: 'users', where: OP.eq('name', 'John'), limit: 1, }); return new Response(JSON.stringify(user)); }, };
Debug
Known issues
breakingFrom v2, cl-orm is ESM-only and requires Node.js 18+ or Cloudflare Workers.
fix
Use ES module imports. For CommonJS projects, consider dynamic import or upgrade to ESM.
affects: >=2.0.0
gotchaThe Connection interface is not constructable; only useD1() and useDO() create connections.
fix
Always create connections via useD1(env.DB) or useDO(this.ctx.storage.sql).
affects: >=1.0.0
gotchalimit: 1 in select returns a direct object or null, not an array.
fix
When using limit: 1, handle single object result. For arrays, omit limit or use limit > 1.
affects: >=1.0.0
deprecatedIn v1, operators were exported individually; in v2 they are grouped under OP.
fix
Use OP.eq(), OP.ne(), etc. instead of importing eq, ne separately.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'DB')
useD1 expects a D1 database binding but env is undefined or missing DB.
fix
Ensure env is passed correctly and bindings are configured in wrangler.toml.
Error: useDO must be called within a Durable Object's method, e.g., fetch or alarm.
useDO requires Durable Object's storage.sql context, not available outside DO.
fix
Call useDO only inside a Durable Object class method, passing this.ctx.storage.sql.
SyntaxError: Named export 'Connection' not found. The requested module 'cl-orm' is a CommonJS module...
Importing Connection as a value instead of type in a CommonJS environment.
fix
Use import type { Connection } from 'cl-orm' or ensure your project is ESM.
Upgrade
Version history
2.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
packagecl-orm
cl-orm — npm install cl-orm · libregistry