2023-06-05 14:46:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin::Metrics::Measure::QueryHelper
|
|
|
|
protected
|
|
|
|
|
|
|
|
def perform_data_query
|
|
|
|
measurement_data_rows.map { |row| { date: row['period'], value: row['value'].to_s } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def measurement_data_rows
|
|
|
|
ActiveRecord::Base.connection.select_all(sanitized_sql_string)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sanitized_sql_string
|
|
|
|
ActiveRecord::Base.sanitize_sql_array(sql_array)
|
|
|
|
end
|
|
|
|
|
2024-06-11 03:42:15 -04:00
|
|
|
def generated_series_days
|
|
|
|
Arel.sql(
|
|
|
|
<<~SQL.squish
|
2024-06-18 12:04:58 -04:00
|
|
|
SELECT generate_series(:start_at::timestamp, :end_at::timestamp, '1 day')::date AS period
|
2024-06-11 03:42:15 -04:00
|
|
|
SQL
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-06-05 14:46:04 -04:00
|
|
|
def account_domain_sql(include_subdomains)
|
|
|
|
if include_subdomains
|
|
|
|
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))"
|
|
|
|
else
|
|
|
|
'accounts.domain = :domain::text'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|