Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbeedle committed Apr 19, 2016
1 parent db866c8 commit a24e25f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Expand Up @@ -47,8 +47,43 @@ If you're using rails then copy the migrations across:
rake usda_nutrient_database_engine:install:migrations
```

## Configuration

```ruby
UsdaNutrientDatabase.configure do |config|
config.batch_size = 20000 # import batch size, if using activerecord-import
config.perform_logging = true # default false
config.logger = Rails.logger # default Logger.new(STDOUT)
config.usda_version = 'sr25' # default sr28
end
```

## Usage

### Importing with UPSERT (takes around 2 minutes)

If you are running MySQL => 5.6 or PostgreSQL => 9.5 then you're in luck, you
can use UPSERT (insert or update) to speed up imports x30. To do this you're
going to need to install
[activerecord-import](https://github.com/zdennis/activerecord-import)

```ruby
require 'activerecord-import/base'
ActiveRecord::Import.require_adapter('postgresql')

# You may want to disable logging during this process to avoid dumping huge SQL
# strings in to your logs
ActiveRecord::Base.logger = Logger.new('/dev/null')
```

Now run the rake task which will import everything in around 2 minutes.
```
rake usda:import
```


### Importing without UPSERT (takes 60+ minutes)

Import the latest data with the import task:
```
rake usda:import
Expand All @@ -60,6 +95,8 @@ tasks:
rake -T usda
```

### Models

Use the models to query and profit:
```
UsdaNutrientDatabase::FoodGroup
Expand Down

0 comments on commit a24e25f

Please sign in to comment.