Class: ActiveRecord::ConnectionAdapters::DepartureAdapter
- Inherits:
-
AbstractMysqlAdapter
- Object
- AbstractMysqlAdapter
- ActiveRecord::ConnectionAdapters::DepartureAdapter
- 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
-
#add_index(table_name, column_name, options = {}) ⇒ Object
Adds a new index to the table.
-
#error_number(_exception) ⇒ Object
Returns the MySQL error number from the exception.
- #exec_delete(sql, name, binds) ⇒ Object (also: #exec_update)
- #exec_insert(sql, name, binds, pk = nil, sequence_name = nil) ⇒ Object
- #exec_query(sql, name = 'SQL', _binds = []) ⇒ Object
-
#initialize(connection, _logger, connection_options, _config) ⇒ DepartureAdapter
constructor
A new instance of DepartureAdapter.
- #new_column(field, default, type, null, collation, extra = "") ⇒ Object
-
#remove_index(table_name, options = {}) ⇒ Object
Remove the given index from the table.
-
#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.
-
#select_rows(sql, name = nil) ⇒ Object
Executes a SELECT query and returns an array of rows.
-
#supports_migrations? ⇒ Boolean
Returns true, as this adapter supports migrations.
Constructor Details
#initialize(connection, _logger, connection_options, _config) ⇒ DepartureAdapter
Returns a new instance of DepartureAdapter.
57 58 59 60 61 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 57 def initialize(connection, _logger, , _config) super @visitor = BindSubstitution.new(self) @mysql_adapter = [:mysql_adapter] end |
Instance Method Details
#add_index(table_name, column_name, options = {}) ⇒ Object
Adds a new index to the table
104 105 106 107 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 104 def add_index(table_name, column_name, = {}) index_name, index_type, index_columns, = (table_name, column_name, ) execute "ALTER TABLE #{quote_table_name(table_name)} ADD #{index_type} INDEX #{quote_column_name(index_name)} (#{index_columns})#{}" end |
#error_number(_exception) ⇒ Object
Returns the MySQL error number from the exception. The AbstractMysqlAdapter requires it to be implemented
120 121 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 120 def error_number(_exception) end |
#exec_delete(sql, name, binds) ⇒ Object Also known as: exec_update
63 64 65 66 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 63 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
69 70 71 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 69 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
73 74 75 76 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 73 def exec_query(sql, name = 'SQL', _binds = []) result = execute(sql, name) ActiveRecord::Result.new(result.fields, result.to_a) end |
#new_column(field, default, type, null, collation, extra = "") ⇒ Object
95 96 97 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 95 def new_column(field, default, type, null, collation, extra = "") Column.new(field, default, type, null, collation, extra) end |
#remove_index(table_name, options = {}) ⇒ Object
Remove the given index from the table.
113 114 115 116 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 113 def remove_index(table_name, = {}) index_name = index_name_for_remove(table_name, ) 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.
86 87 88 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 86 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.
80 81 82 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 80 def select_rows(sql, name = nil) execute(sql, name).to_a end |
#supports_migrations? ⇒ Boolean
Returns true, as this adapter supports migrations
91 92 93 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 91 def supports_migrations? true end |