class Chartable::Queries::Daily

Public Class Methods

call(scope, on:, order:) click to toggle source

It returns analytics data for the daily period. Example output: `{“October 09, 2018” => 1, “October 10, 2018” => 1}`

@return [Hash]

# 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