最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PRISMA, WHERE-contain clause for array of enums - Stack Overflow

programmeradmin1浏览0评论

So here's my prisma schema:

model User {
  id                         String    @id @default(uuid())
  email                      String    @unique
  mailing_address            String
  password                   String
  verification_token         String?
  verification_token_expires DateTime?
  reset_password_token       String?
  reset_password_expires     DateTime?
  name                       String?
  roles                      Role[]
  last_auth_change           DateTime  @default(now())
}

enum Role {
  SUPER_ADMIN
  ADMIN
  USER
  EMAIL_VERIFIED
  UNVERIFIED
}

and i want to notify all the super admins when a user verify his email

the sql query for it is : 'SELECT "id", "mailing_address", "roles" FROM "User" WHERE "roles" @> ARRAY[\'SUPER_ADMIN\']::"Role"[] ;' but i couldn't figure out how to do it with PRISMA , because when i want to write something in the where clause for roles in Prisma, the only option is equal

So here's my prisma schema:

model User {
  id                         String    @id @default(uuid())
  email                      String    @unique
  mailing_address            String
  password                   String
  verification_token         String?
  verification_token_expires DateTime?
  reset_password_token       String?
  reset_password_expires     DateTime?
  name                       String?
  roles                      Role[]
  last_auth_change           DateTime  @default(now())
}

enum Role {
  SUPER_ADMIN
  ADMIN
  USER
  EMAIL_VERIFIED
  UNVERIFIED
}

and i want to notify all the super admins when a user verify his email

the sql query for it is : 'SELECT "id", "mailing_address", "roles" FROM "User" WHERE "roles" @> ARRAY[\'SUPER_ADMIN\']::"Role"[] ;' but i couldn't figure out how to do it with PRISMA , because when i want to write something in the where clause for roles in Prisma, the only option is equal

Share Improve this question asked Oct 27, 2020 at 10:03 Sayyed Alireza Rezaei AslSayyed Alireza Rezaei Asl 3391 gold badge3 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Currently there's an open request here so equals is the only available argument.

As a workaround, you can use a raw query as above via prisma.$queryRaw.

发布评论

评论列表(0)

  1. 暂无评论