www.SmarteGuru.com
  Home | Blogs | Recipe | Find a Friend | Discussion Board | Resources | Developers Area | Articles | Health |  Login | Register Now 

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: , , , , , ,


Viewed: 824 views

One Response to “Ruby on rails plugin: Import With Load Data In File”

  1. rudionrails Says:

    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

Leave a Reply

Comment moderation is enabled. Your comment may take some time to appear.

Home - About Us - Help - Terms and Conditions - Site Map - Link to Us - Resources - Contact Us
Google Rank Calculator | Suggest developer resource | Suggest Article
All rights reserved © 2007 SmarteGuru.com.