diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/crud.rb | 6 | ||||
-rw-r--r-- | lib/arel/nodes/node.rb | 2 | ||||
-rw-r--r-- | lib/arel/select_manager.rb | 24 | ||||
-rw-r--r-- | lib/arel/table.rb | 8 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 34 |
5 files changed, 38 insertions, 36 deletions
diff --git a/lib/arel/crud.rb b/lib/arel/crud.rb index 43805dd464..6c29d5fee4 100644 --- a/lib/arel/crud.rb +++ b/lib/arel/crud.rb @@ -22,7 +22,7 @@ module Arel def update values if $VERBOSE warn <<-eowarn -update (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please +update (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Please switch to `compile_update` eowarn end @@ -45,7 +45,7 @@ switch to `compile_update` def insert values if $VERBOSE warn <<-eowarn -insert (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please +insert (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Please switch to `compile_insert` eowarn end @@ -62,7 +62,7 @@ switch to `compile_insert` def delete if $VERBOSE warn <<-eowarn -delete (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please +delete (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Please switch to `compile_delete` eowarn end diff --git a/lib/arel/nodes/node.rb b/lib/arel/nodes/node.rb index 4faace3782..84dcb1cdf5 100644 --- a/lib/arel/nodes/node.rb +++ b/lib/arel/nodes/node.rb @@ -39,7 +39,7 @@ module Arel def each &block return enum_for(:each) unless block_given? - Visitors::DepthFirst.new(block).accept self + ::Arel::Visitors::DepthFirst.new(block).accept self end end end diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb index 7a1fbbe438..32f833f686 100644 --- a/lib/arel/select_manager.rb +++ b/lib/arel/select_manager.rb @@ -49,9 +49,9 @@ module Arel def where_clauses if $VERBOSE - warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 3.0.0 with no replacement" + warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 4.0.0 with no replacement" end - to_sql = Visitors::ToSql.new @engine.connection_pool + to_sql = Visitors::ToSql.new @engine.connection @ctx.wheres.map { |c| to_sql.accept c } end @@ -139,6 +139,14 @@ module Arel @ctx.projections = projections end + def distinct(value = true) + if value + @ctx.set_quantifier = Arel::Nodes::Distinct.new + else + @ctx.set_quantifier = nil + end + end + def order *expr # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically @ast.orders.concat expr.map { |x| @@ -152,14 +160,14 @@ module Arel end def wheres - warn "#{caller[0]}: SelectManager#wheres is deprecated and will be removed in ARel 3.0.0 with no replacement" - Compatibility::Wheres.new @engine.connection_pool, @ctx.wheres + warn "#{caller[0]}: SelectManager#wheres is deprecated and will be removed in ARel 4.0.0 with no replacement" + Compatibility::Wheres.new @engine.connection, @ctx.wheres end def where_sql return if @ctx.wheres.empty? - viz = Visitors::WhereSql.new @engine.connection_pool + viz = Visitors::WhereSql.new @engine.connection Nodes::SqlLiteral.new viz.accept @ctx end @@ -214,7 +222,7 @@ module Arel end def order_clauses - visitor = Visitors::OrderClauses.new(@engine.connection_pool) + visitor = Visitors::OrderClauses.new(@engine.connection) visitor.accept(@ast).map { |x| Nodes::SqlLiteral.new x } @@ -230,7 +238,7 @@ module Arel def joins manager if $VERBOSE - warn "joins is deprecated and will be removed in 3.0.0" + warn "joins is deprecated and will be removed in 4.0.0" warn "please remove your call to joins from #{caller.first}" end manager.join_sql @@ -258,7 +266,7 @@ module Arel def insert values if $VERBOSE warn <<-eowarn -insert (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please +insert (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Please switch to `compile_insert` eowarn end diff --git a/lib/arel/table.rb b/lib/arel/table.rb index 82d160b87e..7a1983b3d2 100644 --- a/lib/arel/table.rb +++ b/lib/arel/table.rb @@ -32,7 +32,7 @@ module Arel def primary_key if $VERBOSE warn <<-eowarn -primary_key (#{caller.first}) is deprecated and will be removed in ARel 3.0.0 +primary_key (#{caller.first}) is deprecated and will be removed in ARel 4.0.0 eowarn end @primary_key ||= begin @@ -54,7 +54,7 @@ primary_key (#{caller.first}) is deprecated and will be removed in ARel 3.0.0 def joins manager if $VERBOSE - warn "joins is deprecated and will be removed in 3.0.0" + warn "joins is deprecated and will be removed in 4.0.0" warn "please remove your call to joins from #{caller.first}" end nil @@ -104,7 +104,7 @@ primary_key (#{caller.first}) is deprecated and will be removed in ARel 3.0.0 if $VERBOSE warn <<-eowarn (#{caller.first}) Arel::Table#columns is deprecated and will be removed in -Arel 3.0.0 with no replacement. PEW PEW PEW!!! +Arel 4.0.0 with no replacement. PEW PEW PEW!!! eowarn end @columns ||= @@ -138,7 +138,7 @@ Arel 3.0.0 with no replacement. PEW PEW PEW!!! if $VERBOSE warn <<-eowarn (#{caller.first}) Arel::Table.table_cache is deprecated and will be removed in -Arel 3.0.0 with no replacement. PEW PEW PEW!!! +Arel 4.0.0 with no replacement. PEW PEW PEW!!! eowarn end @@table_cache ||= Hash[engine.connection.tables.map { |x| [x,true] }] diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index b414234766..260cb6959f 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -4,30 +4,22 @@ require 'date' module Arel module Visitors class ToSql < Arel::Visitors::Visitor - def initialize pool - @pool = pool - @connection = nil + attr_accessor :last_column + + def initialize connection + @connection = connection + @schema_cache = connection.schema_cache @quoted_tables = {} @quoted_columns = {} + @last_column = nil end def accept object self.last_column = nil - @pool.with_connection do |conn| - @connection = conn - super - end + super end private - def last_column= col - Thread.current[:arel_visitors_to_sql_last_column] = col - end - - def last_column - Thread.current[:arel_visitors_to_sql_last_column] - end - def visit_Arel_Nodes_DeleteStatement o [ "DELETE FROM #{visit o.relation}", @@ -55,7 +47,7 @@ module Arel unless key warn(<<-eowarn) if $VERBOSE (#{caller.first}) Using UpdateManager without setting UpdateManager#key is -deprecated and support will be removed in ARel 3.0.0. Please set the primary +deprecated and support will be removed in ARel 4.0.0. Please set the primary key on UpdateManager using UpdateManager#key= eowarn key = o.relation.primary_key @@ -97,7 +89,7 @@ key on UpdateManager using UpdateManager#key= end def table_exists? name - @pool.table_exists? name + @schema_cache.table_exists? name end def column_for attr @@ -110,7 +102,7 @@ key on UpdateManager using UpdateManager#key= end def column_cache - @pool.columns_hash + @schema_cache.columns_hash end def visit_Arel_Nodes_Values o @@ -141,7 +133,7 @@ key on UpdateManager using UpdateManager#key= (visit(o.set_quantifier) if o.set_quantifier), ("#{o.projections.map { |x| visit x }.join ', '}" unless o.projections.empty?), ("FROM #{visit(o.source)}" if o.source && !o.source.empty?), - ("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.empty?), + ("WHERE #{o.wheres.map { |x| accept x }.join ' AND ' }" unless o.wheres.empty?), ("GROUP BY #{o.groups.map { |x| visit x }.join ', ' }" unless o.groups.empty?), (visit(o.having) if o.having), ].compact.join ' ' @@ -387,7 +379,9 @@ key on UpdateManager using UpdateManager#key= alias :visit_Bignum :literal alias :visit_Fixnum :literal - def quoted o; quote(o, last_column) end + def quoted o + quote(o, last_column) + end alias :visit_ActiveSupport_Multibyte_Chars :quoted alias :visit_ActiveSupport_StringInquirer :quoted |