is it possible to get a list of enum values using ...
# orm-help
j
is it possible to get a list of enum values using prisma client?
r
Hey @John Cantrell 👋 You can use
prisma.queryRaw
to get the enum values. Something like this should work for Postgres:
Copy code
await prisma.queryRaw`select unnest(enum_range(null::enum_name))`
j
A similar question was asked in the BLitz Slack, and there I answered:
👍 1
t
The answer is, you don’t need query raw, you can literally just import the enum like so:
schema.prisma
Copy code
enum Tree {
  ARBORVITAE
  YELLOWBIRCH
  BLACKASH
  DOUGLASFIR
  OAK
}
file.ts
Copy code
import { Tree } from '@prisma/client'

console.log(Tree)
logs:
Copy code
{
  ARBORVITAE: 'ARBORVITAE',
  YELLOWBIRCH: 'YELLOWBIRCH',
  BLACKASH: 'BLACKASH',
  DOUGLASFIR: 'DOUGLASFIR',
  OAK: 'OAK'
}