diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-12 11:09:54 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-08-12 11:09:54 -0700 |
commit | 139038130dd0dadc995aeffd2300f0ef72b74258 (patch) | |
tree | 14f6e2b88f59067eac341f2d57c0f8df7ff0f0f8 /lib/arel/engines/sql/formatters.rb | |
parent | 8543c9d302a726a13ef697cbedd96a2135678958 (diff) | |
download | rails-139038130dd0dadc995aeffd2300f0ef72b74258.tar.gz rails-139038130dd0dadc995aeffd2300f0ef72b74258.tar.bz2 rails-139038130dd0dadc995aeffd2300f0ef72b74258.zip |
clean slate
Diffstat (limited to 'lib/arel/engines/sql/formatters.rb')
-rw-r--r-- | lib/arel/engines/sql/formatters.rb | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/lib/arel/engines/sql/formatters.rb b/lib/arel/engines/sql/formatters.rb deleted file mode 100644 index da899902ff..0000000000 --- a/lib/arel/engines/sql/formatters.rb +++ /dev/null @@ -1,138 +0,0 @@ -module Arel - module Sql - class Formatter - attr_reader :environment, :christener, :engine - - def initialize(environment) - @environment = environment - @christener = environment.christener - @engine = environment.engine - end - - def name_for thing - @christener.name_for thing - end - - def quote_column_name name - @engine.connection.quote_column_name name - end - - def quote_table_name name - @engine.connection.quote_table_name name - end - - def quote value, column = nil - @engine.connection.quote value, column - end - end - - class SelectClause < Formatter - 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 - - 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 - - def select(select_sql, table) - "(#{select_sql}) AS #{quote_table_name(name_for(table))}" - end - - def value(value) - value - end - end - - class PassThrough < Formatter - def value(value) - value - end - end - - class WhereClause < PassThrough - end - - class OrderClause < PassThrough - def ordering(ordering) - "#{quote_table_name(name_for(ordering.attribute.original_relation))}.#{quote_column_name(ordering.attribute.name)} #{ordering.direction_sql}" - end - end - - class GroupClause < PassThrough - def attribute(attribute) - "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" - end - end - - class HavingClause < PassThrough - def attribute(attribute) - attribute - end - end - - class WhereCondition < Formatter - def attribute(attribute) - "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" - end - - def expression(expression) - "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" - end - - def value(value) - value.to_sql(self) - end - - def scalar(value, column = nil) - quote(value, column) - end - - def select(select_sql, table) - "(#{select_sql})" - end - end - - class SelectStatement < Formatter - def select(select_sql, table) - select_sql - end - end - - class TableReference < Formatter - def select(select_sql, table) - "(#{select_sql}) #{quote_table_name(name_for(table))}" - end - - def table(table) - table_name = table.name - return table_name if table_name =~ /\s/ - - unique_name = name_for(table) - - quote_table_name(table_name) + - (table_name != unique_name ? " #{quote_table_name(unique_name)}" : '') - end - end - - class Attribute < WhereCondition - def scalar(scalar) - quote(scalar, environment.column) - end - - def range(left, right) - "#{scalar(left)} AND #{scalar(right)}" - end - end - - class Value < WhereCondition - end - end -end |