Class: AhoyCaptain::CampaignQuery

Inherits:
ApplicationQuery show all
Defined in:
app/queries/ahoy_captain/campaign_query.rb

Instance Attribute Summary

Attributes inherited from ApplicationQuery

#params

Instance Method Summary collapse

Methods inherited from ApplicationQuery

call, inherited, #initialize, #inspect

Constructor Details

This class inherits a constructor from AhoyCaptain::ApplicationQuery

Instance Method Details

#buildObject



3
4
5
6
7
8
9
10
11
12
# File 'app/queries/ahoy_captain/campaign_query.rb', line 3

def build
  visit_query
    .select(
      "COALESCE(#{params[:campaigns_type]}, 'Direct/None') as label",
      "count(COALESCE(#{params[:campaigns_type]}, 'Direct/None')) as count",
      "sum(count(COALESCE(#{params[:campaigns_type]}, 'Direct/None'))) OVER() as total_count"
    )
    .group("COALESCE(#{params[:campaigns_type]}, 'Direct/None')")
    .order(Arel.sql("count(COALESCE(#{params[:campaigns_type]}, 'Direct/None')) desc"))
end