Skip to Content Skip to Search

class ActiveRecord::ConnectionAdapters::TrilogyAdapter

Inherits From

Constants

"Trilogy"
1045
1049
1044
{
SSL_MODE_DISABLED: ::Trilogy::SSL_DISABLED,
SSL_MODE_PREFERRED: ::Trilogy::SSL_PREFERRED_NOVERIFY,
SSL_MODE_REQUIRED: ::Trilogy::SSL_REQUIRED_NOVERIFY,
SSL_MODE_VERIFY_CA: ::Trilogy::SSL_VERIFY_CA,
SSL_MODE_VERIFY_IDENTITY: ::Trilogy::SSL_VERIFY_IDENTITY
}.freeze
Type::TypeMap.new.tap { |m| initialize_type_map(m) }

Public class methods

Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 75
def initialize(config, *)
  config = config.dup

  # Trilogy ignores `socket` if `host is set. We want the opposite to allow
  # configuring UNIX domain sockets via `DATABASE_URL`.
  config.delete(:host) if config[:socket]

  # Set FOUND_ROWS capability on the connection so UPDATE queries returns number of rows
  # matched rather than number of rows updated.
  config[:found_rows] = true

  if config[:prepared_statements]
    raise ArgumentError, "Trilogy currently doesn't support prepared statements. Remove `prepared_statements: true` from your database configuration."
  end

  super
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 30
def new_client(config)
  config[:ssl_mode] = parse_ssl_mode(config[:ssl_mode]) if config[:ssl_mode]
  ::Trilogy.new(config)
rescue ::Trilogy::Error => error
  raise translate_connect_error(config, error)
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 37
def parse_ssl_mode(mode)
  return mode if mode.is_a? Integer

  m = mode.to_s.upcase
  m = "SSL_MODE_#{m}" unless m.start_with? "SSL_MODE_"

  SSL_MODES.fetch(m.to_sym, mode)
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 46
def translate_connect_error(config, error)
  case error.error_code
  when ER_DBACCESS_DENIED_ERROR, ER_BAD_DB_ERROR
    ActiveRecord::NoDatabaseError.db_error(config[:database])
  when ER_ACCESS_DENIED_ERROR
    ActiveRecord::DatabaseConnectionError.username_error(config[:username])
  else
    if error.message.include?("TRILOGY_DNS_ERROR")
      ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
    else
      ActiveRecord::ConnectionNotEstablished.new(error.message)
    end
  end
end

Public instance methods

Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 123
def active?
  connected? && @lock.synchronize { @raw_connection&.ping; verified! } || false
rescue ::Trilogy::Error
  false
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 119
def connected?
  !(@raw_connection.nil? || @raw_connection.closed?)
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 139
def discard!
  @lock.synchronize do
    super
    @raw_connection&.discard!
    @raw_connection = nil
  end
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 131
def disconnect!
  @lock.synchronize do
    super
    @raw_connection&.close
    @raw_connection = nil
  end
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 111
def savepoint_errors_invalidate_transactions?
  true
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 99
def supports_comments?
  true
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 103
def supports_comments_in_create?
  true
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 95
def supports_json?
  !mariadb? && database_version >= "5.7.8"
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 115
def supports_lazy_transactions?
  true
end
Source code GitHub
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 107
def supports_savepoints?
  true
end

Definition files