QueryTrace
Detects ORM code patterns (Prisma, SQLAlchemy, ActiveRecord) that will cause N+1 queries or missing indexes. Flags them inline before you ever run the code.
Features
10 Detection Patterns for common N+1 query problems
Multi-ORM Support:
- Prisma (TypeScript/JavaScript)
- SQLAlchemy (Python)
- ActiveRecord (Ruby)
- Sequelize (JavaScript)
- TypeORM (TypeScript)
- Django ORM (Python)
- Flask-SQLAlchemy (Python)
Inline Diagnostics: Problems appear as squiggly underlines with explanations
Performance Hints: Suggests fixes like include(), select_related(), or eager_load()
Zero Configuration: Works out of the box
Usage
Automatic Scanning
QueryTrace automatically scans open files as you type. No commands needed.
Command Palette
- QueryTrace: Scan Current File — Manually trigger a scan
- QueryTrace: Toggle Scanning — Enable/disable QueryTrace diagnostics
How It Works
QueryTrace looks for patterns like:
- Looping over query results and making nested queries inside the loop
- Accessing relations without eager loading
- Filtering in loops instead of in the database query
Configuration
{
"queryTrace.enabled": true,
"queryTrace.orms": [
"prisma",
"sqlalchemy",
"activerecord",
"sequelize",
"typeorm"
],
"queryTrace.severity": "warning"
}
Example
Problematic Code (N+1):
const users = await prisma.user.findMany();
for (const user of users) {
const posts = await prisma.post.findMany({
where: { authorId: user.id }
});
}
QueryTrace Diagnostic:
⚠ Potential N+1 query: Querying inside a loop.
Consider using `include: { posts: true }` in the initial query.
Fixed Code:
const users = await prisma.user.findMany({
include: { posts: true }
});
for (const user of users) {
console.log(user.posts);
}
Supported ORMs
- Prisma —
.findMany(), .findFirst(), nested loops
- SQLAlchemy —
.query(), .filter(), lazy loading
- ActiveRecord —
.where(), .find(), N+1 in loops
- Sequelize —
.findAll(), nested queries
- TypeORM —
.find(), relations without eager loading
- Django ORM —
.filter(), select_related() hints
- Flask-SQLAlchemy —
.query.all() in loops
Requirements
License
MIT