Class: Chartable::Queries::Monthly
- Inherits:
-
Object
- Object
- Chartable::Queries::Monthly
- Defined in:
- lib/chartable/queries/monthly.rb
Class Method Summary collapse
-
.call(scope, on:, order:) ⇒ Hash
It returns analytics data for the monthly period.
Class Method Details
.call(scope, on:, order:) ⇒ Hash
It returns analytics data for the monthly period. Example output: ‘2018” => 1, “October 2018” => 1` SQLite does not support DATE_FORMAT function so a little hack is needed
9 10 11 12 13 14 15 |
# File 'lib/chartable/queries/monthly.rb', line 9 def self.call(scope, on:, order:) if ActiveRecord::Base.connection.class.to_s.match(/postgresql/i) scope.group(Arel.sql("#{on}, to_char(#{on},'FMMonth YYYY')")).order(Arel.sql("#{on} #{order}")).size else scope.group(Arel.sql("#{on}, DATE_FORMAT(#{on},'%M %Y')")).order(Arel.sql("#{on} #{order}")).size end end |