Methods
- active?
- connected?
- discard!
- disconnect!
- new
- new_client
- parse_ssl_mode
- savepoint_errors_invalidate_transactions?
- supports_comments?
- supports_comments_in_create?
- supports_json?
- supports_lazy_transactions?
- supports_savepoints?
- translate_connect_error
Included Modules
Constants
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) } |
Class Public methods
new(config, *)
📝 Source code
# 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
🔎 See on GitHub
new_client(config)
📝 Source code
# 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
🔎 See on GitHub
parse_ssl_mode(mode)
📝 Source code
# 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
🔎 See on GitHub
translate_connect_error(config, error)
📝 Source code
# 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
🔎 See on GitHub
Instance Public methods
active?()
📝 Source code
# 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
🔎 See on GitHub
connected?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 119
def connected?
!(@raw_connection.nil? || @raw_connection.closed?)
end
🔎 See on GitHub
discard!()
📝 Source code
# 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
🔎 See on GitHub
disconnect!()
📝 Source code
# 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
🔎 See on GitHub
savepoint_errors_invalidate_transactions?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 111
def savepoint_errors_invalidate_transactions?
true
end
🔎 See on GitHub
supports_comments?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 99
def supports_comments?
true
end
🔎 See on GitHub
supports_comments_in_create?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 103
def supports_comments_in_create?
true
end
🔎 See on GitHub
supports_json?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 95
def supports_json?
!mariadb? && database_version >= "5.7.8"
end
🔎 See on GitHub
supports_lazy_transactions?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 115
def supports_lazy_transactions?
true
end
🔎 See on GitHub
supports_savepoints?()
📝 Source code
# File activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb, line 107
def supports_savepoints?
true
end
🔎 See on GitHub