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