Add `createUpdateSchema` to drizzle-zod
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?
+1
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();