我遇到了一个问题,我需要通过用户名和电子邮件检查用户是否存在,因为这两个都是数据库中唯一的字段,但我得到了一个错误。
Argument where of type UserWhereUniqueInput needs exactly one argument, but you provided username and email. Please choose one.
那么,有没有办法只执行这个查询一次呢?而不是像下面这样分别为每个人运行一个
const user = await prisma.user.findUnique({
where: {
username,
email,
},
});
而不是像这样
const user = await prisma.user.findUnique({
where: {
username,
},
});
const user = await prisma.user.findUnique({
where: {
email,
},
});
发布于 2021-02-25 11:06:47
我不完全确定,但prisma返回一个JS对象...因此,这样的查询可能会起作用:
const query = await prisma.user.findUnique({
where: {
user: user.username
},
select: {
user: true,
email: true
}
});
我相信这应该是可行的,但它仍然只找到一个唯一的。我不确定为什么你会选择用户+电子邮件作为两个唯一的,因为我会假设一个是与另一个捆绑在一起的。
如果我的解决方案不起作用,我会在这里寻找进一步的答案:
https://www.prisma.io/docs/concepts/components/prisma-client/crud#findfirst
https://stackoverflow.com/questions/65998680
复制相似问题