简体   繁体   English

如何使用Typescript在prisma的数组中找到所有拥有电子邮件的用户?

[英]How to find all users that have emails in an array in prisma using Typescript?

Hi sorry for the confusing question.嗨,很抱歉这个令人困惑的问题。 Basically, I want to find all the users that have emails that are included in the array.基本上,我想找到所有拥有包含在数组中的电子邮件的用户。

For example I have an array:例如我有一个数组:

const arr = ['test@gmail.com', 'test2@gmail.com']

and I have my model我有我的模型

model User {
  id                Int
  username          String
  name              String
  email             String
}

I want to do something like我想做类似的事情

const data = await prisma.user.findMany({
     where : {
          email: in arr
    },
     select : {
         id: true
    }
});

I have been trying to find a workaround for this for the longest time.长期以来,我一直试图为此找到解决方法。

This is the syntax for the in operator in Prisma.这是 Prisma 中in运算符的语法。

const arr = ['test@gmail.com', 'test2@gmail.com']

const data = await prisma.user.findMany({
     where : {
          email: {in: arr}
    },
     select : {
         id: true
    }
});

You can read more in the Prima Client Reference in the docs.您可以在文档中的Prima Client Reference中阅读更多内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM