diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-07 22:32:16 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-07 22:32:16 -0800 |
commit | 5f03d1616cc6f66013fbaae9c92553df74a7aee4 (patch) | |
tree | 6f35b2683c858fb6bb95f7dc895aecf1309f48df /lib | |
parent | 2fa1ff4e63f27d49a529116bb5e9933a0f385c3e (diff) | |
download | rails-5f03d1616cc6f66013fbaae9c92553df74a7aee4.tar.gz rails-5f03d1616cc6f66013fbaae9c92553df74a7aee4.tar.bz2 rails-5f03d1616cc6f66013fbaae9c92553df74a7aee4.zip |
removed sql builder
Diffstat (limited to 'lib')
33 files changed, 111 insertions, 465 deletions
diff --git a/lib/active_relation.rb b/lib/active_relation.rb index 7cdbd5c02d..2120d09bc8 100644 --- a/lib/active_relation.rb +++ b/lib/active_relation.rb @@ -4,6 +4,8 @@ require 'rubygems' require 'activesupport' require 'activerecord' +require 'active_relation/sql_builder' + require 'active_relation/relations/relation' require 'active_relation/relations/compound_relation' require 'active_relation/relations/table_relation' @@ -19,7 +21,6 @@ require 'active_relation/relations/selection_relation' require 'active_relation/relations/order_relation' require 'active_relation/relations/range_relation' require 'active_relation/relations/rename_relation' -require 'active_relation/relations/join' require 'active_relation/relations/deletion_relation' require 'active_relation/relations/insertion_relation' @@ -36,19 +37,4 @@ require 'active_relation/predicates/match_predicate' require 'active_relation/extensions/object' require 'active_relation/extensions/array' require 'active_relation/extensions/base' -require 'active_relation/extensions/hash' - -require 'active_relation/sql_builder/sql_builder' -require 'active_relation/sql_builder/select_builder' -require 'active_relation/sql_builder/delete_builder' -require 'active_relation/sql_builder/insert_builder' -require 'active_relation/sql_builder/joins_builder' -require 'active_relation/sql_builder/join_builder' -require 'active_relation/sql_builder/inner_join_builder' -require 'active_relation/sql_builder/left_outer_join_builder' -require 'active_relation/sql_builder/equals_condition_builder' -require 'active_relation/sql_builder/conditions_builder' -require 'active_relation/sql_builder/order_builder' -require 'active_relation/sql_builder/columns_builder' -require 'active_relation/sql_builder/selects_builder' -require 'active_relation/sql_builder/values_builder'
\ No newline at end of file +require 'active_relation/extensions/hash'
\ No newline at end of file diff --git a/lib/active_relation/extensions/hash.rb b/lib/active_relation/extensions/hash.rb index f643ac17ab..d9496df2e9 100644 --- a/lib/active_relation/extensions/hash.rb +++ b/lib/active_relation/extensions/hash.rb @@ -5,9 +5,7 @@ class Hash end end - def to_sql(builder = ValuesBuilder.new) - builder.call do - row *values - end + def to_sql(options = {}) + "(#{values.collect(&:to_sql).join(', ')})" end end
\ No newline at end of file diff --git a/lib/active_relation/extensions/object.rb b/lib/active_relation/extensions/object.rb index c241581f86..79d7613d9a 100644 --- a/lib/active_relation/extensions/object.rb +++ b/lib/active_relation/extensions/object.rb @@ -1,12 +1,12 @@ class Object + include SqlBuilder + def qualify self end - def to_sql(builder = EqualsConditionBuilder.new) - me = self - builder.call do - value me.to_s - end + def to_sql(options = {}) + options.reverse_merge!(:quote => true) + options[:quote] ? quote(self) : self end end
\ No newline at end of file diff --git a/lib/active_relation/predicates.rb b/lib/active_relation/predicates.rb new file mode 100644 index 0000000000..0179a15035 --- /dev/null +++ b/lib/active_relation/predicates.rb @@ -0,0 +1,4 @@ +module ActiveRelation + module Predicates + end +end
\ No newline at end of file diff --git a/lib/active_relation/predicates/binary_predicate.rb b/lib/active_relation/predicates/binary_predicate.rb index c467d63310..f3ce430d00 100644 --- a/lib/active_relation/predicates/binary_predicate.rb +++ b/lib/active_relation/predicates/binary_predicate.rb @@ -5,16 +5,15 @@ class BinaryPredicate < Predicate @attribute1, @attribute2 = attribute1, attribute2 end + def ==(other) + super and @attribute1.eql?(other.attribute1) and @attribute2.eql?(other.attribute2) + end + def qualify self.class.new(attribute1.qualify, attribute2.qualify) end - def to_sql(builder = ConditionsBuilder.new) - builder.call do - send(predicate_name) do - attribute1.to_sql(self) - attribute2.to_sql(self) - end - end + def to_sql(options = {}) + "#{attribute1.to_sql} #{predicate_sql} #{attribute2.to_sql}" end end
\ No newline at end of file diff --git a/lib/active_relation/predicates/equality_predicate.rb b/lib/active_relation/predicates/equality_predicate.rb index 7040c45f67..4f4113c740 100644 --- a/lib/active_relation/predicates/equality_predicate.rb +++ b/lib/active_relation/predicates/equality_predicate.rb @@ -6,7 +6,7 @@ class EqualityPredicate < BinaryPredicate end protected - def predicate_name - :equals + def predicate_sql + '=' end end
\ No newline at end of file diff --git a/lib/active_relation/relations/attribute.rb b/lib/active_relation/relations/attribute.rb index 9ccbb495ea..8193132de6 100644 --- a/lib/active_relation/relations/attribute.rb +++ b/lib/active_relation/relations/attribute.rb @@ -1,12 +1,14 @@ class Attribute - attr_reader :relation, :name, :aliaz + include SqlBuilder + + attr_reader :relation, :name, :alias def initialize(relation, name, aliaz = nil) - @relation, @name, @aliaz = relation, name, aliaz + @relation, @name, @alias = relation, name, aliaz end - def alias(aliaz) - Attribute.new(relation, name, aliaz) + def alias(aliaz = nil) + aliaz ? Attribute.new(relation, name, aliaz) : @alias end def qualified_name @@ -16,12 +18,12 @@ class Attribute def qualify self.alias(qualified_name) end - - module Predications - def eql?(other) - relation == other.relation and name == other.name and aliaz == other.aliaz - end + def eql?(other) + relation == other.relation and name == other.name and self.alias == other.alias + end + + module Predications def ==(other) EqualityPredicate.new(self, other) end @@ -48,9 +50,7 @@ class Attribute end include Predications - def to_sql(builder = SelectsBuilder.new) - builder.call do - column relation.table, name, aliaz - end + def to_sql(options = {}) + "#{quote_table_name(relation.table)}.#{quote_column_name(name)}" + (options[:use_alias] && self.alias ? " AS #{self.alias.to_s.to_sql}" : "") end end
\ No newline at end of file diff --git a/lib/active_relation/relations/compound_relation.rb b/lib/active_relation/relations/compound_relation.rb index fe92905d92..b18921e06d 100644 --- a/lib/active_relation/relations/compound_relation.rb +++ b/lib/active_relation/relations/compound_relation.rb @@ -1,3 +1,5 @@ class CompoundRelation < Relation - delegate :attributes, :attribute, :joins, :selects, :orders, :table, :inserts, :to => :relation + attr_reader :relation + + delegate :attributes, :attribute, :joins, :selects, :orders, :table, :inserts, :limit, :offset, :to => :relation end
\ No newline at end of file diff --git a/lib/active_relation/relations/deletion_relation.rb b/lib/active_relation/relations/deletion_relation.rb index e060efd5f9..8418319055 100644 --- a/lib/active_relation/relations/deletion_relation.rb +++ b/lib/active_relation/relations/deletion_relation.rb @@ -1,22 +1,13 @@ class DeletionRelation < CompoundRelation - attr_reader :relation - - def ==(other) - relation == other.relation - end - def initialize(relation) @relation = relation end - def to_sql(builder = DeleteBuilder.new) - builder.call do - delete - from table - where do - selects.each { |s| s.to_sql(self) } - end - end - end - + def to_sql(options = {}) + [ + "DELETE", + "FROM #{quote_table_name(table)}", + ("WHERE #{selects.collect(&:to_sql).join('\n\tAND ')}" unless selects.blank?) + ].compact.join("\n") + end end
\ No newline at end of file diff --git a/lib/active_relation/relations/inner_join_relation.rb b/lib/active_relation/relations/inner_join_relation.rb index 5e58f241f8..74160c559f 100644 --- a/lib/active_relation/relations/inner_join_relation.rb +++ b/lib/active_relation/relations/inner_join_relation.rb @@ -1,6 +1,6 @@ class InnerJoinRelation < JoinRelation protected - def join_type - :inner_join + def join_sql + "INNER JOIN" end end
\ No newline at end of file diff --git a/lib/active_relation/relations/insertion_relation.rb b/lib/active_relation/relations/insertion_relation.rb index 84752d13f9..002ebbf062 100644 --- a/lib/active_relation/relations/insertion_relation.rb +++ b/lib/active_relation/relations/insertion_relation.rb @@ -1,29 +1,21 @@ class InsertionRelation < CompoundRelation - attr_reader :relation, :tuple + attr_reader :record - def initialize(relation, tuple) - @relation, @tuple = relation, tuple - end - - def to_sql(builder = InsertBuilder.new) - builder.call do - insert - into table - columns do - tuple.keys.each { |attribute| attribute.to_sql(self) } - end - values do - inserts.each { |insert| insert.to_sql(self) } - end - end + def initialize(relation, record) + @relation, @record = relation, record end - def ==(other) - relation == other.relation and tuple == other.tuple - end - + def to_sql(options = {}) + [ + "INSERT", + "INTO #{quote_table_name(table)}", + "(#{record.keys.collect(&:to_sql).join(', ')})", + "VALUES #{inserts.collect(&:to_sql).join(', ')}" + ].join("\n") + end + protected def inserts - relation.inserts + [tuple] + relation.inserts + [record] end end
\ No newline at end of file diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb deleted file mode 100644 index 9a6196deac..0000000000 --- a/lib/active_relation/relations/join.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Join - attr_reader :relation1, :relation2, :predicates, :join_type - - def initialize(relation1, relation2, predicates, join_type) - @relation1, @relation2, @predicates, @join_type = relation1, relation2, predicates, join_type - end - - def to_sql(builder = JoinsBuilder.new) - builder.call do - send(join_type, relation2.table) do - predicates.each { |p| p.to_sql(self) } - end - end - end -end
\ No newline at end of file diff --git a/lib/active_relation/relations/join_relation.rb b/lib/active_relation/relations/join_relation.rb index 79c8a915b8..845dfd732f 100644 --- a/lib/active_relation/relations/join_relation.rb +++ b/lib/active_relation/relations/join_relation.rb @@ -17,7 +17,7 @@ class JoinRelation < Relation protected def joins - relation1.joins + relation2.joins + [Join.new(relation1, relation2, predicates, join_type)] + [relation1.joins, relation2.joins, join].compact.join(" ") end def selects @@ -33,4 +33,9 @@ class JoinRelation < Relation end delegate :table, :to => :relation1 + + private + def join + "#{join_sql} #{quote_table_name(relation2.table)} ON #{predicates.collect { |p| p.to_sql(:quote => false) }.join(' AND ')}" + end end
\ No newline at end of file diff --git a/lib/active_relation/relations/left_outer_join_relation.rb b/lib/active_relation/relations/left_outer_join_relation.rb index 6d13d8da07..57eda4e1fc 100644 --- a/lib/active_relation/relations/left_outer_join_relation.rb +++ b/lib/active_relation/relations/left_outer_join_relation.rb @@ -1,6 +1,6 @@ class LeftOuterJoinRelation < JoinRelation protected - def join_type - :left_outer_join + def join_sql + "LEFT OUTER JOIN" end end
\ No newline at end of file diff --git a/lib/active_relation/relations/order_relation.rb b/lib/active_relation/relations/order_relation.rb index b39dc45c3f..dfb0c0bf25 100644 --- a/lib/active_relation/relations/order_relation.rb +++ b/lib/active_relation/relations/order_relation.rb @@ -1,25 +1,15 @@ class OrderRelation < CompoundRelation - attr_reader :relation, :attributes + attr_reader :relation, :orders - def initialize(relation, *attributes) - @relation, @attributes = relation, attributes + def initialize(relation, *orders) + @relation, @orders = relation, orders end def ==(other) - relation == other.relation and attributes.eql?(other.attributes) + relation == other.relation and orders.eql?(other.orders) end def qualify - OrderRelation.new(relation.qualify, *attributes.collect { |a| a.qualify }) - end - - def to_sql(builder = SelectBuilder.new) - relation.to_sql(builder).call do - attributes.each do |attribute| - order_by do - attribute.to_sql(self) - end - end - end + OrderRelation.new(relation.qualify, *orders.collect { |o| o.qualify }) end end
\ No newline at end of file diff --git a/lib/active_relation/relations/projection_relation.rb b/lib/active_relation/relations/projection_relation.rb index 1a0e8dbfe4..53b0ad1e91 100644 --- a/lib/active_relation/relations/projection_relation.rb +++ b/lib/active_relation/relations/projection_relation.rb @@ -1,4 +1,4 @@ -class ProjectionRelation < Relation +class ProjectionRelation < CompoundRelation attr_reader :relation, :attributes def initialize(relation, *attributes) @@ -12,12 +12,4 @@ class ProjectionRelation < Relation def qualify ProjectionRelation.new(relation.qualify, *attributes.collect(&:qualify)) end - - def to_sql(builder = SelectBuilder.new) - relation.to_sql(builder).call do - select do - attributes.collect { |a| a.to_sql(self) } - end - end - end end
\ No newline at end of file diff --git a/lib/active_relation/relations/range_relation.rb b/lib/active_relation/relations/range_relation.rb index 9225d5615b..6a2b0b3470 100644 --- a/lib/active_relation/relations/range_relation.rb +++ b/lib/active_relation/relations/range_relation.rb @@ -1,5 +1,5 @@ -class RangeRelation < Relation - attr_reader :relation, :range +class RangeRelation < CompoundRelation + attr_reader :range def initialize(relation, range) @relation, @range = relation, range @@ -9,10 +9,11 @@ class RangeRelation < Relation relation == other.relation and range == other.range end - def to_sql(builder = SelectBuilder.new) - relation.to_sql(builder).call do - limit range.last - range.first + 1 - offset range.first - end + def limit + range.end - range.begin + 1 + end + + def offset + range.begin end end
\ No newline at end of file diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index be6ee760a5..0a8455b39c 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -1,4 +1,6 @@ class Relation + include SqlBuilder + module Iteration include Enumerable @@ -50,8 +52,8 @@ class Relation RenameRelation.new(self, attribute => aliaz) end - def insert(tuple) - InsertionRelation.new(self, tuple) + def insert(record) + InsertionRelation.new(self, record) end def delete @@ -64,28 +66,25 @@ class Relation ActiveRecord::Base.connection end - def to_sql(builder = SelectBuilder.new) - builder.call do - select do - attributes.each { |a| a.to_sql(self) } - end - from table do - joins.each { |j| j.to_sql(self) } - end - where do - selects.each { |s| s.to_sql(self) } - end - order_by do - orders.each { |o| o.to_sql(self) } - end - end + def to_sql(options = {}) + [ + "SELECT #{attributes.collect{ |a| a.to_sql(:use_alias => true) }.join(', ')}", + "FROM #{quote_table_name(table)}", + (joins.to_sql(:quote => false) unless joins.blank?), + ("WHERE #{selects.collect{|s| s.to_sql(:quote => false)}.join("\n\tAND ")}" unless selects.blank?), + ("ORDER BY #{orders.collect(&:to_sql)}" unless orders.blank?), + ("LIMIT #{limit.to_sql}" unless limit.blank?), + ("OFFSET #{offset.to_sql}" unless offset.blank?) + ].compact.join("\n") end - delegate :to_s, :to => :to_sql + alias_method :to_s, :to_sql protected - def attributes; [] end - def joins; [] end - def selects; [] end - def orders; [] end - def inserts; [] end + def attributes; [] end + def selects; [] end + def orders; [] end + def inserts; [] end + def joins; nil end + def limit; nil end + def offset; nil end end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder.rb b/lib/active_relation/sql_builder.rb new file mode 100644 index 0000000000..0d2187173e --- /dev/null +++ b/lib/active_relation/sql_builder.rb @@ -0,0 +1,7 @@ +module SqlBuilder + def connection + ActiveRecord::Base.connection + end + + delegate :quote_table_name, :quote_column_name, :quote, :to => :connection +end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/columns_builder.rb b/lib/active_relation/sql_builder/columns_builder.rb deleted file mode 100644 index a8a5d0e4ca..0000000000 --- a/lib/active_relation/sql_builder/columns_builder.rb +++ /dev/null @@ -1,16 +0,0 @@ -class ColumnsBuilder < SqlBuilder - def initialize(&block) - @columns = [] - super(&block) - end - - def to_s - @columns.join(', ') - end - - def column(table, column, aliaz = nil) - @columns << "#{quote_table_name(table)}.#{quote_column_name(column)}" - end - - delegate :blank?, :to => :@columns -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/conditions_builder.rb b/lib/active_relation/sql_builder/conditions_builder.rb deleted file mode 100644 index 60430f65d8..0000000000 --- a/lib/active_relation/sql_builder/conditions_builder.rb +++ /dev/null @@ -1,20 +0,0 @@ -class ConditionsBuilder < SqlBuilder - def initialize(&block) - @conditions = [] - super(&block) - end - - def equals(&block) - @conditions << EqualsConditionBuilder.new(&block) - end - - def value(value) - @conditions << value - end - - def to_s - @conditions.join(' AND ') - end - - delegate :blank?, :to => :@conditions -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/delete_builder.rb b/lib/active_relation/sql_builder/delete_builder.rb deleted file mode 100644 index 2e8be94dfe..0000000000 --- a/lib/active_relation/sql_builder/delete_builder.rb +++ /dev/null @@ -1,32 +0,0 @@ -class DeleteBuilder < SqlBuilder - def delete - end - - def from(table) - @table = table - end - - def where(&block) - @conditions = ConditionsBuilder.new(&block) - end - - def to_s - [delete_clause, - from_clause, - where_clause - ].compact.join("\n") - end - - private - def delete_clause - "DELETE" - end - - def from_clause - "FROM #{quote_table_name(@table)}" - end - - def where_clause - "WHERE #{@conditions}" unless @conditions.blank? - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/equals_condition_builder.rb b/lib/active_relation/sql_builder/equals_condition_builder.rb deleted file mode 100644 index cfa919c34c..0000000000 --- a/lib/active_relation/sql_builder/equals_condition_builder.rb +++ /dev/null @@ -1,18 +0,0 @@ -class EqualsConditionBuilder < SqlBuilder - def initialize(&block) - @operands = [] - super(&block) - end - - def column(table, column, aliaz = nil) - @operands << "#{quote_table_name(table)}.#{quote_column_name(column)}" - end - - def value(value) - @operands << value - end - - def to_s - "#{@operands[0]} = #{@operands[1]}" - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/inner_join_builder.rb b/lib/active_relation/sql_builder/inner_join_builder.rb deleted file mode 100644 index 6aec703325..0000000000 --- a/lib/active_relation/sql_builder/inner_join_builder.rb +++ /dev/null @@ -1,5 +0,0 @@ -class InnerJoinBuilder < JoinBuilder - def join_type - "INNER JOIN" - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/insert_builder.rb b/lib/active_relation/sql_builder/insert_builder.rb deleted file mode 100644 index 09deefad10..0000000000 --- a/lib/active_relation/sql_builder/insert_builder.rb +++ /dev/null @@ -1,41 +0,0 @@ -class InsertBuilder < SqlBuilder - def insert - end - - def into(table) - @table = table - end - - def columns(&block) - @columns = ColumnsBuilder.new(&block) - end - - def values(&block) - @values = ValuesBuilder.new(&block) - end - - def to_s - [insert_clause, - into_clause, - columns_clause, - values_clause - ].compact.join("\n") - end - - private - def insert_clause - "INSERT" - end - - def into_clause - "INTO #{quote_table_name(@table)}" - end - - def values_clause - "VALUES #{@values}" unless @values.blank? - end - - def columns_clause - "(#{@columns})" unless @columns.blank? - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/join_builder.rb b/lib/active_relation/sql_builder/join_builder.rb deleted file mode 100644 index ef63d1fcb1..0000000000 --- a/lib/active_relation/sql_builder/join_builder.rb +++ /dev/null @@ -1,13 +0,0 @@ -class JoinBuilder < SqlBuilder - def initialize(table, &block) - @table = table - @conditions = ConditionsBuilder.new - super(&block) - end - - delegate :call, :to => :@conditions - - def to_s - "#{join_type} #{quote_table_name(@table)} ON #{@conditions}" - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/joins_builder.rb b/lib/active_relation/sql_builder/joins_builder.rb deleted file mode 100644 index 36a92e9922..0000000000 --- a/lib/active_relation/sql_builder/joins_builder.rb +++ /dev/null @@ -1,18 +0,0 @@ -class JoinsBuilder < SqlBuilder - def initialize(&block) - @joins = [] - super(&block) - end - - def inner_join(table, &block) - @joins << InnerJoinBuilder.new(table, &block) - end - - def left_outer_join(table, &block) - @joins << LeftOuterJoinBuilder.new(table, &block) - end - - def to_s - @joins.join(' ') - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/left_outer_join_builder.rb b/lib/active_relation/sql_builder/left_outer_join_builder.rb deleted file mode 100644 index dad3f85810..0000000000 --- a/lib/active_relation/sql_builder/left_outer_join_builder.rb +++ /dev/null @@ -1,5 +0,0 @@ -class LeftOuterJoinBuilder < JoinBuilder - def join_type - "LEFT OUTER JOIN" - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/order_builder.rb b/lib/active_relation/sql_builder/order_builder.rb deleted file mode 100644 index 66a8cfdba9..0000000000 --- a/lib/active_relation/sql_builder/order_builder.rb +++ /dev/null @@ -1,16 +0,0 @@ -class OrderBuilder < SqlBuilder - def initialize(&block) - @orders = [] - super(&block) - end - - def column(table, column, aliaz = nil) - @orders << "#{quote_table_name(table)}.#{quote_column_name(column)}" - end - - def to_s - @orders.join(', ') - end - - delegate :blank?, :to => :@orders -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/select_builder.rb b/lib/active_relation/sql_builder/select_builder.rb deleted file mode 100644 index 57116cb64b..0000000000 --- a/lib/active_relation/sql_builder/select_builder.rb +++ /dev/null @@ -1,61 +0,0 @@ -class SelectBuilder < SqlBuilder - def select(&block) - @selects = SelectsBuilder.new(&block) - end - - def from(table, &block) - @table = table - @joins = JoinsBuilder.new(&block) - end - - def where(&block) - @conditions = ConditionsBuilder.new(&block) - end - - def order_by(&block) - @orders = OrderBuilder.new(&block) - end - - def limit(i, offset = nil) - @limit = i - offset(offset) if offset - end - - def offset(i) - @offset = i - end - - def to_s - [select_clause, - from_clause, - where_clause, - order_by_clause, - limit_clause, - offset_clause].compact.join("\n") - end - - private - def select_clause - "SELECT #{@selects}" unless @selects.blank? - end - - def from_clause - "FROM #{quote_table_name(@table)} #{@joins}" unless @table.blank? - end - - def where_clause - "WHERE #{@conditions}" unless @conditions.blank? - end - - def order_by_clause - "ORDER BY #{@orders}" unless @orders.blank? - end - - def limit_clause - "LIMIT #{@limit}" unless @limit.blank? - end - - def offset_clause - "OFFSET #{@offset}" unless @offset.blank? - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/selects_builder.rb b/lib/active_relation/sql_builder/selects_builder.rb deleted file mode 100644 index 6ad06d0ae4..0000000000 --- a/lib/active_relation/sql_builder/selects_builder.rb +++ /dev/null @@ -1,9 +0,0 @@ -class SelectsBuilder < ColumnsBuilder - def all - @columns << :* - end - - def column(table, column, aliaz = nil) - @columns << "#{quote_table_name(table)}.#{quote_column_name(column)}" + (aliaz ? " AS #{quote(aliaz)}" : '') - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/sql_builder.rb b/lib/active_relation/sql_builder/sql_builder.rb deleted file mode 100644 index c984444e41..0000000000 --- a/lib/active_relation/sql_builder/sql_builder.rb +++ /dev/null @@ -1,35 +0,0 @@ -class SqlBuilder - def initialize(&block) - @callers = [] - call(&block) if block - end - - def method_missing(method, *args) - @callers.last.send(method, *args) - end - - def ==(other) - to_s == other.to_s - end - - def to_s - end - - def call(&block) - returning self do |builder| - @callers << eval("self", block.binding) - begin - instance_eval &block - ensure - @callers.pop - end - end - end - - private - delegate :quote_table_name, :quote_column_name, :quote, :to => :connection - - def connection - ActiveRecord::Base.connection - end -end
\ No newline at end of file diff --git a/lib/active_relation/sql_builder/values_builder.rb b/lib/active_relation/sql_builder/values_builder.rb deleted file mode 100644 index f22b1e507e..0000000000 --- a/lib/active_relation/sql_builder/values_builder.rb +++ /dev/null @@ -1,16 +0,0 @@ -class ValuesBuilder < SqlBuilder - def initialize(&block) - @values = [] - super(&block) - end - - def row(*values) - @values << "(#{values.collect { |v| quote(v) }.join(', ')})" - end - - def to_s - @values.join(', ') - end - - delegate :blank?, :to => :@values -end
\ No newline at end of file |