Module: ActiveRecord::ConnectionAdapters

Extended by:
ActiveSupport::Autoload
Defined in:
lib/active_record/connection_adapters/column.rb,
lib/active_record/connection_adapters.rb,
lib/active_record/connection_adapters/pool_config.rb,
lib/active_record/connection_adapters/deduplicable.rb,
lib/active_record/connection_adapters/mysql/column.rb,
lib/active_record/connection_adapters/pool_manager.rb,
lib/active_record/connection_adapters/schema_cache.rb,
lib/active_record/connection_adapters/mysql/quoting.rb,
lib/active_record/connection_adapters/mysql2_adapter.rb,
lib/active_record/connection_adapters/postgresql/oid.rb,
lib/active_record/connection_adapters/sqlite3/column.rb,
lib/active_record/connection_adapters/statement_pool.rb,
lib/active_record/connection_adapters/sqlite3/quoting.rb,
lib/active_record/connection_adapters/sqlite3_adapter.rb,
lib/active_record/connection_adapters/trilogy_adapter.rb,
lib/active_record/connection_adapters/abstract/quoting.rb,
lib/active_record/connection_adapters/abstract_adapter.rb,
lib/active_record/connection_adapters/postgresql/utils.rb,
lib/active_record/connection_adapters/postgresql/column.rb,
lib/active_record/connection_adapters/sql_type_metadata.rb,
lib/active_record/connection_adapters/postgresql/oid/bit.rb,
lib/active_record/connection_adapters/postgresql/oid/oid.rb,
lib/active_record/connection_adapters/postgresql/oid/xml.rb,
lib/active_record/connection_adapters/postgresql/quoting.rb,
lib/active_record/connection_adapters/postgresql_adapter.rb,
lib/active_record/connection_adapters/abstract/savepoints.rb,
lib/active_record/connection_adapters/mysql/schema_dumper.rb,
lib/active_record/connection_adapters/mysql/type_metadata.rb,
lib/active_record/connection_adapters/postgresql/oid/cidr.rb,
lib/active_record/connection_adapters/postgresql/oid/date.rb,
lib/active_record/connection_adapters/postgresql/oid/enum.rb,
lib/active_record/connection_adapters/postgresql/oid/inet.rb,
lib/active_record/connection_adapters/postgresql/oid/uuid.rb,
lib/active_record/connection_adapters/abstract/query_cache.rb,
lib/active_record/connection_adapters/abstract/transaction.rb,
lib/active_record/connection_adapters/postgresql/oid/array.rb,
lib/active_record/connection_adapters/postgresql/oid/bytea.rb,
lib/active_record/connection_adapters/postgresql/oid/jsonb.rb,
lib/active_record/connection_adapters/postgresql/oid/money.rb,
lib/active_record/connection_adapters/postgresql/oid/point.rb,
lib/active_record/connection_adapters/postgresql/oid/range.rb,
lib/active_record/connection_adapters/mysql/schema_creation.rb,
lib/active_record/connection_adapters/postgresql/oid/hstore.rb,
lib/active_record/connection_adapters/postgresql/oid/vector.rb,
lib/active_record/connection_adapters/sqlite3/schema_dumper.rb,
lib/active_record/connection_adapters/abstract/schema_dumper.rb,
lib/active_record/connection_adapters/abstract_mysql_adapter.rb,
lib/active_record/connection_adapters/postgresql/oid/decimal.rb,
lib/active_record/connection_adapters/postgresql/oid/macaddr.rb,
lib/active_record/connection_adapters/mysql/schema_statements.rb,
lib/active_record/connection_adapters/postgresql/oid/interval.rb,
lib/active_record/connection_adapters/sqlite3/schema_creation.rb,
lib/active_record/connection_adapters/abstract/connection_pool.rb,
lib/active_record/connection_adapters/abstract/database_limits.rb,
lib/active_record/connection_adapters/abstract/schema_creation.rb,
lib/active_record/connection_adapters/mysql/schema_definitions.rb,
lib/active_record/connection_adapters/postgresql/oid/date_time.rb,
lib/active_record/connection_adapters/postgresql/oid/timestamp.rb,
lib/active_record/connection_adapters/postgresql/schema_dumper.rb,
lib/active_record/connection_adapters/postgresql/type_metadata.rb,
lib/active_record/connection_adapters/mysql/database_statements.rb,
lib/active_record/connection_adapters/sqlite3/schema_statements.rb,
lib/active_record/connection_adapters/abstract/schema_statements.rb,
lib/active_record/connection_adapters/mysql2/database_statements.rb,
lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb,
lib/active_record/connection_adapters/postgresql/schema_creation.rb,
lib/active_record/connection_adapters/sqlite3/schema_definitions.rb,
lib/active_record/connection_adapters/abstract/connection_handler.rb,
lib/active_record/connection_adapters/abstract/schema_definitions.rb,
lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb,
lib/active_record/connection_adapters/sqlite3/database_statements.rb,
lib/active_record/connection_adapters/trilogy/database_statements.rb,
lib/active_record/connection_adapters/abstract/database_statements.rb,
lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb,
lib/active_record/connection_adapters/postgresql/schema_statements.rb,
lib/active_record/connection_adapters/postgresql/schema_definitions.rb,
lib/active_record/connection_adapters/abstract/connection_pool/queue.rb,
lib/active_record/connection_adapters/postgresql/database_statements.rb,
lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb,
lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb,
lib/active_record/connection_adapters/postgresql/referential_integrity.rb,
lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb,
lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb,
lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb,
lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb

