Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Use a schema language abstraction. #2576

Open
jspears opened this issue Jul 2, 2024 · 1 comment
Open

[FEATURE]: Use a schema language abstraction. #2576

jspears opened this issue Jul 2, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jspears
Copy link

jspears commented Jul 2, 2024

Describe what you want

Coming to Drizzle from Prisma, I find I miss having a a succinct schema language to describe and annotate models.

In this end I wrote a PoC Drizz for using TypeSpec to generate drizzle/schema.ts from schema.tsp. Not sure if anybody else would be interested in such a thing, it's fairly complete for Postgres, and at least shows how it could be done. It would pretty easy to write an emitter for MySql, and PSSql.

Advantages of using TypeSpec is it already has IDE support, linter support and an existing extensible grammar. As such one could add their own annotations to a model and generate DB/Rest whatever from a model.

Some examples can be found in the tests

The schema looks like

       @table model User {
          @id id: integer;
          name:string;
        };
        @table model Book {
          @id id: integer;
          name: string;
        };
        @table("books_to_authors") 
        @id("booksToAuthor", #["authorId", "bookId"])
        model BooksToAuthors {
          authorId: integer;
          bookId: integer;
        };

      @table("users") model User {
          @uuid @id id: string; 
          @unique email: string;
          rank: int32;
          @map("cool_score") coolScore: int32;
        };
        @table("blogs") model Blog {
          @uuid @id id: string; 
          @unique name: string;
          posts: Post[];
        };
        @table("posts") model Post {
          @uuid @id id: string; 
          title: string;
          content: string;
          @relation(#{fields:#["blogId"]}) blog: Blog;
        };

Thanks for the great project.

@jspears jspears added the enhancement New feature or request label Jul 2, 2024
@ehsan2003
Copy link

I disagree with this approach since it brings one more level of complexity and another build step to add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants