query-agent

Encapsulate complex Rails queries into reusable query objects returning ActiveRecord relations.

Updated Nov 1, 2025
One-click install
npx skills add https://github.com/nschneble/rails-superstack --skill query-agent-nschneble
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-agent
Source: https://github.com/nschneble/rails-superstack/tree/main/.agents/skills/query-agent
Command: npx skills add https://github.com/nschneble/rails-superstack --skill query-agent-nschneble

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rails apps often struggle with reusable, testable complex queries. Querying with many conditions leads to scattered scopes and duplicated logic, making maintenance painful and error-prone.

Core Features & Use Cases

  • Encapsulated Query Objects: create modular, composable queries under app/queries that return ActiveRecord relations.
  • Composability and SRP: chainable filters via then and private helpers to keep logic focused and testable.
  • Testability: includes RSpec specs ensuring behavior, edge cases, and N+1 prevention.
  • Use Cases: ideal for reports, dashboards, aggregations, and statistics where complex querying is required.

Quick Start

Create a new query object under app/queries and invoke it from a controller to compose reusable, testable queries.

Frequently Asked Questions about query-agent

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

FAQPage Schema
How do I handle complex Rails queries with multiple conditions without duplicating scopes?

Encapsulating complex Rails queries into reusable query objects under app/queries prevents scattered scopes and duplicated logic. These objects return ActiveRecord relations, simplifying data access for multi-criteria filtering while keeping maintenance manageable and error-free.

What is the best way to structure reusable ActiveRecord queries for dashboards and reports?

Building reusable query objects for ActiveRecord is ideal for dashboards, reports, and aggregations. By returning ActiveRecord relations and applying the Single Responsibility Principle, you create modular, composable filters that keep complex querying logic organized and focused.

How do I test complex ActiveRecord query objects and prevent N+1 issues in RSpec?

Testing query objects involves writing RSpec specs to ensure behavior, verify edge cases, and prevent N+1 queries. By encapsulating logic into testable classes that return ActiveRecord relations, you isolate database interactions for precise and reliable RSpec validation.

Can I chain multiple filters in Rails query objects while maintaining the Single Responsibility Principle?

You can chain filters in Rails query objects using then and private helpers. This approach maintains the Single Responsibility Principle by keeping logic focused, allowing you to compose modular ActiveRecord relations without creating bloated, multi-purpose classes.

When should I extract Rails scopes into dedicated query objects?

Extract Rails scopes into dedicated query objects when querying involves many conditions, leading to scattered logic and painful maintenance. Query objects are specifically suited for reports, dashboards, aggregations, and statistics where complex, reusable data access is required.