Labsco
prisma logo

prisma-client-api-model-queries

✓ Official8

by prisma · part of prisma/cursor-plugin

Model Queries. 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.

Model Queries. 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

Model Queries. Reference when using this Prisma feature. npx skills add https://github.com/prisma/cursor-plugin --skill prisma-client-api-model-queries Download ZIPGitHub8

Model Queries

CRUD operations for your Prisma models.

Read Operations

findUnique

Find a single record by unique field:

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

const user = await prisma.user.findUnique({
 where: { email: '[email protected]' }
})

With composite unique key

Copy & paste — that's it
// Model with @@unique([firstName, lastName])
const user = await prisma.user.findUnique({
 where: {
 firstName_lastName: {
 firstName: 'Alice',
 lastName: 'Smith'
 }
 }
})

findUniqueOrThrow

Same as findUnique but throws if not found:

Copy & paste — that's it
const user = await prisma.user.findUniqueOrThrow({
 where: { id: 1 }
})
// Throws PrismaClientKnownRequestError if not found

findFirst

Find first matching record:

Copy & paste — that's it
const user = await prisma.user.findFirst({
 where: { role: 'ADMIN' },
 orderBy: { createdAt: 'desc' }
})

findFirstOrThrow

Copy & paste — that's it
const user = await prisma.user.findFirstOrThrow({
 where: { role: 'ADMIN' }
})

findMany

Find multiple records:

Copy & paste — that's it
const users = await prisma.user.findMany({
 where: { role: 'USER' },
 orderBy: { name: 'asc' },
 take: 10,
 skip: 0
})

Create Operations

create

Create a single record:

Copy & paste — that's it
const user = await prisma.user.create({
 data: {
 email: '[email protected]',
 name: 'Alice'
 }
})

With relations

Copy & paste — that's it
const user = await prisma.user.create({
 data: {
 email: '[email protected]',
 posts: {
 create: [
 { title: 'First Post' },
 { title: 'Second Post' }
 ]
 }
 },
 include: { posts: true }
})

createMany

Create multiple records:

Copy & paste — that's it
const result = await prisma.user.createMany({
 data: [
 { email: '[email protected]', name: 'Alice' },
 { email: '[email protected]', name: 'Bob' }
 ],
 skipDuplicates: true // Skip records with duplicate unique fields
})
// Returns { count: 2 }

createManyAndReturn

Create multiple and return them:

Copy & paste — that's it
const users = await prisma.user.createManyAndReturn({
 data: [
 { email: '[email protected]', name: 'Alice' },
 { email: '[email protected]', name: 'Bob' }
 ]
})
// Returns array of created users

Update Operations

update

Update a single record:

Copy & paste — that's it
const user = await prisma.user.update({
 where: { id: 1 },
 data: { name: 'Alice Smith' }
})

Atomic operations

Copy & paste — that's it
const post = await prisma.post.update({
 where: { id: 1 },
 data: {
 views: { increment: 1 },
 likes: { decrement: 1 },
 score: { multiply: 2 },
 rating: { divide: 2 },
 version: { set: 5 }
 }
})

updateMany

Update multiple records:

Copy & paste — that's it
const result = await prisma.user.updateMany({
 where: { role: 'USER' },
 data: { verified: true }
})
// Returns { count: 42 }

updateManyAndReturn

Copy & paste — that's it
const users = await prisma.user.updateManyAndReturn({
 where: { role: 'USER' },
 data: { verified: true }
})
// Returns array of updated users

upsert

Update or create:

Copy & paste — that's it
const user = await prisma.user.upsert({
 where: { email: '[email protected]' },
 update: { name: 'Alice Smith' },
 create: { email: '[email protected]', name: 'Alice' }
})

Delete Operations

delete

Delete a single record:

Copy & paste — that's it
const user = await prisma.user.delete({
 where: { id: 1 }
})
// Returns deleted record

deleteMany

Delete multiple records:

Copy & paste — that's it
const result = await prisma.user.deleteMany({
 where: { role: 'GUEST' }
})
// Returns { count: 5 }

// Delete all
const result = await prisma.user.deleteMany({})

Aggregation Operations

count

Copy & paste — that's it
const count = await prisma.user.count({
 where: { role: 'ADMIN' }
})

aggregate

Copy & paste — that's it
const result = await prisma.post.aggregate({
 _avg: { views: true },
 _sum: { views: true },
 _min: { views: true },
 _max: { views: true },
 _count: { _all: true }
})

groupBy

Copy & paste — that's it
const groups = await prisma.user.groupBy({
 by: ['country'],
 _count: { _all: true },
 _avg: { age: true },
 having: {
 age: { _avg: { gt: 30 } }
 }
})

Return Types

Method Returns findUnique Record | null findUniqueOrThrow Record (throws if not found) findFirst Record | null findFirstOrThrow Record (throws if not found) findMany Record[] create Record createMany { count: number } createManyAndReturn Record[] update Record updateMany { count: number } delete Record deleteMany { count: number } count number aggregate Aggregate result groupBy Group result[]