Method: ActiveRecord::Import::SQLite3Adapter#insert_many

Defined in:
lib/activerecord-import/adapters/sqlite3_adapter.rb

#insert_many(sql, values, _options = {}, *args) ⇒ Object

sql can be a single string or an array. If it is an array all elements that are in position >= 1 will be appended to the final SQL.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/activerecord-import/adapters/sqlite3_adapter.rb', line 24

def insert_many( sql, values, _options = {}, *args ) # :nodoc:
  number_of_inserts = 0

  base_sql, post_sql = case sql
                       when String
                         [sql, '']
                       when Array
                         [sql.shift, sql.join( ' ' )]
  end

  value_sets = ::ActiveRecord::Import::ValueSetsRecordsParser.parse(values,
    max_records: SQLITE_LIMIT_COMPOUND_SELECT)

  transaction(requires_new: true) do
    value_sets.each do |value_set|
      number_of_inserts += 1
      sql2insert = base_sql + value_set.join( ',' ) + post_sql
      insert( sql2insert, *args )
    end
  end

  ActiveRecord::Import::Result.new([], number_of_inserts, [], [])
end