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)

Social Bookmarks: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • Webnews
  • Y!GG
  • Google Bookmarks
  • SEOigg
  • YahooMyWeb
  • Live-MSN
  • DZone
  • Facebook
  • Technorati
  • Ask
  • Furl
  • Spurl
  • Webbrille

Related Posts

Tags: , , , , , ,

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.50 out of 5)
Loading ... Loading ...

Viewed: 499 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

Twitter Users!
Enter your personal information in the form or sign in with your Twitter account by clicking the button below.

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.