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

Add createUpdateSchema to drizzle-zod #503

Closed
dankochetov opened this issue Apr 23, 2023 · 4 comments
Closed

Add createUpdateSchema to drizzle-zod #503

dankochetov opened this issue Apr 23, 2023 · 4 comments
Labels
drizzle/zod enhancement New feature or request

Comments

@dankochetov
Copy link
Contributor

No description provided.

@dankochetov dankochetov converted this from a draft issue Apr 23, 2023
@dankochetov dankochetov added the enhancement New feature or request label Apr 23, 2023
@tacomanator
Copy link
Contributor

I think the current createInsertSchema with partial() works pretty well, but causes confusion because of the name. Having a shortcut for createUpdateSchema is not not useful, ...but as a point of consideration have you thought about renaming the current createInsertSchema to something universal like createMutationSchema or createMutateSchema?

@tylerzey
Copy link

tylerzey commented Jun 2, 2023

+1

@gburtini
Copy link

gburtini commented Apr 23, 2024

I think the current createInsertSchema with partial() works pretty well.

Some sort of selection criteria (typically a key, like ID) seems like it would have to be mandatory for update, but should generally not be present for insert.

Here's an example of approximately what I've landed on for CRUD, but you can imagine why you might want to separate that need and use the selection schema for an update criteria.

const apiMutateUser = createInsertSchema(users, refine).omit({
  created_at: true,
  updated_at: true,
});
export const apiInsertUser = apiMutateUser.omit({ id: true });
export const apiUpdateUser = apiMutateUser.partial().required({ id: true });
export const apiDeleteUser = apiMutateUser.pick({ id: true });
export const apiSelectUser = createSelectSchema(users, refine)
  .pick(selectableFields)
  .partial();

@AndriiSherman
Copy link
Member

This one was fixed in the latest for all validator packages
drizzle-zod@0.6.0
drizzle-valibot@0.3.0
drizzle-typebox@0.2.0

@github-project-automation github-project-automation bot moved this from Backlog to Done in Public Roadmap Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drizzle/zod enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

6 participants