Sha256: 024288a373a77b4d0b37341321e47b6136cebd337644c65b08b07dac77f640a4

Contents?: true

Size: 470 Bytes

Versions: 3

Compression:

Stored size: 470 Bytes

Contents

class BatchInsert
  include FromHash
  attr_accessor :rows, :table_name
  fattr(:column_names) { rows.first.sorted_column_names }
  fattr(:values_sql) do
    "VALUES " + rows.map { |x| x.insert_values_sql }.join(", ")
  end
  fattr(:columns_sql) do
    "(" + column_names.join(", ") + ")"
  end
  fattr(:insert_sql) do
    "INSERT into #{table_name} #{columns_sql} #{values_sql};"
  end
  def insert!
    ActiveRecord::Base.connection.execute(insert_sql) 
  end
end
    

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
GFunk911-dataload-0.8.0 lib/dataload/batch_insert.rb
GFunk911-dataload-0.8.1 lib/dataload/batch_insert.rb
GFunk911-dataload-0.8.2 lib/dataload/batch_insert.rb