Labsco
prisma logo

prisma-client-api-query-options

✓ Official8

by prisma · part of prisma/cursor-plugin

Query Options. Reference when using this Prisma feature.

🔥🔥🔥✓ VerifiedFreeQuick setup
🧩 One of 7 skills in the prisma/cursor-plugin package — works on its own, and pairs well with its siblings.

Query Options. Reference when using this Prisma feature.

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates — shown here so you can audit it before installing. You don't need to read it to use the skill.

by prisma

Query Options. Reference when using this Prisma feature. npx skills add https://github.com/prisma/cursor-plugin --skill prisma-client-api-query-options Download ZIPGitHub8

Query Options

Options for controlling query behavior.

select

Choose specific fields to return:

Copy & paste — that's it
const user = await prisma.user.findUnique({
 where: { id: 1 },
 select: {
 id: true,
 name: true,
 email: true,
 // password: false (excluded by not including)
 }
})
// Returns: { id: 1, name: 'Alice', email: '[email protected]' }

Select relations

Copy & paste — that's it
const user = await prisma.user.findUnique({
 where: { id: 1 },
 select: {
 name: true,
 posts: {
 select: {
 title: true,
 published: true
 }
 }
 }
})

Select with include inside

Copy & paste — that's it
const user = await prisma.user.findMany({
 select: {
 name: true,
 posts: {
 include: {
 comments: true
 }
 }
 }
})

Select relation count

Copy & paste — that's it
const users = await prisma.user.findMany({
 select: {
 name: true,
 _count: {
 select: { posts: true }
 }
 }
})
// Returns: { name: 'Alice', _count: { posts: 5 } }

include

Include related records:

Copy & paste — that's it
const user = await prisma.user.findUnique({
 where: { id: 1 },
 include: {
 posts: true,
 profile: true
 }
})

Filtered include

Copy & paste — that's it
const user = await prisma.user.findUnique({
 where: { id: 1 },
 include: {
 posts: {
 where: { published: true },
 orderBy: { createdAt: 'desc' },
 take: 5
 }
 }
})

Nested include

Copy & paste — that's it
const user = await prisma.user.findUnique({
 where: { id: 1 },
 include: {
 posts: {
 include: {
 comments: {
 include: {
 author: true
 }
 }
 }
 }
 }
})

Include relation count

Copy & paste — that's it
const users = await prisma.user.findMany({
 include: {
 _count: {
 select: { posts: true, followers: true }
 }
 }
})

omit

Exclude specific fields:

Copy & paste — that's it
const user = await prisma.user.findUnique({
 where: { id: 1 },
 omit: {
 password: true
 }
})
// Returns all fields except password

Omit in relations

Copy & paste — that's it
const users = await prisma.user.findMany({
 omit: { password: true },
 include: {
 posts: {
 omit: { content: true }
 }
 }
})

Note: Cannot use select and omit together.

where

Filter records:

Copy & paste — that's it
const users = await prisma.user.findMany({
 where: {
 email: { contains: '@prisma.io' },
 role: 'ADMIN'
 }
})

See filters.md for detailed filter operators.

orderBy

Sort results:

Copy & paste — that's it
// Single field
const users = await prisma.user.findMany({
 orderBy: { name: 'asc' }
})

// Multiple fields
const users = await prisma.user.findMany({
 orderBy: [
 { role: 'desc' },
 { name: 'asc' }
 ]
})

Order by relation

Copy & paste — that's it
const users = await prisma.user.findMany({
 orderBy: {
 posts: { _count: 'desc' }
 }
})

Null handling

Copy & paste — that's it
const users = await prisma.user.findMany({
 orderBy: {
 name: { sort: 'asc', nulls: 'last' }
 }
})

take & skip

Pagination:

Copy & paste — that's it
// First page
const users = await prisma.user.findMany({
 take: 10,
 skip: 0
})

// Second page
const users = await prisma.user.findMany({
 take: 10,
 skip: 10
})

Negative take (reverse)

Copy & paste — that's it
const lastUsers = await prisma.user.findMany({
 take: -10,
 orderBy: { id: 'asc' }
})
// Returns last 10 users

cursor

Cursor-based pagination:

Copy & paste — that's it
// First page
const firstPage = await prisma.user.findMany({
 take: 10,
 orderBy: { id: 'asc' }
})

// Next page using cursor
const nextPage = await prisma.user.findMany({
 take: 10,
 skip: 1, // Skip the cursor record
 cursor: { id: firstPage[firstPage.length - 1].id },
 orderBy: { id: 'asc' }
})

distinct

Return unique values:

Copy & paste — that's it
const cities = await prisma.user.findMany({
 distinct: ['city'],
 select: { city: true }
})

Multiple distinct fields

Copy & paste — that's it
const locations = await prisma.user.findMany({
 distinct: ['city', 'country']
})