Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 679 Bytes

grab-a-limited-set-of-records.md

File metadata and controls

27 lines (20 loc) · 679 Bytes

Grab A Limited Set Of Records

Let's say you want to grab some records from a table, but you want to limit the result set to 10 records.

You can do that with the take option.

const posts = await prisma.post.findMany({
  take: 10
});

It is generally good to not assume anything about the ordering. Instead, you should be explicit about the order you want, so let's include an orderBy as well.

const posts = await prisma.post.findMany({
  take: 10,
  orderBy: { createdAt: "asc" },
});

This will return the 10 most recently created posts.

source