Skip to content

drizzle enums #1914

Answered by ap0nia
cehenriques asked this question in Q&A
Feb 21, 2024 · 7 comments · 17 replies
Discussion options

You must be logged in to vote
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))

Replies: 7 comments 17 replies

Comment options

You must be logged in to vote
3 replies
@NielsCodes
Comment options

@nathanchapman
Comment options

@RobSchilderr
Comment options

Comment options

You must be logged in to vote
2 replies
@sisimomo
Comment options

@ubinatus
Comment options

Comment options

You must be logged in to vote
3 replies
@Weixuanf
Comment options

@aprilmintacpineda
Comment options

@ap0nia
Comment options

Answer selected by cehenriques
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Weixuanf
Comment options

Comment options

You must be logged in to vote
8 replies
@NielsCodes
Comment options

@aprilmintacpineda
Comment options

@aprilmintacpineda
Comment options

@aprilmintacpineda
Comment options

@incompletude
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet