Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (32 sloc) 1.85 KB


This gem adds bulk import functionality to ActiveRecord model using the fast MySQL's 'LOAD DATA INFILE' feature. This gem code is largely inspired by the import_with_load_data_in_file plugin. (thanks Paolo Dona)


Install the gem from github

gem install guillaumegentil-import_fu --source

Add the gem to your Rails environment.rb file:

config.gem "guillaumegentil-import_fu", :lib => "import_fu", :source => ""

Include import_fu in your ActiveRecord Model:

class Foo < ActiveRecord::Base
  include ImportFu


Import from an array of values

columns = [:name, :size]
values = [["toto", "32"],
          ["tata", "33"]]

Foo.import columns, values

Import from a csv file (MySQL needs to have access on this file, so be sure it has the proper ownership/permissions)

columns = [:name, :size]

Foo.import columns, '/path/of/a/csv'


By default ImportFu adds timestamps values ( when importing from an array, this can be avoided with:

Foo.import columns, values, :timestamps => false

By default ImportFu does NOT reformat values passed in the array (like Time or Data value), if you want the reformat use:

Foo.import columns, values, :format => true

By default ImportFu does NOT replace already existing values in database and ignores them (like values with an id already used), if you want the replace behavior use:

Foo.import columns, values, :replace => true

If your Rails app and your MySQL database are on the same machine, you can speed up the import by passing:

Foo.import columns, values, :local => true


Thibaud Guillaume-Gentil