Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Extended by:
Futures::Delegation
Defined in:
lib/activerecord-futures.rb,
lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb,
lib/active_record/connection_adapters/future_enabled_postgresql_adapter.rb

Defined Under Namespace

Classes: ConnectionSpecification

Class Method Summary collapse

Class Method Details

.future_enabled_mysql2_connection(config) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/active_record/connection_adapters/future_enabled_mysql2_adapter.rb', line 5

def self.future_enabled_mysql2_connection(config)
  config = config.symbolize_keys

  config[:username] = 'root' if config[:username].nil?

  if Mysql2::Client.const_defined? :FOUND_ROWS
    config[:flags] = Mysql2::Client::FOUND_ROWS | Mysql2::Client::MULTI_STATEMENTS
  end
  client = Mysql2::Client.new(config)
  options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
  ConnectionAdapters::FutureEnabledMysql2Adapter.new(client, logger, options, config)
end

.future_enabled_postgresql_connection(config) ⇒ Object

Establishes a connection to the database that’s used by all Active Record objects



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_record/connection_adapters/future_enabled_postgresql_adapter.rb', line 7

def self.future_enabled_postgresql_connection(config) # :nodoc:
  config = config.symbolize_keys
  host     = config[:host]
  port     = config[:port] || 5432
  username = config[:username].to_s if config[:username]
  password = config[:password].to_s if config[:password]

  if config.key?(:database)
    database = config[:database]
  else
    raise ArgumentError, "No database specified. Missing argument: database."
  end

  # The postgres drivers don't allow the creation of an unconnected PGconn object,
  # so just pass a nil connection object for the time being.
  ConnectionAdapters::FutureEnabledPostgreSQLAdapter.new(nil, logger, [host, port, nil, nil, database, username, password], config)
end