Method: Sequel::Dataset#multi_insert

Defined in:
lib/sequel/dataset/actions.rb

#multi_insert(hashes, opts = OPTS) ⇒ Object

This is a front end for import that allows you to submit an array of hashes instead of arrays of columns and values:

DB[:table].multi_insert([{:x => 1}, {:x => 2}])
# INSERT INTO table (x) VALUES (1)
# INSERT INTO table (x) VALUES (2)

Be aware that all hashes should have the same keys if you use this calling method, otherwise some columns could be missed or set to null instead of to default values.

This respects the same options as #import.



430
431
432
433
434
# File 'lib/sequel/dataset/actions.rb', line 430

def multi_insert(hashes, opts=OPTS)
  return if hashes.empty?
  columns = hashes.first.keys
  import(columns, hashes.map{|h| columns.map{|c| h[c]}}, opts)
end