Module: AdapterExtensions::MysqlAdapter
- Included in:
- ActiveRecord::ConnectionAdapters::Mysql2Adapter, ActiveRecord::ConnectionAdapters::MysqlAdapter
- Defined in:
- lib/adapter_extensions/adapters/mysql_adapter.rb
Instance Method Summary collapse
-
#add_select_into_table(new_table_name, sql_query) ⇒ Object
Inserts an INTO table_name clause to the sql_query.
-
#copy_table(old_table_name, new_table_name) ⇒ Object
Copy the specified table.
- #disable_keys(table) ⇒ Object
- #enable_keys(table) ⇒ Object
- #support_select_into_table? ⇒ Boolean
- #with_keys_disabled(table) ⇒ Object
Instance Method Details
#add_select_into_table(new_table_name, sql_query) ⇒ Object
Inserts an INTO table_name clause to the sql_query.
8 9 10 |
# File 'lib/adapter_extensions/adapters/mysql_adapter.rb', line 8 def add_select_into_table(new_table_name, sql_query) "CREATE TABLE #{new_table_name} " + sql_query end |
#copy_table(old_table_name, new_table_name) ⇒ Object
Copy the specified table.
13 14 15 16 17 18 |
# File 'lib/adapter_extensions/adapters/mysql_adapter.rb', line 13 def copy_table(old_table_name, new_table_name) transaction do execute "CREATE TABLE #{new_table_name} LIKE #{old_table_name}" execute "INSERT INTO #{new_table_name} SELECT * FROM #{old_table_name}" end end |
#disable_keys(table) ⇒ Object
20 21 22 |
# File 'lib/adapter_extensions/adapters/mysql_adapter.rb', line 20 def disable_keys(table) execute("ALTER TABLE #{table} DISABLE KEYS") end |
#enable_keys(table) ⇒ Object
24 25 26 |
# File 'lib/adapter_extensions/adapters/mysql_adapter.rb', line 24 def enable_keys(table) execute("ALTER TABLE #{table} ENABLE KEYS") end |
#support_select_into_table? ⇒ Boolean
3 4 5 |
# File 'lib/adapter_extensions/adapters/mysql_adapter.rb', line 3 def support_select_into_table? true end |
#with_keys_disabled(table) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/adapter_extensions/adapters/mysql_adapter.rb', line 28 def with_keys_disabled(table) disable_keys(table) yield ensure enable_keys(table) end |