Class: ConsoleKit::Connections::SqlConnectionHandler

Inherits:
BaseConnectionHandler show all
Defined in:
lib/console_kit/connections/sql_connection_handler.rb

Overview

Handles SQL connections

Instance Attribute Summary

Attributes inherited from BaseConnectionHandler

#context

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseConnectionHandler

#initialize, registry, #safe_diagnostics

Methods included from DiagnosticHelpers

clock_time, error_diagnostics, timeout_diagnostics

Constructor Details

This class inherits a constructor from ConsoleKit::Connections::BaseConnectionHandler

Class Method Details

.base_class_nameObject



16
# File 'lib/console_kit/connections/sql_connection_handler.rb', line 16

def base_class_name = ConsoleKit.configuration.sql_base_class

.sql_version(conn) ⇒ Object



10
11
12
13
14
# File 'lib/console_kit/connections/sql_connection_handler.rb', line 10

def sql_version(conn)
  conn.select_value('SELECT version()')
rescue StandardError
  nil
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


26
# File 'lib/console_kit/connections/sql_connection_handler.rb', line 26

def available? = self.class.base_class_name.to_s.safe_constantize.present?

#connectObject



19
20
21
22
23
24
# File 'lib/console_kit/connections/sql_connection_handler.rb', line 19

def connect
  shard = context_attribute(:tenant_shard).presence&.to_sym
  Output.print_info("#{connection_message(shard)} via #{base_class}")
  disconnect_existing_pool
  shard ? base_class.establish_connection(shard) : base_class.establish_connection
end

#diagnosticsObject



28
29
30
31
32
33
34
# File 'lib/console_kit/connections/sql_connection_handler.rb', line 28

def diagnostics
  return unavailable_diagnostics('SQL') unless available?

  perform_diagnostics
rescue StandardError => e
  error_diagnostics('SQL', e)
end