L
L
loljapanes2022-03-24 23:50:41
ORM
loljapanes, 2022-03-24 23:50:41

How to sort using typeorm?

The database contains the following data:

[
  {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},
]


now i need to make a query with typeorm to get the data but i need to sort it according to the amount field and only get 3 users, i.e. i have to get this:
[
      {id: 5, username: "aas", amount: 10},
      {id: 1, username: "test", amount: 2},
      {id: 3, username: "hello", amount: 1},
    ]

how to make this request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rag'n' Code Man, 2022-03-25
@iDmitriyWinX

.orderBy()and.limit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question