Ruby on rails plugin: Import With Load Data In File
This plugin lets you bulk insert records into a MySql table using the “LOAD DATA IN FILE” feature of MySql.
This is about 30% faster than using a standard bulk insert (eg: ar-extensions import)
all it does is:
- take a list of columns and a 2D Array with the column values
- create a tempfile and put a csv representation of the data in it
- call mysql’s LOAD DATA INFILE against the temp file
Example:
# Table name: users
#
# id :integer(11) not null, primary key
# name :string(20)
# surname :string(32)
#
class User < ActiveRecord::Base
# you need to include this module
include ImportWithLoadDataInFile
end
cols = [:name, :surname]
vals = [["paolo", "dona"], ["james", "dean"]]
User.import_with_load_data_infile(cols, vals)
Related Posts
Tags: bulk insert, feature of MySql, import with load data, insert bulk record, load data infile, mysql plugin, ror plugin
Viewed: 499 views


















(2 votes, average: 4.50 out of 5)
October 8th, 2008 at 12:11 pm
Nice little plugin
How about extending AR directly in the plugin, like:
ActiveRecord::Base.class_eval do
include ImportWithLoadDataInFile
end
Then one does not have to require it for every AR class.
Take it easy, R