To distill the essence of turning a raw SQL DB query into an API endpoint in Rails, we can abstract away the domain-specific details and focus on the general process. Here's a step-by-step guide that captures the technique:
Create a module with a method that encapsulates the raw SQL query. This method should accept parameters to filter or manipulate the data as needed and return the result set.
module Queries
module CustomData
def self.perform(params:)
query = <<-SQL