Module: FiberedMysql2::FiberedMysql2ConnectionFactory

Defined in:
lib/fibered_mysql2/fibered_mysql2_connection_factory.rb

Instance Method Summary collapse

Instance Method Details

#fibered_mysql2_connection(raw_config) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fibered_mysql2/fibered_mysql2_connection_factory.rb', line 105

def fibered_mysql2_connection(raw_config)
  config = raw_config.symbolize_keys

  config[:username] = 'root' if config[:username].nil?
  config[:flags]    = Mysql2::Client::FOUND_ROWS if Mysql2::Client.const_defined?(:FOUND_ROWS)

  client =
      begin
        Mysql2::EM::Client.new(config)
      rescue Mysql2::Error => error
        if error.message.include?("Unknown database")
          raise ActiveRecord::NoDatabaseError.new(error.message, error)
        else
          raise
        end
      end

  options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
  FiberedMysql2Adapter.new(client, logger, options, config)
end