Class: ActiveRecord::ConnectionAdapters::PerconaMigratorAdapter

Inherits:
AbstractMysqlAdapter
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/active_record/connection_adapters/percona_adapter.rb

Defined Under Namespace

Classes: Column

Constant Summary collapse

ADAPTER_NAME =
'Percona'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(connection, _logger, connection_options, _config) ⇒ PerconaMigratorAdapter

Returns a new instance of PerconaMigratorAdapter.



56
57
58
59
60
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 56

def initialize(connection, _logger, connection_options, _config)
  super
  @prepared_statements = false
  @mysql_adapter = connection_options[:mysql_adapter]
end

Instance Method Details

#add_index(table_name, column_name, options = {}) ⇒ Object

Adds a new index to the table

Parameters:

  • table_name (String, Symbol)
  • column_name (String, Symbol)
  • options (Hash) (defaults to: {})

    optional



103
104
105
106
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 103

def add_index(table_name, column_name, options = {})
  index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, options)
  execute "ALTER TABLE #{quote_table_name(table_name)} ADD #{index_type} INDEX #{quote_column_name(index_name)} (#{index_columns})#{index_options}"
end

#error_number(_exception) ⇒ Object

Returns the MySQL error number from the exception. The AbstractMysqlAdapter requires it to be implemented



119
120
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 119

def error_number(_exception)
end

#exec_delete(sql, name, binds) ⇒ Object Also known as: exec_update



62
63
64
65
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 62

def exec_delete(sql, name, binds)
  execute(to_sql(sql, binds), name)
  @connection.affected_rows
end

#exec_insert(sql, name, binds, pk = nil, sequence_name = nil) ⇒ Object



68
69
70
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 68

def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
  execute(to_sql(sql, binds), name)
end

#exec_query(sql, name = 'SQL', _binds = []) ⇒ Object



72
73
74
75
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 72

def exec_query(sql, name = 'SQL', _binds = [])
  result = execute(sql, name)
  ActiveRecord::Result.new(result.fields, result.to_a)
end

#full_versionObject



122
123
124
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 122

def full_version
  mysql_adapter.raw_connection.server_info[:version]
end

#new_column(field, default, cast_type, sql_type = nil, null = true, collation = '', extra = '') ⇒ Object



94
95
96
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 94

def new_column(field, default, cast_type, sql_type = nil, null = true, collation = '', extra = '')
  Column.new(field, default, cast_type, sql_type, null, collation, strict_mode?, extra)
end

#remove_index(table_name, options = {}) ⇒ Object

Remove the given index from the table.

Parameters:

  • table_name (String, Symbol)
  • options (Hash) (defaults to: {})

    optional



112
113
114
115
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 112

def remove_index(table_name, options = {})
  index_name = index_name_for_remove(table_name, options)
  execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}"
end

#select(sql, name = nil, binds = []) ⇒ Object

Executes a SELECT query and returns an array of record hashes with the column names as keys and column values as values.



85
86
87
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 85

def select(sql, name = nil, binds = [])
  exec_query(sql, name, binds)
end

#select_rows(sql, name = nil) ⇒ Object

Executes a SELECT query and returns an array of rows. Each row is an array of field values.



79
80
81
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 79

def select_rows(sql, name = nil)
  execute(sql, name).to_a
end

#supports_migrations?Boolean

Returns true, as this adapter supports migrations

Returns:

  • (Boolean)


90
91
92
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 90

def supports_migrations?
  true
end