aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/nodes/node.rb3
-rw-r--r--lib/arel/select_manager.rb9
-rw-r--r--lib/arel/tree_manager.rb12
-rw-r--r--lib/arel/visitors/to_sql.rb6
4 files changed, 15 insertions, 15 deletions
diff --git a/lib/arel/nodes/node.rb b/lib/arel/nodes/node.rb
index 1a5bc27856..4faace3782 100644
--- a/lib/arel/nodes/node.rb
+++ b/lib/arel/nodes/node.rb
@@ -32,8 +32,7 @@ module Arel
#
# Maybe we should just use `Table.engine`? :'(
def to_sql engine = Table.engine
- viz = Visitors.for engine
- viz.accept self
+ engine.connection.visitor.accept self
end
# Iterate through AST, nodes will be yielded depth-first
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index d95a259177..dc80150957 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -149,13 +149,13 @@ module Arel
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, @ctx.wheres
+ Compatibility::Wheres.new @engine.connection_pool, @ctx.wheres
end
def where_sql
return if @ctx.wheres.empty?
- viz = Visitors::WhereSql.new @engine
+ viz = Visitors::WhereSql.new @engine.connection_pool
Nodes::SqlLiteral.new viz.accept @ctx
end
@@ -205,12 +205,13 @@ module Arel
def join_sql
return nil if @ctx.source.right.empty?
- sql = @visitor.dup.extend(Visitors::JoinSql).accept @ctx
+ sql = visitor.dup.extend(Visitors::JoinSql).accept @ctx
Nodes::SqlLiteral.new sql
end
def order_clauses
- Visitors::OrderClauses.new(@engine).accept(@ast).map { |x|
+ visitor = Visitors::OrderClauses.new(@engine.connection_pool)
+ visitor.accept(@ast).map { |x|
Nodes::SqlLiteral.new x
}
end
diff --git a/lib/arel/tree_manager.rb b/lib/arel/tree_manager.rb
index 5722baca77..99a7164e2e 100644
--- a/lib/arel/tree_manager.rb
+++ b/lib/arel/tree_manager.rb
@@ -4,21 +4,23 @@ module Arel
include Arel::Relation
include Arel::FactoryMethods
- attr_accessor :visitor
attr_reader :ast, :engine
def initialize engine
- @engine = engine
- @visitor = Visitors.visitor_for @engine
- @ctx = nil
+ @engine = engine
+ @ctx = nil
end
def to_dot
Visitors::Dot.new.accept @ast
end
+ def visitor
+ engine.connection.visitor
+ end
+
def to_sql
- @visitor.accept @ast
+ visitor.accept @ast
end
def initialize_copy other
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index ec62f4fb89..d424f8602e 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -4,17 +4,15 @@ require 'date'
module Arel
module Visitors
class ToSql < Arel::Visitors::Visitor
- def initialize engine
- @engine = engine
+ def initialize pool
+ @pool = pool
@connection = nil
- @pool = nil
@quoted_tables = {}
@quoted_columns = {}
end
def accept object
self.last_column = nil
- @pool = @engine.connection_pool
@pool.with_connection do |conn|
@connection = conn
super