debugging-orm-queries

galihcitta's avatarfrom galihcitta

Converts ORM calls to raw SQL and analyzes query performance. Detects N+1 queries, missing indexes, and other anti-patterns. Use when debugging slow queries, tracing ORM-generated SQL, or optimizing database performance for Sequelize, Prisma, TypeORM (Node.js), GORM, sqlc, sqlx, ent (Go), or SQLAlchemy, Django ORM, Peewee (Python).

⭐2stars🔀0forks📁View on GitHub🕐Updated Dec 4, 2025

When & Why to Use This Skill

This Claude skill is a powerful diagnostic tool for developers to optimize database performance by bridging the gap between high-level ORM abstractions and raw SQL execution. It supports a wide range of frameworks including Sequelize, Prisma, SQLAlchemy, and GORM, allowing users to convert ORM calls into readable SQL, detect costly N+1 query patterns, and identify missing indexes. By providing deep visibility into database interactions and parsing EXPLAIN plans, it helps ensure that Node.js, Python, and Go applications maintain high throughput and low latency.

Use Cases

  • Identifying and resolving N+1 query anti-patterns in complex web applications to reduce unnecessary database round-trips.
  • Converting abstract ORM logic into raw SQL to perform 'EXPLAIN ANALYZE' for deep performance profiling and query plan optimization.
  • Debugging unexpected data results by tracing and pretty-printing the exact SQL generated by frameworks like TypeORM, Django ORM, or GORM.
  • Analyzing database logs to detect missing indexes or inefficient WHERE clauses that cause performance bottlenecks in production.
  • Assisting developers in migrating or translating complex query logic between different ORMs or raw SQL formats.
namedebugging-orm-queries
descriptionConverts ORM calls to raw SQL and analyzes query performance. Detects N+1 queries, missing indexes, and other anti-patterns. Use when debugging slow queries, tracing ORM-generated SQL, or optimizing database performance for Sequelize, Prisma, TypeORM (Node.js), GORM, sqlc, sqlx, ent (Go), or SQLAlchemy, Django ORM, Peewee (Python).

Debugging ORM Queries

References

Language ORMs Reference
Node.js Sequelize, Prisma, TypeORM references/nodejs.md
Go GORM, sqlc, sqlx, ent references/golang.md
Python SQLAlchemy, Django, Peewee references/python.md
Anti-patterns N+1, indexes, pagination references/anti_patterns.md

Scripts

# Pretty-print SQL
python scripts/sql_formatter.py "SELECT..."

# Detect N+1, missing WHERE, duplicates from log file
python scripts/query_analyzer.py queries.log [--json]

# Parse EXPLAIN output (PostgreSQL or MySQL)
psql -c "EXPLAIN ANALYZE ..." | python scripts/explain_parser.py --postgres
mysql -e "EXPLAIN FORMAT=JSON ..." | python scripts/explain_parser.py --mysql

# Node.js request-scoped query tracking (see script for setup)
# Integrates with Sequelize, Prisma, TypeORM

Quick Patterns

Enable logging: Check reference for ORM-specific config (usually logging: true or echo=True)

ORM → SQL: Enable logging, run query, capture output

SQL → ORM: Map clauses to methods:

  • SELECT columns → specify fields/attributes
  • WHERE → where/filter with operators
  • JOIN → include/preload/prefetch_related
  • ORDER BY → order/orderBy
  • LIMIT/OFFSET → limit/offset or cursor-based

Performance issues: Run query_analyzer.py on logs, check anti_patterns.md for solutions