Class: ActiveRecord::ConnectionAdapters::DepartureAdapter
- Inherits:
-
AbstractMysqlAdapter
- Object
- AbstractMysqlAdapter
- ActiveRecord::ConnectionAdapters::DepartureAdapter
- Extended by:
- Forwardable
- Includes:
- ForAlterStatements
- Defined in:
- lib/active_record/connection_adapters/percona_adapter.rb
Defined Under Namespace
Classes: Column, SchemaCreation
Constant Summary collapse
- TYPE_MAP =
Type::TypeMap.new.tap { |m| initialize_type_map(m) }
- ADAPTER_NAME =
'Percona'.freeze
Instance Method Summary collapse
-
#add_index(table_name, column_name, options = {}) ⇒ Object
Adds a new index to the table.
- #change_table(table_name, _options = {}) {|update_table_definition(table_name, recorder)| ... } ⇒ Object
-
#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, returning: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument, Metrics/LineLength, Metrics/ParameterLists.
- #full_version ⇒ Object
-
#get_full_version ⇒ Object
This is a method defined in Rails 6.0, and we have no control over the naming of this method.
-
#initialize(connection, _logger, connection_options, _config) ⇒ DepartureAdapter
constructor
A new instance of DepartureAdapter.
-
#internal_exec_query(sql, name = 'SQL', _binds = [], **_kwargs) ⇒ Object
(also: #exec_query)
:nodoc:.
- #last_inserted_id(result) ⇒ Object
-
#new_column(field, default, type_metadata, null, table_name, default_function, collation, comment) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#remove_index(table_name, column_name = nil, **options) ⇒ Object
Remove the given index from the table.
- #schema_creation ⇒ Object
-
#select(sql, name = nil, binds = [], **kwargs) ⇒ 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(arel, name = nil, binds = []) ⇒ Object
Executes a SELECT query and returns an array of rows.
-
#supports_migrations? ⇒ Boolean
Returns true, as this adapter supports migrations.
-
#write_query?(sql) ⇒ Boolean
:nodoc:.
Methods included from ForAlterStatements
#add_column_for_alter, #add_index_for_alter, #add_timestamps_for_alter, #bulk_change_table, #change_column_for_alter, included, #remove_column_for_alter, #remove_columns_for_alter, #remove_index_for_alter, #remove_timestamps_for_alter, #rename_column_for_alter
Constructor Details
#initialize(connection, _logger, connection_options, _config) ⇒ DepartureAdapter
Returns a new instance of DepartureAdapter.
77 78 79 80 81 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 77 def initialize(connection, _logger, , _config) @mysql_adapter = [:mysql_adapter] super @prepared_statements = false end |
Instance Method Details
#add_index(table_name, column_name, options = {}) ⇒ Object
Adds a new index to the table
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 135 def add_index(table_name, column_name, = {}) if ActiveRecord::VERSION::STRING >= '6.1' index_definition, = (table_name, column_name, **) execute " ALTER TABLE \#{quote_table_name(index_definition.table)}\n ADD \#{schema_creation.accept(index_definition)}\n SQL\n else\n index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, **options)\n execute <<-SQL.squish\n ALTER TABLE \#{quote_table_name(table_name)}\n ADD \#{index_type} INDEX\n \#{quote_column_name(index_name)} (\#{index_columns})\#{index_options}\n SQL\n end\nend\n".squish |
#change_table(table_name, _options = {}) {|update_table_definition(table_name, recorder)| ... } ⇒ Object
171 172 173 174 175 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 171 def change_table(table_name, = {}) recorder = ActiveRecord::Migration::CommandRecorder.new(self) yield update_table_definition(table_name, recorder) bulk_change_table(table_name, recorder.commands) end |
#error_number(_exception) ⇒ Object
Returns the MySQL error number from the exception. The AbstractMysqlAdapter requires it to be implemented
179 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 179 def error_number(_exception); end |
#exec_delete(sql, name, binds) ⇒ Object Also known as: exec_update
89 90 91 92 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 89 def exec_delete(sql, name, binds) execute(to_sql(sql, binds), name) mysql_adapter.raw_connection.affected_rows end |
#exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument, Metrics/LineLength, Metrics/ParameterLists
95 96 97 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 95 def exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil) # rubocop:disable Lint/UnusedMethodArgument, Metrics/LineLength, Metrics/ParameterLists execute(to_sql(sql, binds), name) end |
#full_version ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 181 def full_version if ActiveRecord::VERSION::MAJOR < 6 get_full_version else schema_cache.database_version.full_version_string end end |
#get_full_version ⇒ Object
This is a method defined in Rails 6.0, and we have no control over the naming of this method.
191 192 193 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 191 def get_full_version # rubocop:disable Style/AccessorMethodName mysql_adapter.raw_connection.server_info[:version] end |
#internal_exec_query(sql, name = 'SQL', _binds = [], **_kwargs) ⇒ Object Also known as: exec_query
:nodoc:
99 100 101 102 103 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 99 def internal_exec_query(sql, name = 'SQL', _binds = [], **_kwargs) # :nodoc: result = execute(sql, name) fields = result.fields if defined?(result.fields) ActiveRecord::Result.new(fields, result.to_a) end |
#last_inserted_id(result) ⇒ Object
195 196 197 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 195 def last_inserted_id(result) mysql_adapter.send(:last_inserted_id, result) end |
#new_column(field, default, type_metadata, null, table_name, default_function, collation, comment) ⇒ Object
rubocop:disable Metrics/ParameterLists
125 126 127 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 125 def new_column(field, default, , null, table_name, default_function, collation, comment) Column.new(field, default, , null, table_name, default_function, collation, comment) end |
#remove_index(table_name, column_name = nil, **options) ⇒ Object
Remove the given index from the table.
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 156 def remove_index(table_name, column_name = nil, **) if ActiveRecord::VERSION::STRING >= '6.1' return if [:if_exists] && !index_exists?(table_name, column_name, **) index_name = index_name_for_remove(table_name, column_name, ) else index_name = index_name_for_remove(table_name, ) end execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}" end |
#schema_creation ⇒ Object
167 168 169 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 167 def schema_creation SchemaCreation.new(self) end |
#select(sql, name = nil, binds = [], **kwargs) ⇒ Object
Executes a SELECT query and returns an array of record hashes with the column names as keys and column values as values.
115 116 117 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 115 def select(sql, name = nil, binds = [], **kwargs) exec_query(sql, name, binds, **kwargs) end |
#select_rows(arel, name = nil, binds = []) ⇒ Object
Executes a SELECT query and returns an array of rows. Each row is an array of field values.
109 110 111 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 109 def select_rows(arel, name = nil, binds = []) select_all(arel, name, binds).rows end |
#supports_migrations? ⇒ Boolean
Returns true, as this adapter supports migrations
120 121 122 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 120 def supports_migrations? true end |
#write_query?(sql) ⇒ Boolean
:nodoc:
83 84 85 86 87 |
# File 'lib/active_record/connection_adapters/percona_adapter.rb', line 83 def write_query?(sql) # :nodoc: !ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp( :desc, :describe, :set, :show, :use ).match?(sql) end |