sequel-from_csv 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2828e85c1caf38af3b32a722a4973f5eb7c5ae94
4
- data.tar.gz: c1590dbd1f44605cf34d1898a1c331b041e26466
3
+ metadata.gz: a4d228e5c25da53d734d288c0985b4923f8a3a10
4
+ data.tar.gz: b4fad2d2d4e559ecfc7900ec321da5c299931d65
5
5
  SHA512:
6
- metadata.gz: 88da935334c894c73f53378bb2f78fc551944e55dcb176df5e767e72b7695580ef1ad73200319542cab444a3ecb74f89bc8ecb6c0b1a2f660c117909cafcd26c
7
- data.tar.gz: 9af9c728634971508cf77c282a0c19bd611d0413d447da827197b248b17a075c4fa13d2f2351e04483f96d29beb0fed809f8431b282e2996e083a4f022274f58
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, delete: false
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 delete
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.run <<~SQL
35
- SELECT
36
- setval(pg_get_serial_sequence('#{self.simple_table}', 'id'), coalesce(max(id), 1), true)
37
- FROM
38
- #{self.simple_table}
39
- SQL
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.0
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-21 00:00:00.000000000 Z
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: '1.13'
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: '1.13'
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: '10.0'
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: '10.0'
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
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in sequel-from_csv.gemspec
4
- gemspec
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
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
@@ -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