(feat) generate zod schemas from kysely-codegen#96
(feat) generate zod schemas from kysely-codegen#96benjaminstrasser wants to merge 1 commit intomainfrom
Conversation
Signed-off-by: Benjamin Strasser <bp.strasser@gmail.com>
7fbc960 to
f1acd78
Compare
|
I think we can treat the DB as an internal component. We can ensure data integrity through testing. I'll reconsider my decision when we release the project and hit over 1k stars on GitHub. :) |
|
In general this is not a bad idea. However, the main points of validation should be on the client and when data is passed to our internal API (if there is any). In many cases, the data model for passing data to service layer in order to be persisted differs from the actual DB schema. Therefore, I do not really see the big advantage of this generation. |
This pull request explores the feasibility of using Zod schemas as the foundation for our database type definitions. The primary motivation behind this approach is to leverage the numerous benefits that Zod offers for type validation and type safety. While this PR is very much a draft and not up to our usual code quality standards, it serves as a proof of concept and a starting point for discussion. I was pretty much just interested if it works.
This would allow us to see the values returned from our db to be what they are - potentially unsafe. This is especially true as kysely does not validate what is returned from our database, but very much suggests that the values conform to our types. This was briefly discussed with @jjnp.