/prisma-6:optimizing-query-selectionfrom prisma-6
Optimize queries by selecting only required fields and avoiding N+1 problems. Use when writing queries with relations or large result sets.
Ships in prisma-6. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Optimize Prisma 6 queries through selective field loading and relation batching to prevent N+1 problems and reduce data transfer.
include (prototyping, most fields) vs. select (production, API responses, performance-critical)select for precise control, nest relations with select, use _count instead of loading all records, limit relation results with takewhere clauses, orderBy fields, composite indexes for filtered relationsProblem: Fetching entire models wastes bandwidth and memory
const users = await prisma.user.findMany()
Solution: Use select to fetch only needed fields
const users = await prisma.user.findMany({
select: {
id: true,
email: true,
name: true,
},
})
Performance Impact:
Include: Adds relations to full model
const user = await prisma.user.findUnique({
where: { id: 1 },
include: {
posts: true,
profile: true,
},
})
Select: Precise control over all fields
const user = await prisma.user.findUnique({
where: { id: 1 },
select: {
id: true,
email: true,
posts: {
select: {
id: true,
title: true,
published: true,
},
},
profile: {
select: {
bio: true,
avatar: true,
},
},
},
})
When to Use:
include: Quick prototyping, need most fieldsselect: Production code, API responses, performance-critical pathsN+1 Problem: Separate query for each relation
const posts = await prisma.post.findMany()
for (const post of posts) {
const author = await prisma.user.findUnique({
where: { id: post.authorId },
})
}
Solution: Use include or select with relations
const posts = await prisma.post.findMany({
include: {
author: true,
},
})
Better: Select only needed author fields
const posts = await prisma.post.findMany({
select: {
id: true,
title: true,
content: true,
author: {
select: {
id: true,
name: true,
email: true,
},
},
},
})
Problem: Loading all relations just to count them
const user = await prisma.user.findUnique({
where: { id: 1 },
include: {
posts: true,
},
})
const postCount = user.posts.length
Solution: Use _count for efficient aggregation
const user = await prisma.user.findUnique({
where: { id: 1 },
select: {
id: true,
name: true,
_count: {
select: {
posts: true,
comments: true,
},
},
},
})
Result:
{
id: 1,
name: "Alice",
_count: {
posts: 42,
comments: 128
}
}
## Quick Reference
const optimized = await prisma.model.findMany({
where: {},
select: {
field1: true,
field2: true,
relation: {
select: {
field: true,
},
take: 10,
},
_count: {
select: {
relation: true,
},
},
},
orderBy: { field: 'desc' },
take: 20,
skip: 0,
})
select for all production queriesinclude only for prototyping_count for counting relationsMUST:
select for all API responses_count for relation countsSHOULD:
takeNEVER:
include in production without field selectionFor detailed patterns and examples, see:
What SKILL.md sets; muted values are Claude Code's defaults
19 skills in this plugin
/configuring-connection-poolsConfigure connection pool sizing for optimal performance. Use when configuring DATABASE_URL or deploying to production./configuring-serverless-clientsConfigure PrismaClient for serverless (Next.js, Lambda, Vercel) with connection_limit=1 and global singleton pattern./configuring-transaction-isolationConfigure transaction isolation levels to prevent race conditions and handle concurrent access. Use when dealing with concurrent updates, financial operations, inventory management, or when users mention race conditions, dirty reads, phantom reads, or concurrent modifications.npx claudepluginhub djankies/claude-configs --plugin prisma-6