Class: Babik::QuerySet::PostgresMySQLAggregationFunction

Inherits:
AbstractAggregationFunction show all
Defined in:
lib/babik/queryset/components/aggregation.rb

Overview

When a aggregation function is in PostgreSQL and MySQL (main supported databases)

Direct Known Subclasses

StdDev, StdDevSample, Var, VarSample

Instance Attribute Summary

Attributes inherited from AbstractAggregationFunction

#field_name, #model, #selection

Instance Method Summary collapse

Methods inherited from AbstractAggregationFunction

db_adapter, #initialize, #left_joins_by_alias, #prepare, #sql

Constructor Details

This class inherits a constructor from Babik::QuerySet::AbstractAggregationFunction

Instance Method Details

#sql_operationString

Return the SQL code operation for this aggregation, e.g.:

- STDDEV_POP(?field)
- VAR_POP(?field)

Returns:

  • (String)

    SQL code for the aggregation

Raises:

  • (RuntimeException)

    if database has no support for this operation.



144
145
146
147
148
# File 'lib/babik/queryset/components/aggregation.rb', line 144

def sql_operation
  db_adapter = self.class.db_adapter
  return self.class::SQL_OPERATION if %w[postgresql mysql2].include?(db_adapter)
  raise "#{db_adapter} has no support for #{self.class} aggregation"
end