Sha256: b0cc6cedc6a8dfd9fefb49008a9f925990acf9ce26b0710ad40ceb3900835722
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
# MassInsert [![Build Status](https://travis-ci.org/alejandrodevs/mass_insert.png?branch=master)](https://travis-ci.org/alejandrodevs/mass_insert) [![Coverage Status](https://coveralls.io/repos/github/alejandrodevs/mass_insert/badge.svg?branch=master)](https://coveralls.io/github/alejandrodevs/mass_insert?branch=master) This gem aims to provide an easy and faster way to do single database insertions in Rails. Support Mysql, PostgreSQL and SQLite3 adapters. It depends on ActiveRecord. ## Installation Add this line to your application's Gemfile: ```ruby gem 'mass_insert' ``` Run the bundle command to install it. ## Advantages Faster. It's depending of the computer but these are some results... * PostgreSQL - Saving 10,000 records in 0.49s ## Attention Since this is a single database insertion your model validations will be ignored, then if you use this gem you need to be sure that information is OK to be persisted. ## Basic Usage To use MassInsert gem you need to call `mass_insert` method from your ActiveRecord model and pass it an array with the values that you want to persist into the database. ```ruby values = [ { name: 'Jay', email: 'tremendous_gamer@gmail.com', age: 15 }, { name: 'Beverly', email: 'nippy_programmer@gmail.com', age: 24 } ] User.mass_insert(values) ``` ## Insertion per batches Due you can get a database timeout error you can specify that the insertion will be in batches. Just pass the `per_batch` option with the records per batch. Example... ```ruby User.mass_insert(values, per_batch: 1000) ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mass_insert-0.2.2 | README.md |
mass_insert-0.2.1 | README.md |