跳至内容 跳至搜索
方法
A
C
D
N
P
S
T
包含的模块

常量

ADAPTER_NAME = "Trilogy"
 
ER_ACCESS_DENIED_ERROR = 1045
 
ER_BAD_DB_ERROR = 1049
 
ER_DBACCESS_DENIED_ERROR = 1044
 
SSL_MODES = { 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_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }
 

类公共方法

new(config, *)

# 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

new_client(config)

# 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

parse_ssl_mode(mode)

# 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

translate_connect_error(config, error)

# 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

实例公共方法

active?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 123
def active?
  connected? && @lock.synchronize { @raw_connection&.ping } || false
rescue ::Trilogy::Error
  false
end

connected?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 119
def connected?
  !(@raw_connection.nil? || @raw_connection.closed?)
end

discard!()

# 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

disconnect!()

# 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

savepoint_errors_invalidate_transactions?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 111
def savepoint_errors_invalidate_transactions?
  true
end

supports_comments?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 99
def supports_comments?
  true
end

supports_comments_in_create?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 103
def supports_comments_in_create?
  true
end

supports_json?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 95
def supports_json?
  !mariadb? && database_version >= "5.7.8"
end

supports_lazy_transactions?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 115
def supports_lazy_transactions?
  true
end

supports_savepoints?()

# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 107
def supports_savepoints?
  true
end