aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/tree_manager.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/tree_manager.rb')
-rw-r--r--lib/arel/tree_manager.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/arel/tree_manager.rb b/lib/arel/tree_manager.rb
index 11d34ec138..4ee4a6f219 100644
--- a/lib/arel/tree_manager.rb
+++ b/lib/arel/tree_manager.rb
@@ -4,23 +4,31 @@ module Arel
include Arel::Relation
VISITORS = {
- 'postgresql' => Arel::Visitors::PostgreSQL
+ 'postgresql' => Arel::Visitors::PostgreSQL,
+ 'mysql' => Arel::Visitors::MySQL,
+ 'mysql2' => Arel::Visitors::MySQL,
}
+ attr_accessor :visitor
+
def initialize engine
- @engine = engine
- @pool = engine.connection_pool
- @adapter = @pool.spec.config[:adapter]
- @visitor_klass = VISITORS[@adapter] || Visitors::ToSql
+ @engine = engine
+ @visitor = nil
end
def to_dot
Visitors::Dot.new.accept @head
end
+ def visitor
+ return @visitor if @visitor
+ pool = @engine.connection_pool
+ adapter = pool.spec.config[:adapter]
+ @visitor = (VISITORS[adapter] || Visitors::ToSql).new(@engine)
+ end
+
def to_sql
- viz = @visitor_klass.new @engine
- viz.accept @head
+ visitor.accept @head
end
def initialize_copy other