Module: Populator::Adapters::Sqlite

Included in:
ActiveRecord::ConnectionAdapters::SQLiteAdapter
Defined in:
lib/populator/adapters/sqlite.rb

Instance Method Summary collapse

Instance Method Details

#execute_batch(sql, name = nil) ⇒ Object

Executes multiple SQL statements in one query when joined with “;”



5
6
7
8
9
# File 'lib/populator/adapters/sqlite.rb', line 5

def execute_batch(sql, name = nil)
  log(sql, name) do
    @connection.transaction { |db| db.execute_batch(sql) }
  end
end

#populate(table, columns, rows, name = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/populator/adapters/sqlite.rb', line 11

def populate(table, columns, rows, name = nil)
  queries = []
  rows.each do |row|
    queries << "INSERT INTO #{table} #{columns} VALUES #{row}"
  end
  execute_batch(queries.join(';'), name)
end