Skip to content

Instantly share code, notes, and snippets.

@by-nari
Created December 29, 2024 11:12
Show Gist options
  • Save by-nari/d72b4f146cbb49bcff71da9b8dd57d93 to your computer and use it in GitHub Desktop.
Save by-nari/d72b4f146cbb49bcff71da9b8dd57d93 to your computer and use it in GitHub Desktop.
TypeScript enum to Drizzle's pgEnum
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