n-plus-one-prevention

Eliminate N+1 database queries by enforcing eager loading across ORM frameworks.

13|2|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/yanko-belov/code-craft --skill n-plus-one-prevention
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: n-plus-one-prevention
Source: https://github.com/yanko-belov/code-craft/tree/main/skills/n-plus-one-prevention
Command: npx skills add https://github.com/yanko-belov/code-craft --skill n-plus-one-prevention

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers avoid N+1 database queries by promoting eager loading and efficient data access patterns.

Core Features & Use Cases

  • Eager loading guidance: Learn how to fetch related data in a single query across popular ORMs (e.g., Sequelize, Prisma, TypeORM).
  • Loop optimization: Detect and replace per-item queries inside loops with bulk or joined queries.
  • Real-world scenario: Turn a two-step process that queries orders and then their customers into a single optimized query path.

Quick Start

Refactor a loop that queries related data for each item into a single, joined or bulk-loaded query.

Frequently Asked Questions about n-plus-one-prevention

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix N+1 queries in my ORM?

To fix N+1 queries in your ORM, you enforce eager loading to fetch related data in a single query. This Skill specifies detection patterns and safe fallback strategies to replace per-item queries with bulk or joined fetches.

What is the best way to prevent N+1 queries in a list endpoint?

The best way to prevent N+1 queries in a list endpoint is to refactor loops that fetch related data into a single, joined or bulk-loaded query path, enforcing eager loading across your ORM framework.

How do I refactor a loop to use eager loading?

You refactor a loop to use eager loading by replacing per-item database queries with a single bulk or joined query. This turns a two-step process, like fetching orders then customers, into one optimized query path.

Does this N+1 prevention approach work with Prisma and TypeORM?

Yes, this N+1 prevention approach works with Prisma and TypeORM. It provides eager loading guidance and detection patterns that apply across popular ORM frameworks to optimize data access.

When do I need to apply N+1 query prevention strategies?

You need to apply N+1 query prevention strategies when you have list endpoints or loops that fetch related data across an ORM. If your code executes separate queries for each item to get related data, N+1 prevention is required.