Module: ActiveRecord::ConnectionHandling

Defined in:
lib/active_record/connection_adapters/7.1/postgres_cipherstash_adapter.rb,
lib/active_record/connection_adapters/6.1/postgres_cipherstash_adapter.rb,
lib/active_record/connection_adapters/7.0/postgres_cipherstash_adapter.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#postgres_cipherstash_connection(config) ⇒ Object

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/active_record/connection_adapters/7.1/postgres_cipherstash_adapter.rb', line 41

def postgres_cipherstash_connection(config)
  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 ::CipherStashPG::Connection.connect.
  valid_conn_param_keys = ::CipherStashPG::Connection.conndefaults_hash.keys + [:requiressl]
  conn_params.slice!(*valid_conn_param_keys)

  ConnectionAdapters::CipherStashPGAdapter.new(
    ConnectionAdapters::CipherStashPGAdapter.new_client(conn_params),
    logger,
    conn_params,
    config,
  )
end

#postgresql_adapter_classObject

Everything from this point onwards is a copy-paste or inherit from Rails’ activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb with some changes

The changes besides name changes include:

* ore_64_8_v1_term and ore_64_8_v1 are registered
* column_definitions maps with CipherStashColumnMapper.map_column_definitions

(We can’t just inherit from PostgreSQLAdapter because we cannot load the

postgresql_adapter.rb file; that would load 'pg', and we cannot [right
now] have both 'cipherstash-pg' and 'pg' loaded at the same time.)


36
37
38
# File 'lib/active_record/connection_adapters/7.1/postgres_cipherstash_adapter.rb', line 36

def postgresql_adapter_class
  ConnectionAdapters::CipherStashPGAdapter
end