query-agent

Generate reusable ActiveRecord Query Objects with eager loading and RSpec tests.

Updated Feb 8, 2026
One-click install
npx skills add https://github.com/mlbright/notes --skill query-agent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-agent
Source: https://github.com/mlbright/notes/tree/main/.github/skills/query-agent
Command: npx skills add https://github.com/mlbright/notes --skill query-agent

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill streamlines complex database interactions in Rails applications by encapsulating intricate queries into reusable, testable Query Objects, preventing messy logic in controllers and models.

Core Features & Use Cases

  • Encapsulates Complex Queries: Organizes SQL logic into dedicated classes.
  • Promotes Reusability: Allows queries to be easily shared and maintained across the application.
  • Enhances Testability: Enables isolated testing of query logic.
  • Prevents N+1 Queries: Encourages the use of includes and other eager loading techniques.
  • Use Case: When building a reporting dashboard that requires filtering by multiple criteria, sorting, and aggregations, use this Skill to create a clean SalesDataQuery object instead of cluttering your controller.

Quick Start

Use the query-agent skill to create a new ActiveRecord query object for filtering users by their last login date.

Frequently Asked Questions about query-agent

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

FAQPage Schema
How do I encapsulate complex ActiveRecord queries in Rails?

Encapsulate complex ActiveRecord queries by generating reusable Query Objects that isolate SQL logic into dedicated classes, preventing messy code in controllers and models while promoting organization and reusability across your application.

What is the best way to organize Rails query logic for reporting dashboards?

Organizing Rails query logic for reporting dashboards is best handled by extracting filtering, sorting, and aggregations into a clean Query Object, preventing cluttered controllers and enabling isolated testing for complex database interactions.

How do I prevent N+1 queries in Rails ActiveRecord?

Prevent N+1 queries in Rails ActiveRecord by generating Query Objects that encapsulate eager loading strategies, utilizing `includes` to optimize database interactions and avoid excessive queries when fetching associated records.

Can I generate RSpec tests for Rails query objects?

Yes, you can generate RSpec tests alongside Rails query objects to enable isolated testing of complex database query logic, ensuring your encapsulated ActiveRecord filters and aggregations function correctly without hitting controllers.

When do I need a query object in Rails?

You need a query object in Rails when building complex database queries involving multiple filtering criteria, sorting, or aggregations, allowing you to extract intricate SQL logic from models and controllers into a reusable, testable class.

Does query-agent work without external Rails dependencies?

Yes, query-agent works without external dependencies, relying solely on standard Rails ActiveRecord components to encapsulate query logic and generate RSpec tests for your database interactions.