Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

(feat) generate zod schemas from kysely-codegen#96

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
benjaminstrasser wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromgen-zod-schemas

Conversation

@benjaminstrasser
Copy link
Member

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.

@benjaminstrasserbenjaminstrasser marked this pull request as draftJune 14, 2024 14:02
Signed-off-by: Benjamin Strasser <bp.strasser@gmail.com>
@sjaghori
Copy link
Collaborator

sjaghori commentedJun 15, 2024
edited
Loading

I think we can treat the DB as an internal component. We can ensure data integrity through testing.
I really like the idea of validation with Zod because it's convenient and effective. However, I suggest we continue validating the endpoints (client-to-server communication) and not the server-to-database communication, as it's an additional step in the process of creating a simple database query.
Another point against validating server <-> database communication is the runtime overhead (we want to be blazingly fast).

I'll reconsider my decision when we release the project and hit over 1k stars on GitHub. :)

@mledl
Copy link
Contributor

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.
I really see a big advantage when when creating service layer and client side schemas and infer models from them.

sjaghori reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mledlmledlAwaiting requested review from mledlmledl is a code owner

@jjnpjjnpAwaiting requested review from jjnpjjnp will be requested when the pull request is marked ready for reviewjjnp is a code owner

@sjaghorisjaghoriAwaiting requested review from sjaghorisjaghori will be requested when the pull request is marked ready for reviewsjaghori is a code owner

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@benjaminstrasser@sjaghori@mledl

[8]ページ先頭

©2009-2025 Movatter.jp