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 request: Third-party generator support #17

Open
Cmacu opened this issue Feb 9, 2023 · 2 comments
Open

Feature request: Third-party generator support #17

Cmacu opened this issue Feb 9, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@Cmacu
Copy link

Cmacu commented Feb 9, 2023

Inspired by prisma generator feature. I find it very useful for generating json/types/schemas/validators/trpc/etc. The idea is to have a plugin type function that has access to the underlying orm schema/types with the ability to automatically generate and output code based on that.

Use cases include generating custom CRUD types, various API schema/routes patterns (trpc, openAPI, graphQL), non-zod validators, running complex multi-schema migrations, etc

I guess the main challenge is the entry point fur such function. Prisma includes/requires a convenient generation step for that purpose. In the case of orchid-orm this could be part of the connection configuration and can be conditionally (necessary for production builds) triggered during initialization. The user than installs the package which includes predifined initialization function accepting the schema and handles the rest. Bonus points for compatibility with Prisma generators (not sure how feasible that is).

In terms of syntax it could look like something like this:

orchidORM({
  // databaseURL has the following format:
  // postgres://user:password@localhost:5432/dbname
  // 
  // ssl option can be specified as a parameter:
  // postgres://user:password@localhost:5432/dbname?ssl=true
  databaseURL: process.env.DATABASE_URL,

  // ssl can also be specified as an option:
  ssl: true,
  generators: [
    {
       name: 'orchid-orm-trpc-generator',
       config: { ... },
       enabled: process.env.MODE === 'development',
    }
  ]
  
  log: true, // option for logging, false by default
  autoPreparedStatements: true, // see in query builder setup docs, false by default
  noPrimaryKey: 'ignore', // see in query builder setup docs, 'error' by default
}, {
  user: UserTable,
  message: MessageTable,
})

PS: Let me know, if I am missing something. I have a couple of more features in mind that I shared on reddit. I can follow the above template to create issues for them. OrchidORM looks really promising, I would love to also help with the project, so I will stay in touch once I free up my schedule a bit.

@romeerez
Copy link
Owner

romeerez commented Feb 9, 2023

This sounds very useful and interesting!
I see Prisma has a lot of generators for various frameworks. tRPC is a good starting point.
Making it compatible with Prisma would be a big win because all Prisma generators would work with Orchid.

So many ideas and everything to do, it would be awesome if other people could help.
And of course, create more issues if you have more ideas, sooner or later all will be done.

I'm going to write a contribution doc soon.

@romeerez romeerez added the enhancement New feature or request label Feb 11, 2023
@romeerez
Copy link
Owner

I didn't use such generators for Prisma before, so had a little naive hope that they will generate code that only depends on a framework, but of course, in reality, generated code highly depends on Prisma.

Use cases include generating custom CRUD types, various API schema/routes patterns (trpc, openAPI, graphQL), non-zod validators, running complex multi-schema migrations, etc

Cannot do everything, but I'll start with on trpc, and sooner or later on a generator for some GraphQL server.

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