Class: ActiveRecordDataLoader::BulkInsertStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_data_loader/bulk_insert_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_generator, file_adapter) ⇒ BulkInsertStrategy

Returns a new instance of BulkInsertStrategy.



5
6
7
8
# File 'lib/active_record_data_loader/bulk_insert_strategy.rb', line 5

def initialize(data_generator, file_adapter)
  @data_generator = data_generator
  @file_adapter = file_adapter
end

Instance Method Details

#load_batch(row_numbers, connection) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/active_record_data_loader/bulk_insert_strategy.rb', line 10

def load_batch(row_numbers, connection)
  command = <<~SQL
    INSERT INTO #{quoted_table_name(connection)} (#{column_list(connection)})
    VALUES #{values(row_numbers, connection)}
  SQL
  insert(connection: connection, command: command)
  file_adapter.insert(command)
end

#nameObject



23
24
25
# File 'lib/active_record_data_loader/bulk_insert_strategy.rb', line 23

def name
  "BULK INSERT"
end

#table_nameObject



19
20
21
# File 'lib/active_record_data_loader/bulk_insert_strategy.rb', line 19

def table_name
  data_generator.table
end