README.md in mass_insert-0.1.1 vs README.md in mass_insert-0.1.2
- old
+ new
@@ -1,9 +1,9 @@
# MassInsert [![Build Status](https://travis-ci.org/alejandrogutierrez/mass_insert.png?branch=master)](https://travis-ci.org/alejandrogutierrez/mass_insert)
This gem aims to provide an easy and faster way to do single database insertions in Rails.
-Support Mysql, PostgreSQL, SQLite3 and SQLServer adapters.
+Support Mysql, PostgreSQL and SQLite3 adapters.
## Installation
Add this line to your application's Gemfile:
@@ -19,11 +19,11 @@
## Advantages
Faster. It's depending of the computer but these are some results...
-* PostgreSQL - Saving 10,000 records in 0.84s
+* PostgreSQL - Saving 10,000 records in 0.49s
## Attention
Since this is a single database insertion your model validation will be ignored, then if you use this gem you need to be sure that information is OK to be persisted.
@@ -41,67 +41,59 @@
},
{
:name => "Beverly",
:email => "nippy_programmer@gmail.com",
:age => 24
- },
- {
- :name => "Scottie",
- :email => "angry_programmer@gmail.com",
- :age => 32
}
]
And call mass_insert method from your model:
User.mass_insert(values)
## Results
-Sometimes after MassInsert process you need to see some necessary information about the process. MassInsert gem provides a simple way to do it. Only call the next methods from your model after MassInsert execution.
+Sometimes after MassInsert process you need to see some necessary information about the process. MassInsert gem provides a simple way to do it. Just call the next methods from your model after MassInsert execution.
User.mass_insert_results.records # => 120000
Some result options are...
1. `records` : Returns the amount of records that were persisted.
2. `time` : Returns the time that took to do all the MassInsert process.
-3. `build_time` : Returns the time that took to create the query string that was persisted.
-4. `execute_time` : Returns the time that took to execute the query string that was persisted.
+3. `building_time` : Returns the time that took to create the query string that was persisted.
+4. `execution_time` : Returns the time that took to execute the query string that was persisted.
## Options
MassInsert accepts options hash by second param when you call `mass_insert` from your model. This options allow you to configure the way that the records will be created. Example...
options = {
- :primary_key => :user_id,
- :primary_key_mode => :manual
+ :some_option => some_value,
+ :some_option => some_value
}
User.mass_insert(values, options)
OR directly
- User.mass_insert(values, :primary_key => :user_id, :primary_key_mode => :manual)
+ User.mass_insert(values, :option => value)
-Some options that you can include are...
+Some options you can include are...
-**table_name**
-- Default value is the table name to your model. This options rarely needs to change but you can do it if you pass a string with the table name. Example...
+**Primary key**
- options = {:table_name => "users"}
+By default primary key is ignored. If you wish primary key doesn't be ignored you need to pass the `primary_key` option on true. Example...
-**primary_key**
-- Default value is `:id`. You can change the name of primary key column send it a symbol with the column name.
+ User.mass_insert(values, :primary_key => true)
- options = {:primary_key => :post_id}
+**Each slice**
-**primary_key_mode**
-- Default value is `:auto`. When is `:auto` MassInsert knows that the database will generate the value of the primary key column automatically. If you pass `:manual` as primary key mode you need to create your value hashes with the key and value of the primary key column.
+Due you can get a database timeout error you can specify that the insertion will be in batches. You need to pass the `each_slice` option with the records per batch. Example...
- options = {:primary_key_mode => :manual}
+ User.mass_insert(values, :each_slice => 10000)
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)