如何解决棱镜 findUnique 其中只需要一个唯一参数
我遇到了一个问题,我需要通过他的用户名和电子邮件来检查用户是否存在,因为这两个字段都是数据库中的唯一字段,但出现错误。
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,});
解决方法
我不完全确定,但prisma 返回一个JS 对象... 所以也许这样的查询应该有效:
const query = await prisma.user.findUnique({
where: {
user: user.username
},select: {
user: true,email: true
}
});
我相信这应该有效,但它仍然只能找到一个独特的。我不确定为什么您会选择 user + email 作为两者都是唯一的,因为我认为无论如何都会与另一个相关联。
如果我的解决方案不起作用,我会在这里查看进一步的答案:https://www.prisma.io/docs/concepts/components/prisma-client/crud#findfirst
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。