Overview

:nodoc:

Defined Under Namespace

Modules: AbstractPool, ColumnMethods, DatabaseLimits, DatabaseStatements, Deduplicable, MySQL, Mysql2, PostgreSQL, QueryCache, Quoting, SQLite3, Savepoints, SchemaStatements, Trilogy Classes: AbstractAdapter, AbstractMysqlAdapter, AddColumnDefinition, AlterTable, BoundSchemaReflection, ChangeColumnDefaultDefinition, ChangeColumnDefinition, CheckConstraintDefinition, Column, ColumnDefinition, ConnectionHandler, ConnectionPool, CreateIndexDefinition, ForeignKeyDefinition, IndexDefinition, Mysql2Adapter, NullColumn, NullPool, NullTransaction, PoolConfig, PoolManager, PostgreSQLAdapter, PrimaryKeyDefinition, RealTransaction, ReferenceDefinition, RestartParentTransaction, SQLite3Adapter, SavepointTransaction, SchemaCache, SchemaCreation, SchemaDumper, SchemaReflection, SqlTypeMetadata, StatementPool, Table, TableDefinition, Transaction, TransactionInstrumenter, TransactionManager, TransactionState, TrilogyAdapter

Constant Summary collapse

PostgreSQLColumn =

:nodoc:

PostgreSQL::Column
PostgreSQLTypeMetadata =
PostgreSQL::TypeMetadata

Class Method Summary collapse

Class Method Details

.register(name, class_name, path = class_name.underscore) ⇒ Object

Registers a custom database adapter.

Can also be used to define aliases.

Example

ActiveRecord::ConnectionAdapters.register("megadb", "MegaDB::ActiveRecordAdapter", "mega_db/active_record_adapter")

ActiveRecord::ConnectionAdapters.register("mysql", "ActiveRecord::ConnectionAdapters::TrilogyAdapter", "active_record/connection_adapters/trilogy_adapter")


22
23
24
# File 'lib/active_record/connection_adapters.rb', line 22

def register(name, class_name, path = class_name.underscore)
  @adapters[name.to_s] = [class_name, path]
end

.resolve(adapter_name) ⇒ Object

:nodoc:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/active_record/connection_adapters.rb', line 26

def resolve(adapter_name) # :nodoc:
  # Require the adapter itself and give useful feedback about
  #   1. Missing adapter gems.
  #   2. Incorrectly registered adapters.
  #   3. Adapter gems' missing dependencies.
  class_name, path_to_adapter = @adapters[adapter_name.to_s]

  unless class_name
    raise AdapterNotFound, <<~MSG.squish
      Database configuration specifies nonexistent '#{adapter_name}' adapter.
      Available adapters are: #{@adapters.keys.sort.join(", ")}.
      Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary
      adapter gem to your Gemfile if it's not in the list of available adapters.
    MSG
  end

  unless Object.const_defined?(class_name)
    begin
      require path_to_adapter
    rescue LoadError => error
      # We couldn't require the adapter itself.
      if error.path == path_to_adapter
        # We can assume here that a non-builtin adapter was specified and the path
        # registered by the adapter gem is incorrect.
        raise LoadError, "Error loading the '#{adapter_name}' Active Record adapter. Ensure that the path registered by the adapter gem is correct. #{error.message}", error.backtrace
      else
        # Bubbled up from the adapter require. Prefix the exception message
        # with some guidance about how to address it and reraise.
        raise LoadError, "Error loading the '#{adapter_name}' Active Record adapter. Missing a gem it depends on? #{error.message}", error.backtrace
      end
    end
  end

  begin
    Object.const_get(class_name)
  rescue NameError => error
    raise AdapterNotFound, "Could not load the #{class_name} Active Record adapter (#{error.message})."
  end
end