Custom error messages with drizzle-zod?

Hey there! 👋 Does somebody know how to add custom error messages to a schema created via createInsertSchema? I know I can refine the schema by passing an object as the second argument, but since the error messages are part of the actual type definition, I would be repeating myself like so:

export const users = sqliteTable("users", {
  id: integer("id").primaryKey().notNull()
});

const zodSchema = createInsertSchema(users, {
  id: (schema) => schema.id.number({
    required_error: "Id is required",
    invalid_type_error: "Id must be a number",
});
Was this page helpful?