typeorm find with limit 1

typeorm find with limit

// the FindManyOptions's limit option is called 'take'
repository.find( { 
  order: { created: "DESC" }, // order results
  take: 1 // limit 1
} )

Here is what the above code is Doing:
1. We’re using the find() method to find all the records in the database.
2. We’re using the order option to order the results by the created column in descending order.
3. We’re using the take option to limit the results to 1.

The find() method returns a Promise, so we can use the then() method to get the results.

Similar Posts