Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/greyblake/fast_seeder
Speed up seeding your Rails application using multiple SQL inserts!
https://github.com/greyblake/fast_seeder
Last synced: 17 days ago
JSON representation
Speed up seeding your Rails application using multiple SQL inserts!
- Host: GitHub
- URL: https://github.com/greyblake/fast_seeder
- Owner: greyblake
- License: lgpl-3.0
- Created: 2012-08-05T16:38:06.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T04:39:44.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T13:25:34.706Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 57.6 KB
- Stars: 25
- Watchers: 3
- Forks: 3
- Open Issues: 9
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# FastSeeder [![Build Status](https://secure.travis-ci.org/greyblake/fast_seeder.png)](http://travis-ci.org/greyblake/fast_seeder)
By [Sergey Potapov](https://github.com/greyblake)
Speed up seeding database in Rails application using multiple SQL inserts!
## Deprecation
The project is deprecated and no longer supported.
Please consider using [activerecord-import](https://github.com/zdennis/activerecord-import) instead.## Installation
Add to Gemfile:
```ruby
gem "fast_seeder"
```## Usage
### Seeding from CSV file
Lets say you have CSV file `db/seeds/cities/ukraine.csv`:
```csv
Kharkov,1654
Lviv,1240
Kiev,600
```You can populate DB with it using FastSeeder:
```ruby
# Seeding from CSV file:
FastSeeder.seed_csv!(City, "cities/ukraine.csv", :name, :founded_in, :country => "Ukraine")
```Technically it equals to:
```ruby
City.create(:name => "Kharkov", :founded_in => 1654, :country => "Ukraine")
City.create(:name => "Lviv" , :founded_in => 1240, :country => "Ukraine")
City.create(:name => "Kiev" , :founded_in => 600 , :country => "Ukraine")
```But does the job faster using only one SQL query instead of three.
As you also noticed it expects you to pass model class, path to CSV file(located in `db/seeds`),
CSV columns, and default values.### Seeding in place
The next example is equivalent to showed above one, but uses inline data
without CSV file:```ruby
# Seeding in place:
FastSeeder.seed!(City, :name, :founded_in, :country => "Ukraine") do
record "Kharkov", 1654
record "Lviv" , 1240
record "Kiev" , 600
end
```## Supported database adapters
* PostgreSQL
* MySQL(mysql, mysql2)
* SQLite3## Running specs
```
rake spec:all # run specs with all supported adapters
rake spec:mysql # run specs with mysql adapter
rake spec:mysql2 # run specs with mysql2 adapter
rake spec:postgresql # run specs with postgresql adapter
rake spec:sqlite3 # run specs with sqlite3 adapter
```## Rails 3
Gemfile:
```ruby
gem "fast_seeder", "0.0.2"
```## Credits
* [Sergey Potapov](https://github.com/greyblake) - creator and maintainer
## License
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see