Registry / database / simple-cloudflare-orm

simple-cloudflare-orm

JSON →
library1.0.9jsnpmunverified

A lightweight ORM and query builder for Cloudflare D1 databases. Current stable version: 1.0.9. Provides basic CRUD operations, filtering with WHERE clauses, JOIN support, column selection, ordering, pagination, and JSON field handling. Differentiators: simple API, direct Cloudflare D1 integration, and nested object transformation. It is still in early development with limited features (no bulk create, no OR/NOT conditions).

npm install simple-cloudflare-orm
INSTALL
IMPORT
SIG · SIMPLE-CLOUDFLARE-
S
simple-cloudflare-orm
databasejavascriptv1.0.9
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.

SimpleORM
import { SimpleORM } from 'simple-cloudflare-orm'
const SimpleORM = require('simple-cloudflare-orm')
Package is ESM-only. Default import is not available; named import is required.

Shows how to instantiate SimpleORM with a Cloudflare D1 binding, define table schemas, create a record, and query with JOIN, filtering, ordering, and limit.

import { SimpleORM } from 'simple-cloudflare-orm'; import type { D1Database } from '@cloudflare/workers-types'; // Define table schema as a JS object const tables = { users: { id: 'text primary key', name: 'text', email: 'text', status: 'text', roleID: 'text', createdAt: 'DATETIME DEFAULT CURRENT_TIMESTAMP', updatedAt: 'DATETIME DEFAULT CURRENT_TIMESTAMP' }, roles: { id: 'text primary key', name: 'text' } }; // Example Cloudflare Worker fetch handler export default { async fetch(request: Request, env: { DB: D1Database }) { const orm = new SimpleORM(env.DB, tables); // Insert a new user const newUser = await orm.create('users', { id: 'user1', name: 'Alice', email: 'alice@example.com', status: 'active', roleID: 'admin' }); // Find active users joined with roles, ordered by creation date descending const users = await orm.findAll('users', { include: [['roles', 'roles.id', 'users.roleID']], where: [ ['users.status', '=', 'active'] ], orderBy: { createdAt: 'DESC' }, limit: 10 }); return new Response(JSON.stringify(users), { headers: { 'content-type': 'application/json' } }); } };
Debug
Known issues
gotchaThe package is in early development; many features are missing (bulk create, OR/NOT conditions, case-insensitive search). Do not use for production with complex queries.
fix
Consider alternatives like Drizzle ORM or Kysely for production use.
affects: <2.0.0
breakingThe table definition must exactly match the database schema; mismatched column types can cause runtime errors.
fix
Ensure every column in the table object matches the D1 table schema exactly.
affects: >=1.0.0
Errors
Common errors & fixes
Error: SimpleORM is not a constructor
Using default import instead of named import.
fix
Use 'import { SimpleORM } from 'simple-cloudflare-orm'' (named import).
TypeError: env.DB is undefined
D1 binding not configured in wrangler.toml or environment.
fix
Add a D1 binding in wrangler.toml: [[d1_databases]] binding = "DB" database_name = "your-db" database_id = "..."
Error: Cannot find module 'simple-cloudflare-orm'
Package not installed or missing from node_modules.
fix
Run 'npm i simple-cloudflare-orm' in your project root.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Meta
1
Resources
simple-cloudflare-orm — npm install simple-cloudflare-orm · libregistry