Created
December 29, 2024 11:12
-
-
Save by-nari/d72b4f146cbb49bcff71da9b8dd57d93 to your computer and use it in GitHub Desktop.
TypeScript enum to Drizzle's pgEnum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export enum Role { | |
APPLICANT = 'applicant', | |
TRAINER = 'trainer', | |
ADMIN = 'admin', | |
} | |
export function enumToPgEnum<T extends Record<string, any>>( | |
myEnum: T, | |
): [T[keyof T], ...T[keyof T][]] { | |
return Object.values(myEnum).map((value: any) => `${value}`) as any | |
} | |
export const roleEnum = pgEnum('role', enumToPgEnum(Role)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment