Module: ActiveRecordProxyAdapters::PostgreSQL::ConnectionHandling

Defined in:
lib/active_record_proxy_adapters/connection_handling/postgresql_proxy.rb

Overview

rubocop:disable Style/Documentation

Instance Method Summary collapse

Instance Method Details

#postgresql_proxy_adapter_classObject



15
16
17
# File 'lib/active_record_proxy_adapters/connection_handling/postgresql_proxy.rb', line 15

def postgresql_proxy_adapter_class
  ::ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter
end

#postgresql_proxy_connection(config) ⇒ Object

This method is a copy and paste from Rails’ postgresql_connection, replacing PostgreSQLAdapter by PostgreSQLProxyAdapter This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_record_proxy_adapters/connection_handling/postgresql_proxy.rb', line 22

def postgresql_proxy_connection(config) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  conn_params = config.symbolize_keys.compact

  # Map ActiveRecords param names to PGs.
  conn_params[:user]   = conn_params.delete(:username) if conn_params[:username]
  conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]

  # Forward only valid config params to PG::Connection.connect.
  valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
  conn_params.slice!(*valid_conn_param_keys)

  postgresql_proxy_adapter_class.new(
    postgresql_proxy_adapter_class.new_client(conn_params),
    logger,
    conn_params,
    config
  )
end