Class: Lhm::ChunkInsert
- Inherits:
-
Object
- Object
- Lhm::ChunkInsert
- Defined in:
- lib/lhm/chunk_insert.rb
Constant Summary collapse
- LOG_PREFIX =
"ChunkInsert"
Instance Method Summary collapse
-
#initialize(migration, connection, lowest, highest, retry_options = {}) ⇒ ChunkInsert
constructor
A new instance of ChunkInsert.
- #insert_and_return_count_of_rows_created ⇒ Object
- #sql ⇒ Object
Constructor Details
#initialize(migration, connection, lowest, highest, retry_options = {}) ⇒ ChunkInsert
Returns a new instance of ChunkInsert.
9 10 11 12 13 14 15 |
# File 'lib/lhm/chunk_insert.rb', line 9 def initialize(migration, connection, lowest, highest, = {}) @migration = migration @connection = connection @lowest = lowest @highest = highest @retry_options = end |
Instance Method Details
#insert_and_return_count_of_rows_created ⇒ Object
17 18 19 |
# File 'lib/lhm/chunk_insert.rb', line 17 def insert_and_return_count_of_rows_created @connection.update(sql, should_retry: true, log_prefix: LOG_PREFIX) end |
#sql ⇒ Object
21 22 23 24 25 |
# File 'lib/lhm/chunk_insert.rb', line 21 def sql "insert ignore into `#{ @migration.destination_name }` (#{ @migration.destination_columns }) " \ "select #{ @migration.origin_columns } from `#{ @migration.origin_name }` " \ "#{ conditions } `#{ @migration.origin_name }`.`id` between #{ @lowest } and #{ @highest }" end |