0.9.2 • Published 11 months ago

d1-orm v0.9.2

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

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.

0.9.2

11 months ago

0.9.1

12 months ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.2

3 years ago

0.5.4

3 years ago

0.7.1

3 years ago

0.5.3

3 years ago

0.5.5

3 years ago

0.7.0

3 years ago

0.5.2

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.5.0

3 years ago

0.3.2

3 years ago

0.2.3

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.2.2

3 years ago

0.1.3

3 years ago

0.3.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago