Giter VIP home page Giter VIP logo

d1-orm's Introduction

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.

d1-orm's People

Contributors

skye-31 avatar github-actions[bot] avatar dannyball710 avatar david8z avatar kingmesal avatar nikukyugamer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.