<commit_before># postgres-copy [![Build Status](https://travis-ci.org/diogob/postgres-copy.png?branch=master)](https://travis-ci.org/diogob/postgres-copy)

This Gem will enable your AR models to use the PostgreSQL COPY command to import/export data in CSV format.
If you need to tranfer data between a PostgreSQL database and CSV files, the PostgreSQL native CSV parser
will give you a greater performance than using the ruby CSV+INSERT commands.
I have not found time to make accurate benchmarks, but in the use scenario where I have developed the gem
I have had a four-fold performance gain.
This gem was written having the Rails framework in mind, I think it could work only with active-record, 
but I will assume in this README that you are using Rails.

## Install

Put it in your Gemfile

    gem 'postgres-copy'

Run the bundle command

    bundle

## Rails (or ActiveRecord) versions

Rails 4 users should use the version 0.7 and onward, while if you use Rails 3.2 stick with the 0.6 versions.

## Usage

To enable the copy commands in an ActiveRecord model called User you should use:
```ruby<commit_msg>notes in README about versions<commit_after># postgres-copy [![Build Status](https://travis-ci.org/diogob/postgres-copy.png?branch=master)](https://travis-ci.org/diogob/postgres-copy)

This Gem will enable your AR models to use the PostgreSQL COPY command to import/export data in CSV format.
If you need to tranfer data between a PostgreSQL database and CSV files, the PostgreSQL native CSV parser
will give you a greater performance than using the ruby CSV+INSERT commands.
I have not found time to make accurate benchmarks, but in the use scenario where I have developed the gem
I have had a four-fold performance gain.
This gem was written having the Rails framework in mind, I think it could work only with active-record, 
but I will assume in this README that you are using Rails.

## Install

Put it in your Gemfile

    gem 'postgres-copy'

Run the bundle command

    bundle

## IMPORTANT note about recent versions

* Rails 4 users should use the version 0.7 and onward, while if you use Rails 3.2 stick with the 0.6 versions.
* Since version 0.8 all methods lost the prefix pg_ and they should be included in models thourgh acts_as_copy_target.

## Usage

To enable the copy commands in an ActiveRecord model called User you should use:
```ruby
{'fraction_non_alphanumeric': 0.05574324324324324, 'fraction_numerical': 0.006756756756756757, 'mean_word_length': 4.21806167400881, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3326832', 'n_tokens_mistral': 675, 'n_tokens_neox': 635, 'n_words': 350}