1

我知道目前Prisma不支持按多个标量字段排序,(请参阅此问题:https ://github.com/prisma/prisma/issues/62 )。但是,我想知道是否有人在不使用 executeRaw 突变(原始SQL )的情况下找到了解决此问题的解决方案,因为我的代码中有很多地方需要按多个字段排序,而我不想在很多地方使用 executeRaw。我将不胜感激任何建议。谢谢!

4

2 回答 2

1

我认为没有解决方案,在我的项目中,我需要随机顺序、递增/递减、聚合......最后使用 raw。

于 2019-04-30T18:23:29.903 回答
0

由于 Prisma 2.4 这应该基本上可以通过在 orderBy 中使用数组来实现:

const users = await prisma.user.findMany({
   select: {
      email: true,
      role: true,
   },
   orderBy: [
      {
         email: 'desc',
      },
      {
         role: 'desc',
      }
   ],
})

在文档中查找更多信息:https ://www.prisma.io/docs/reference/api-reference/prisma-client-reference#sort-user-by-multiple-fields---email-and-role

于 2022-01-31T15:01:32.477 回答