小编rej*_*ejs的帖子

如何用typeor进行排序?

该数据库包含以下数据:

[
  {id: 1, username: "test", amount: 2},
  {id: 2, username: "example", amount: 0},
  {id: 3, username: "hello", amount: 1},
  {id: 4, username: "fsa", amount: 0},
  {id: 5, username: "aas", amount: 10},
]
Run Code Online (Sandbox Code Playgroud)

现在我需要使用 typeorm 查询来检索数据,但我需要根据 amount 字段对其进行排序,并且限制只有 3 个用户,所以我应该得到这个:

 [
      {id: 5, username: "aas", amount: 10},
      {id: 1, username: "test", amount: 2},
      {id: 3, username: "hello", amount: 1},
    ]
Run Code Online (Sandbox Code Playgroud)

如何进行该查询?

node.js typeorm nestjs

1
推荐指数
1
解决办法
7552
查看次数

标签 统计

nestjs ×1

node.js ×1

typeorm ×1