select and alter columns with drizzle-zod

Hi, I want to create validation schema for update patch request. Not sure how it should be done. I want to (based on drizzle schema) select which field is updatable and mark everyfield as optional. I tried:

const requestSchema = createDocumentSublineSchema.pick({
quantityInBaseUnit: true,
});

const updateDocumentSublineSchema = createInsertSchema(documentSubline, {
quantityInBaseUnit: (schema) => schema.quantityInBaseUnit.optional(),
});

const requestSchema = createDocumentSublineSchema.pick({
quantityInBaseUnit: true,
});

const updateDocumentSublineSchema = createInsertSchema(documentSubline, {
quantityInBaseUnit: (schema) => schema.quantityInBaseUnit.optional(),
});
this does not work, I must be missing something
2 Replies
tzezar
tzezar10mo ago
I mean, the first one successfully pick desired columns, but I am not sure how to alter them, to make them optional for example
Angelelz
Angelelz10mo ago
I think there might be a refine or transform method availble in the requestSchema You might want to check the zod docs
Want results from more Discord servers?
Add your server