Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/interactions-as-a-service/d1-orm
A simple, strictly typed ORM, to assist you in using Cloudflare's D1 product
https://github.com/interactions-as-a-service/d1-orm
cloudflare cloudflare-d1 cloudflare-workers d1 orm typescript workers
Last synced: 3 days ago
JSON representation
A simple, strictly typed ORM, to assist you in using Cloudflare's D1 product
- Host: GitHub
- URL: https://github.com/interactions-as-a-service/d1-orm
- Owner: Interactions-as-a-Service
- License: apache-2.0
- Created: 2022-08-28T20:50:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-01T12:55:56.000Z (4 months ago)
- Last Synced: 2024-12-23T00:03:44.601Z (3 days ago)
- Topics: cloudflare, cloudflare-d1, cloudflare-workers, d1, orm, typescript, workers
- Language: TypeScript
- Homepage: https://docs.interactions.rest/d1-orm/
- Size: 504 KB
- Stars: 163
- Watchers: 5
- Forks: 9
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# D1-Orm
✨ A simple, strictly typed ORM, to assist you in using [Cloudflare's SQLite Database](https://developers.cloudflare.com/d1)
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](https://npmjs.com/package/d1-orm)
```sh
npm install d1-orm
```## Usage
This package is recommended to be used with [@cloudflare/workers-types](https://github.com/cloudflare/workers-types) 4+.
```ts
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;await users.First({
where: {
id: 1,
},
});
// Promise
},
};
```