sequel-from_csv 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sequel/plugins/from_csv.rb +11 -11
- metadata +10 -15
- data/.gitignore +0 -9
- data/Gemfile +0 -4
- data/README.md +0 -55
- data/Rakefile +0 -2
- data/sequel-from_csv.gemspec +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4d228e5c25da53d734d288c0985b4923f8a3a10
|
4
|
+
data.tar.gz: b4fad2d2d4e559ecfc7900ec321da5c299931d65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14880de509b89278786708e2135c2d427cc229cfc70b63a07dd1e5d646fd175019e2e536b032d4cb36e399e8fd7cc1704ac8d28d744ffd99712d9b2e1e465e44
|
7
|
+
data.tar.gz: 8b48b9e1b534144f1f063213fdb04ce9d4b81bee7d34aa19f33a4cf100c307fc29b18744d11e07adb598cd73dd4389d07e8766f6e1804b6e769b7effdf15dd75
|
@@ -3,11 +3,10 @@ require 'csv'
|
|
3
3
|
module Sequel
|
4
4
|
module Plugins
|
5
5
|
module FromCsv
|
6
|
-
|
7
6
|
module ClassMethods
|
8
7
|
|
9
8
|
# Synchronizes a table's data with a CSV file
|
10
|
-
def seed_from_csv csv_path,
|
9
|
+
def seed_from_csv csv_path, delete_missing: false, reset_sequence: true
|
11
10
|
|
12
11
|
# Read the source CSV file
|
13
12
|
data = CSV.table csv_path
|
@@ -26,25 +25,26 @@ module Sequel
|
|
26
25
|
end
|
27
26
|
|
28
27
|
# DELETE old rows
|
29
|
-
if
|
28
|
+
if delete_missing
|
30
29
|
self.exclude("id IN ?", data.map{|row| row[:id]}).delete
|
31
30
|
end
|
32
31
|
|
33
32
|
# Update the table's sequence
|
34
|
-
self.db.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
if reset_sequence case self.db.database_type
|
34
|
+
when :postgres
|
35
|
+
self.db.run <<~SQL
|
36
|
+
SELECT
|
37
|
+
setval(pg_get_serial_sequence('#{self.simple_table}', 'id'), coalesce(max(id), 1), true)
|
38
|
+
FROM
|
39
|
+
#{self.simple_table}
|
40
|
+
SQL
|
41
|
+
end
|
40
42
|
|
41
43
|
end
|
42
44
|
|
43
45
|
end
|
44
46
|
|
45
47
|
end
|
46
|
-
|
47
48
|
end
|
48
|
-
|
49
49
|
end
|
50
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-from_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenaniah Cerny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -42,30 +42,30 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- kenaniah@gmail.com
|
@@ -73,13 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- ".gitignore"
|
77
|
-
- Gemfile
|
78
|
-
- README.md
|
79
|
-
- Rakefile
|
80
76
|
- lib/sequel/extensions/from_csv.rb
|
81
77
|
- lib/sequel/plugins/from_csv.rb
|
82
|
-
- sequel-from_csv.gemspec
|
83
78
|
homepage: https://github.com/kenaniah/sequel-from_csv
|
84
79
|
licenses: []
|
85
80
|
metadata: {}
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# Sequel - From CSV
|
2
|
-
|
3
|
-
Provides a simple way to seed and synchronize table data using CSV files.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
```bash
|
8
|
-
$ gem install sequel-from_csv
|
9
|
-
```
|
10
|
-
|
11
|
-
Or add this line to your application's Gemfile then execute `bundle install`:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'sequel-from_csv'
|
15
|
-
```
|
16
|
-
|
17
|
-
## Usage
|
18
|
-
|
19
|
-
To seed data for an individual model:
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
# Load the plugin
|
23
|
-
Sequel::Model.plugin :from_csv
|
24
|
-
|
25
|
-
# Sync an individual model
|
26
|
-
class Country < Sequel::Model; end;
|
27
|
-
Country.seed_from_csv "app/models/country.csv"
|
28
|
-
```
|
29
|
-
|
30
|
-
To seed all models with CSV files present:
|
31
|
-
|
32
|
-
```ruby
|
33
|
-
# Load the extension
|
34
|
-
Sequel::Database.extension :from_csv
|
35
|
-
|
36
|
-
# Sync all models with CSV files recursively
|
37
|
-
DB.seed_from_csv "app/models/"
|
38
|
-
```
|
39
|
-
## To Do
|
40
|
-
|
41
|
-
- [ ] Add tests
|
42
|
-
- [ ] Remove the `activesupport` dependency
|
43
|
-
- [ ] Allow custom primary key field names
|
44
|
-
- [ ] Remove PostgreSQL-specific code
|
45
|
-
- [ ] Document optional arguments
|
46
|
-
|
47
|
-
## Development
|
48
|
-
|
49
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
-
|
51
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
52
|
-
|
53
|
-
## Contributing
|
54
|
-
|
55
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/kenaniah/sequel-from_csv.
|
data/Rakefile
DELETED
data/sequel-from_csv.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# lib = File.expand_path('../lib', __FILE__)
|
3
|
-
# $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "sequel-from_csv"
|
7
|
-
s.version = "0.1.0"
|
8
|
-
s.authors = ["Kenaniah Cerny"]
|
9
|
-
s.email = ["kenaniah@gmail.com"]
|
10
|
-
|
11
|
-
s.summary = "A simple way to seed and synchronize table data using CSV files"
|
12
|
-
s.homepage = "https://github.com/kenaniah/sequel-from_csv"
|
13
|
-
|
14
|
-
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
-
f.match(%r{^(test|spec|bin)/})
|
16
|
-
end
|
17
|
-
s.require_paths = ["lib"]
|
18
|
-
|
19
|
-
s.add_dependency "activesupport" # For String#classify and String#constantize
|
20
|
-
s.add_dependency "sequel"
|
21
|
-
|
22
|
-
s.add_development_dependency "bundler", "~> 1.13"
|
23
|
-
s.add_development_dependency "rake", "~> 10.0"
|
24
|
-
end
|