Class: Arel::Sql::SelectClause

Inherits:
Formatter show all
Defined in:
lib/arel/engines/sql/formatters.rb

Instance Attribute Summary

Attributes inherited from Formatter

#environment

Instance Method Summary collapse

Methods inherited from Formatter

#initialize

Constructor Details

This class inherits a constructor from Arel::Sql::Formatter

Instance Method Details

#attribute(attribute) ⇒ Object



15
16
17
18
# File 'lib/arel/engines/sql/formatters.rb', line 15

def attribute(attribute)
  "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" +
  (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "")
end

#expression(expression) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/arel/engines/sql/formatters.rb', line 20

def expression(expression)
  if expression.function_sql == "DISTINCT"
    "#{expression.function_sql} #{expression.attribute.to_sql(self)}" +
    (expression.alias ? " AS #{quote_column_name(expression.alias)}" : '')
  else
    "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" +
    (expression.alias ? " AS #{quote_column_name(expression.alias)}" : " AS #{expression.function_sql.to_s.downcase}_id")
  end
end

#select(select_sql, table) ⇒ Object



30
31
32
# File 'lib/arel/engines/sql/formatters.rb', line 30

def select(select_sql, table)
  "(#{select_sql}) AS #{quote_table_name(name_for(table))}"
end

#value(value) ⇒ Object



34
35
36
# File 'lib/arel/engines/sql/formatters.rb', line 34

def value(value)
  value
end