d1-orm
TypeScript icon, indicating that this package has built-in type declarations

0.9.2 • Public • Published

D1-Orm

✨ A simple, strictly typed ORM, to assist you in using Cloudflare's D1 product

Docs can be found at https://docs.interactions.rest/d1-orm/

API reference can be found at https://orm.interactions.rest/modules

Installation

This package can be found on NPM

npm install d1-orm

Usage

This package is recommended to be used with @cloudflare/workers-types 3.16.0+.

import { D1Orm, DataTypes, Model } from "d1-orm";
import type { Infer } from "d1-orm";

export interface Env {
	// from @cloudflare/workers-types
	DB: D1Database;
}

export default {
	async fetch(request: Request, env: Env) {
		const orm = new D1Orm(env.DB);
		const users = new Model(
			{
				D1Orm: orm,
				tableName: "users",
				primaryKeys: "id",
				autoIncrement: "id",
				uniqueKeys: [["email"]],
			},
			{
				id: {
					type: DataTypes.INTEGER,
					notNull: true,
				},
				name: {
					type: DataTypes.STRING,
					notNull: true,
					defaultValue: "John Doe",
				},
				email: {
					type: DataTypes.STRING,
				},
			},
		);
		type User = Infer<typeof users>;

		await users.First({
			where: {
				id: 1,
			},
		});
		// Promise<User | null>
	},
};

For more information, refer to the docs.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.9.243latest

Version History

VersionDownloads (Last 7 Days)Published
0.9.243
0.9.10
0.9.023
0.8.08
0.7.226
0.7.10
0.7.01
0.6.00
0.5.52
0.5.40
0.5.32
0.5.20
0.5.11
0.5.01
0.4.01
0.3.31
0.3.20
0.3.11
0.3.01
0.2.30
0.2.21
0.2.11
0.2.01
0.1.30
0.1.20
0.1.10
0.1.00
0.0.10

Package Sidebar

Install

npm i d1-orm

Weekly Downloads

114

Version

0.9.2

License

ISC

Unpacked Size

66 kB

Total Files

19

Last publish

Collaborators

  • skye31