找不到记录时如何获取带有 Prisma2 错误的空数组

How to get an empty array with Prisma2 error when no records found

当数据库中没有记录时,Photon (Prisma2) 会抛出错误,而不是像 Prisma 那样返回空数组。处理这个问题的最佳方法是什么,在没有找到记录时得到一个空数组?我不希望我所有的 Photon 查询都被 try 和 catch 语句包围。

例如:

photon.context.photon.users.findOne({ where: { email } })

报错:

Error in connector: Record does not exist.

根据 github 上的 this and this 个问题,这似乎是一个错误。但是,使用 findMany 而不是 findOne 可能会解决您的问题