Skip to content

Commit

Permalink
Extract arel_visitor and move up to the abstract adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
kamipo committed Feb 6, 2016
1 parent c909a00 commit c3508bf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ def initialize(connection, logger = nil, config = {}) # :nodoc:
@config = config
@pool = nil
@schema_cache = SchemaCache.new self
@visitor = nil
@prepared_statements = false
@visitor = arel_visitor

if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
@prepared_statements = true
@visitor.extend(DetermineIfPreparableVisitor)
else
@prepared_statements = false
end
end

class Version
Expand Down Expand Up @@ -143,6 +149,10 @@ def collector
end
end

def arel_visitor # :nodoc:
(Arel::Visitors::VISITORS[@config[:adapter]] || Arel::Visitors::ToSql).new(self)
end

def valid_type?(type)
true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ def initialize(connection, logger, connection_options, config)
super(connection, logger, config)
@quoted_column_names, @quoted_table_names = {}, {}

@visitor = Arel::Visitors::MySQL.new self

if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
@prepared_statements = true
@visitor.extend(DetermineIfPreparableVisitor)
else
@prepared_statements = false
end

if version < '5.0.0'
raise "Your version of MySQL (#{full_version.match(/^\d+\.\d+\.\d+/)[0]}) is too old. Active Record supports MySQL >= 5.0."
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,6 @@ def connection_active?
def initialize(connection, logger, connection_parameters, config)
super(connection, logger, config)

@visitor = Arel::Visitors::PostgreSQL.new self
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
@prepared_statements = true
@visitor.extend(DetermineIfPreparableVisitor)
else
@prepared_statements = false
end

@connection_parameters = connection_parameters

# @local_tz is initialized as nil to avoid warnings when connect tries to use it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,7 @@ def initialize(connection, logger, connection_options, config)
@active = nil
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 }))

@visitor = Arel::Visitors::SQLite.new self
@quoted_column_names = {}

if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
@prepared_statements = true
@visitor.extend(DetermineIfPreparableVisitor)
else
@prepared_statements = false
end
end

def supports_ddl_transactions?
Expand Down

0 comments on commit c3508bf

Please sign in to comment.