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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fibered_mysql2/fibered_mysql2_connection_factory.rb', line 7

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::Client.new(config)
      rescue Mysql2::Error => error
        if error.message.include?("Unknown database")
          raise ActiveRecord::NoDatabaseError.new(error.message)
        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