Filtering, Sorting, and Pagination
Prisma Client mirrors the WHERE, ORDER BY, and LIMIT/OFFSET you already know from SQL, as options on findMany.
const topPosts = await prisma.post.findMany({
where: {
published: true,
title: { contains: 'Prisma' },
},
orderBy: { createdAt: 'desc' },
skip: 0,
take: 10,
});
Mapping to SQL
| Prisma option | SQL equivalent |
|---|---|
where: { published: true } | WHERE published = true |
orderBy: { createdAt: 'desc' } | ORDER BY created_at DESC |
take: 10 | LIMIT 10 |
skip: 20 | OFFSET 20 |
skip + take together give you pagination, page 3 of 10-per-page results is skip: 20, take: 10.