Node.js, Prisma & PostgreSQL

Lesson 6 of 12

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 optionSQL equivalent
where: { published: true }WHERE published = true
orderBy: { createdAt: 'desc' }ORDER BY created_at DESC
take: 10LIMIT 10
skip: 20OFFSET 20

skip + take together give you pagination, page 3 of 10-per-page results is skip: 20, take: 10.

📝 Filtering & Pagination Quiz

Passing score: 70%
  1. 1.Which Prisma option is equivalent to SQL's LIMIT?

  2. 2.The ____ option in findMany is equivalent to SQL's OFFSET.

  3. 3.Prisma's orderBy option maps directly to SQL's ORDER BY clause.