Module: BulkInsert::ClassMethods
- Defined in:
- lib/bulk_insert.rb
Instance Method Summary collapse
- #bulk_insert(*columns, values: nil, set_size: 500, ignore: false, update_duplicates: false, return_primary_keys: false) ⇒ Object
-
#default_bulk_columns ⇒ Object
helper method for preparing the columns before a call to :bulk_insert.
Instance Method Details
#bulk_insert(*columns, values: nil, set_size: 500, ignore: false, update_duplicates: false, return_primary_keys: false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bulk_insert.rb', line 7 def bulk_insert(*columns, values: nil, set_size:500, ignore: false, update_duplicates: false, return_primary_keys: false) columns = default_bulk_columns if columns.empty? worker = BulkInsert::Worker.new(connection, table_name, primary_key, columns, set_size, ignore, update_duplicates, return_primary_keys) if values.present? transaction do worker.add_all(values) worker.save! end nil elsif block_given? transaction do yield worker worker.save! end nil else worker end end |
#default_bulk_columns ⇒ Object
helper method for preparing the columns before a call to :bulk_insert
29 30 31 |
# File 'lib/bulk_insert.rb', line 29 def default_bulk_columns self.column_names - %w(id) end |