Interactions-as-a-Service / d1-orm

A simple, strictly typed ORM, to assist you in using Cloudflare's D1 product
https://docs.interactions.rest/d1-orm/
Apache License 2.0
161 stars 10 forks source link

Inferred types! #44

Closed Skye-31 closed 2 years ago

Skye-31 commented 2 years ago

Models no longer require you to specify a definition when you create them. Instead, you can just pass in an object and the model will infer the types for you. See the following example:

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

- const users = new Model<User>(
+ const users = new Model(
    {
        tableName: "users",
        D1Orm: MyD1OrmInstance,
    },
    {
        name: {
                     type: DataTypes.TEXT,
                },
        age: {
                    type: DataTypes.INTEGER,
                }
    }
);

+ type User = Infer<typeof users>;
- type User = {
-   name: string,
-   age: number
- }
changeset-bot[bot] commented 2 years ago

🦋 Changeset detected

Latest commit: d9f84759e294df47d82e1e9a0158e2ac8eedcf22

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------ | ----- | | d1-orm | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

cloudflare-workers-and-pages[bot] commented 2 years ago

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: d9f8475
Status: âœ…  Deploy successful!
Preview URL: https://d0cdac9b.d1-orm.pages.dev
Branch Preview URL: https://feat-inferred-types.d1-orm.pages.dev

View logs