Spec-Zone.ru › Ruby on Rails 7.0

класс ActiveRecord::ConnectionAdapters::Mysql2Adapter

Родитель:
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
Включенные модули:
ActiveRecord::ConnectionAdapters::MySQL::DatabaseStatements

Константы

ADAPTER_NAME
ER_ACCESS_DENIED_ERROR
ER_BAD_DB_ERROR
ER_CONN_HOST_ERROR
ER_UNKNOWN_HOST_ERROR

Публичные методы класса

database_exists?(config) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 64
def self.database_exists?(config)
  !!ActiveRecord::Base.mysql2_connection(config)
rescue ActiveRecord::NoDatabaseError
  false
end
new(connection, logger, connection_options, config) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 58
def initialize(connection, logger, connection_options, config)
  superclass_config = config.reverse_merge(prepared_statements: false)
  super(connection, logger, connection_options, superclass_config)
  configure_connection
end
Вызывает метод родительского класса ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::new
new_client(config) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 43
def new_client(config)
  Mysql2::Client.new(config)
rescue Mysql2::Error => error
  if error.error_number == ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
    raise ActiveRecord::NoDatabaseError.db_error(config[:database])
  elsif error.error_number == ConnectionAdapters::Mysql2Adapter::ER_ACCESS_DENIED_ERROR
    raise ActiveRecord::DatabaseConnectionError.username_error(config[:username])
  elsif [ConnectionAdapters::Mysql2Adapter::ER_CONN_HOST_ERROR, ConnectionAdapters::Mysql2Adapter::ER_UNKNOWN_HOST_ERROR].include?(error.error_number)
    raise ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
  else
    raise ActiveRecord::ConnectionNotEstablished, error.message
  end
end

Публичные методы экземпляра

active?() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 118
def active?
  @connection.ping
end
disconnect!() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 131
def disconnect!
  super
  @connection.close
end

Отключается от базы данных, если уже подключен. В противном случае, этот метод ничего не делает.

Вызывает метод родительского класса ActiveRecord::ConnectionAdapters::AbstractAdapter#disconnect!
error_number(exception) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 100
def error_number(exception)
  exception.error_number if exception.respond_to?(:error_number)
end
quote_string(string) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 108
def quote_string(string)
  @connection.escape(string)
rescue Mysql2::Error => error
  raise translate_exception(error, message: error.message, sql: "<escape>", binds: [])
end
reconnect!() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 122
def reconnect!
  super
  disconnect!
  connect
end
Вызывает метод родительского класса ActiveRecord::ConnectionAdapters::AbstractAdapter#reconnect!
Также является алиасом для: reset!
reset!()
Псевдоним для: reconnect!
supports_comments?() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 74
def supports_comments?
  true
end
supports_comments_in_create?() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 78
def supports_comments_in_create?
  true
end
supports_json?() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 70
def supports_json?
  !mariadb? && database_version >= "5.7.8"
end
supports_lazy_transactions?() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 86
def supports_lazy_transactions?
  true
end
supports_savepoints?() Показать исходный код
# File activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb, line 82
def supports_savepoints?
  true
end

© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API