sinclairzx81 / typebox

Json Schema Type Builder with Static Type Resolution for TypeScript
Other
4.56k stars 148 forks source link

Trying to do codegen from Drizzle schemas #903

Closed StevenStavrakis closed 3 weeks ago

StevenStavrakis commented 3 weeks ago

To avoid importing my database schema code into the front end, I am trying to create a code-gen tool that generates TypeBox schemas and types from my drizzle schema.

The codegen package looked like it was going to be exactly what I was looking for, but it seems to take a string instead of a type. I'm not exactly sure how I would go about making this work, since I am not writing out my types but instead getting them from the drizzle-typebox utility.

sinclairzx81 commented 3 weeks ago

@StevenStavrakis Hi,

This issue is probably best posted on the typebox-codegen project. This said, TypeBox doesn't actually provide Drizzle > Typebox conversion tooling, only TypeScript > TypeBox conversion tools (so unfortunately wouldn't be applicable to the typebox-codegen project either).

I think if approaching explicit TB code generation from Drizzle (as a CLI tool), you're probably going to have to reflect on Drizzle structures and generate that way. I am not sure if existing tools exist for this, but I think it should be possible as Drizzle can already generate TypeBox types dynamically (so all the metadata you need should be inside the Drizzle types), if going code generation, you would have to do the same (but generating strings / code instead)

Will close up this issue for now as it's somewhat out of scope for TypeBox. But if you wanted to start a project that does such code generation, I would be happy to help with the conversions if you need.

All the best S