Class: ActiveRecord::ConnectionAdapters::FutureEnabledMysql2Adapter

Inherits:
Mysql2Adapter
  • Object
show all
Includes:
FutureEnabled
Defined in:
lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb

Instance Method Summary collapse

Methods included from FutureEnabled

#exec_query

Constructor Details

#initialize(*args) ⇒ FutureEnabledMysql2Adapter

Returns a new instance of FutureEnabledMysql2Adapter.



23
24
25
26
27
28
29
30
31
# File 'lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb', line 23

def initialize(*args)
  super
  unless supports_futures?
    logger.warn("ActiveRecord::Futures - You're using the mysql2 future "\
      "enabled adapter with an old version of the mysql2 gem. You must "\
      "use a mysql2 gem version higher than or equal to 0.3.12b1 to take "\
      "advantage of futures.\nFalling back to normal query execution behavior.")
  end
end

Instance Method Details

#build_active_record_result(raw_result) ⇒ Object



44
45
46
# File 'lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb', line 44

def build_active_record_result(raw_result)
  ActiveRecord::Result.new(raw_result.fields, raw_result.to_a)
end

#future_execute(arels, binds, name) ⇒ Object



39
40
41
42
# File 'lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb', line 39

def future_execute(arels, binds, name)
  sql = arels.zip(binds).map { |arel, bind| to_sql(arel, bind.try(:dup)) }.join(';')
  execute(sql, name)
end

#next_resultObject



48
49
50
# File 'lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb', line 48

def next_result
  @connection.store_result if @connection.next_result
end

#supports_futures?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb', line 33

def supports_futures?
  # Support only if the mysql client allows fetching multiple statements
  # results
  @connection.respond_to?(:store_result)
end