query_helper.rb 659 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. module Admin::Metrics::Measure::QueryHelper
  3. protected
  4. def perform_data_query
  5. measurement_data_rows.map { |row| { date: row['period'], value: row['value'].to_s } }
  6. end
  7. def measurement_data_rows
  8. ActiveRecord::Base.connection.select_all(sanitized_sql_string)
  9. end
  10. def sanitized_sql_string
  11. ActiveRecord::Base.sanitize_sql_array(sql_array)
  12. end
  13. def account_domain_sql(include_subdomains)
  14. if include_subdomains
  15. "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
  16. else
  17. 'accounts.domain = :domain::text'
  18. end
  19. end
  20. end