Package Exports
- cl-orm
- cl-orm/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cl-orm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
CL ORM
⛅️ A lightweight ORM for Cloudflare Workers (D1 and Durable Objects), designed to be intuitive and productive, focused on essential functionality.
Why
- Supports both Cloudflare D1 and Durable Objects SQL Storage.
- Unified Connection interface across different database drivers.
- User-friendly ORM for INSERT, SELECT, UPDATE, DELETE and WHERE clauses.
- Automatic Prepared Statements.
Documentation
See detailed specifications and usage in Documentation section for queries, advanced concepts and much more.
Quickstart
Installation
npm i cl-ormConnect
D1
import { useD1 } from 'cl-orm';
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const db = useD1(env.DB);
await db.query('SELECT 1');
// ...
},
};Durable Objects
import { useDO } from 'cl-orm';
import { DurableObject } from 'cloudflare:workers';
export class MyDurableObject extends DurableObject {
async fetch(request: Request): Promise<Response> {
const db = useDO(this.ctx.storage.sql);
await db.query('SELECT 1');
// ...
}
}Basic Usage Example
The following example is based on TypeScript and ES Modules.
import type { Connection } from 'cl-orm';
import { OP } from 'cl-orm';
export const getUser = async (db: Connection, id: number) => {
const user = await db.select({
from: 'users',
where: OP.eq('id', id),
limit: 1,
});
return user;
};
// Usage: await getUser(db, 15);- See all available operators (OP) here.
- Due to
limit: 1, it returns a direct object with the row result ornull.
Acknowledgements
- The operator names eq, ne, gt, lt, gte and lte are inspired by Sequelize.
- Contributors.
- This project is adapted from MySQL2 ORM.