-
-
Notifications
You must be signed in to change notification settings - Fork 864
[BUG]: pgEnum enumValues
does not return as literal value anymore
#358
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
Comments
Yes, this was intentional, but seems like it was implemented incorrectly. As a quick workaround, you can extract your values tuple into a variable and pass it both to |
Also, you can use |
Yes I have looked into that. The problem I have with that is that I still need to refine the validation and then add a transformation for sanitization etc. so I still have to do the same kind of work. Example without // Only the fields that can be changed after insertion
const memberInput = z.object({
userId: z.string().cuid2(),
firstName: z.string().max(255),
middleName: z.string().max(255).nullable(),
insertion: z.string().max(255).nullable(),
lastName: z.string().max(255),
sex: z.enum(["female", "male", "other"]),
dateOfBirth: z.date().max(new Date()),
});
export const createMemberSchema = memberInput.transform((member) => ({
id: createId(),
userId: member.userId,
firstName: member.firstName.trim(),
middleName: member.middleName?.trim() || null,
insertion: member.insertion?.trim() || null,
lastName: member.lastName.trim(),
sex: member.sex,
dateOfBirth: member.dateOfBirth,
createdAt: new Date(),
updatedAt: new Date(),
}));
export const updateMemberSchema = memberInput.partial().transform((member) => ({
userId: member.userId,
firstName: member.firstName?.trim(),
middleName: member.middleName?.trim(),
insertion: member.insertion?.trim(),
lastName: member.lastName?.trim(),
sex: member.sex,
dateOfBirth: member.dateOfBirth,
updatedAt: new Date(),
})); Example with const memberInsertSchema = createInsertSchema(members, {
userId: z.string().cuid2(),
}).transform((member) => ({
id: createId(),
userId: member.userId,
firstName: member.firstName.trim(),
middleName: member.middleName?.trim() || null,
insertion: member.insertion?.trim() || null,
lastName: member.lastName.trim(),
sex: member.sex,
dateOfBirth: member.dateOfBirth,
createdAt: new Date(),
updatedAt: new Date(),
}));
const memberUpdateSchema = createInsertSchema(members, {
userId: z.string().cuid2(),
})
.omit({
id: true,
createdAt: true,
updatedAt: true,
})
.partial()
.transform((member) => ({
userId: member.userId,
firstName: member.firstName?.trim(),
middleName: member.middleName?.trim(),
insertion: member.insertion?.trim(),
lastName: member.lastName?.trim(),
sex: member.sex,
dateOfBirth: member.dateOfBirth,
updatedAt: new Date(),
})); Of course with What would be amazing is to be able to create database tables from a zod schema. If you think this is possible and something for this project, I might be able to take a look at it but I've never really contributed to projects like this. If you can point me to where this can be implemented, I might try something. |
- 🐛 Fixed referencing the selected aliased field in the same query - 🐛 Fixed decimal column data type in MySQL - 🐛 Fixed mode autocompletion for integer column in SQLite - 🐛 Fixed extra parentheses in the generated SQL for the `IN` operator (#382) - 🐛 Fixed regression in `pgEnum.enumValues` type (#358) - 🎉 Allowed readonly arrays to be passed to `pgEnum`
Fixed in |
Hello, I'm on 0.38.3 and this isn't fixed. Fields that have pgEnum type return a typescript string, why do they not return the enum values? |
What version of
drizzle-orm
are you using?0.23.4
Describe the Bug
The
z.enum()
requires a literal value andpgEnum.enumValues
used to return as type["female", "male", "other"]
.Now the type is just a
string[]
.Is this intentional and do I need to change the way I do it?
The text was updated successfully, but these errors were encountered: