upsert 2.0.3 → 2.0.4

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZWU3NjI3M2VmZDY1YzVlNGMyMzA5NWI3ZTQyNjVkNzZkNjE4MWMwNA==
5
- data.tar.gz: !binary |-
6
- MTIzNjU4OGIxMmYwNzliZGY1OWVkYTA5ZWUxNzk1ZDViMjg0Mzg1NQ==
2
+ SHA1:
3
+ metadata.gz: e403ffd510814ad862057a3059f8ce8e65d974d4
4
+ data.tar.gz: 142ba5495b4d63641f23b1e54ab2c855a9f858d9
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ODFiNzk2M2MwMTQwNWFkYmQ1MDhkMmFlNTRkMzg5MDI2ZDNlZjAzNzhiY2Yx
10
- MmE1NTVhMzYzZjBjYTQyZTkzY2U3Y2M5M2M4OTU0MjVkNGE1YWFlY2U2NTU0
11
- ZWJiZjA1YjdiMzM2ZjdmNGU3NThkZTcxMzA4MjdiYzk0OTA3MDc=
12
- data.tar.gz: !binary |-
13
- MDlhYzkxZjg5NThiMDNkY2I5YTE2ODViNGQ2NzM5ZjU0OTk3ODdiMDMwOTNm
14
- NTYwNTUxMTEyMjIwMTdmNGRlYzc4MDg5NWUzOGExYWI3ZDQ0OGUwNDg1Njlk
15
- NGIxY2NkMzc2YjE5OWNlMmNkZmRhMjFlOGIxMmU5MmY1ZDZjN2U=
6
+ metadata.gz: d4ad43d341e5fefbecac30c296f4dc6956e4e513a68e1aca95ea0026017ce882849b59144282cc9ac82f7eabea5bfc9297a134b7f3b6320b9ad717be180d977d
7
+ data.tar.gz: 3bec3b12605a00058fb654d718baa5cc6adef91ea8e1b6931e22248a3f45f1a3652db43183923346516675edf4ff0269d3a0122199ac941784851c996d6f0583
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ *.log
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ global:
3
+ - USERNAME=travis
4
+ PASSWORD=
5
+ rvm:
6
+ - 1.9.3
7
+ - 1.9.2
8
+ - 1.8.7
9
+ env:
10
+ - DB=postgresql
11
+ - DB=mysql
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ 2.0.4 / 2015-01-27
2
+
3
+ * Bug fixes
4
+
5
+ * Support mysql returning column info as symbols - thanks @pnomolos
6
+
7
+ * Enhancements
8
+
9
+ * Travis and misc test fixes - thanks @raviolicode
10
+ * Backwards compat with 1.8 - thanks @raviolicode
11
+
1
12
  2.0.3 / 2013-11-27
2
13
 
3
14
  * Bug fixes
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Upsert
2
2
 
3
+ **note** There is a known problem with mysql2 and sidekiq - we're working on it in https://github.com/seamusabshere/upsert/tree/real_thread_safe and various issues
4
+
5
+ [![Build Status](https://travis-ci.org/seamusabshere/upsert.svg?branch=master)](https://travis-ci.org/seamusabshere/upsert)
6
+
3
7
  Make it easy to upsert on traditional RDBMS like MySQL, PostgreSQL, and SQLite3—hey look NoSQL!. Transparently creates (and re-uses) stored procedures/functions when necessary.
4
8
 
5
9
  You pass it a bare-metal connection to the database like `Mysql2::Client` (from `mysql2` gem on MRI) or `Java::OrgPostgresqlJdbc4::Jdbc4Connection` (from `jdbc-postgres` on Jruby).
@@ -365,4 +369,4 @@ Per https://github.com/seamusabshere/upsert/issues/23 you might have issues if y
365
369
 
366
370
  ## Copyright
367
371
 
368
- Copyright 2013 Seamus Abshere
372
+ Copyright 2014 Seamus Abshere
data/Rakefile CHANGED
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = "--format documentation"
7
+ end
8
+
9
+ task :default => :spec
3
10
 
4
11
  task :rspec_all_databases do
5
12
  results = {}
@@ -15,16 +22,19 @@ task :rspec_all_databases do
15
22
  puts "# Running specs against #{db}"
16
23
  puts '#'*50
17
24
  puts
18
- # won't work on 1.8.7...
19
- pid = Kernel.spawn({'DB' => db}, 'rspec', '--format', 'documentation', File.expand_path('../spec', __FILE__))
20
- Process.waitpid pid
21
- results[db] = $?.success?
25
+
26
+ if RUBY_VERSION >= '1.9'
27
+ pid = spawn({'DB' => db}, 'rspec', '--format', 'documentation', File.expand_path('../spec', __FILE__))
28
+ Process.waitpid pid
29
+ results[db] = $?.success?
30
+ else
31
+ exec({'DB' => db}, 'rspec', '--format', 'documentation', File.expand_path('../spec', __FILE__))
32
+ end
33
+
22
34
  end
23
35
  puts results.inspect
24
36
  end
25
37
 
26
- task :default => :rspec_all_databases
27
-
28
38
  task :n, :from, :to do |t, args|
29
39
  Dir[File.expand_path("../lib/upsert/**/#{args.from}.*", __FILE__)].each do |path|
30
40
  dir = File.dirname(path)
@@ -6,16 +6,16 @@ class Upsert
6
6
  def all(connection, table_name)
7
7
  connection.execute("SHOW COLUMNS FROM #{connection.quote_ident(table_name)}").map do |row|
8
8
  # {"Field"=>"name", "Type"=>"varchar(255)", "Null"=>"NO", "Key"=>"PRI", "Default"=>nil, "Extra"=>""}
9
- name = row['Field'] || row['COLUMN_NAME']
10
- type = row['Type'] || row['COLUMN_TYPE']
11
- default = row['Default'] || row['COLUMN_DEFAULT']
9
+ name = row['Field'] || row['COLUMN_NAME'] || row[:Field] || row[:COLUMN_NAME]
10
+ type = row['Type'] || row['COLUMN_TYPE'] || row[:Type] || row[:COLUMN_TYPE]
11
+ default = row['Default'] || row['COLUMN_DEFAULT'] || row[:Default] || row[:COLUMN_DEFAULT]
12
12
  new connection, name, type, default
13
13
  end.sort_by do |cd|
14
14
  cd.name
15
15
  end
16
16
  end
17
17
  end
18
-
18
+
19
19
  def equality(left, right)
20
20
  "#{left} <=> #{right}"
21
21
  end
@@ -1,3 +1,3 @@
1
1
  class Upsert
2
- VERSION = '2.0.3'
2
+ VERSION = '2.0.4'
3
3
  end
@@ -41,8 +41,8 @@ describe Upsert do
41
41
  p.save!
42
42
  Pet.find_by_name_and_gender('Jerry', 'blue').tag_number.should == 777
43
43
  u = Upsert.new($conn, :pets)
44
- selector = {name: 'Jerry', gender: 'red'} # this shouldn't select anything
45
- setter = {tag_number: 888}
44
+ selector = {:name => 'Jerry', :gender => 'red'} # this shouldn't select anything
45
+ setter = {:tag_number => 888}
46
46
  u.row(selector, setter)
47
47
  Pet.find_by_name_and_gender('Jerry', 'blue').tag_number.should == 777
48
48
  end
@@ -53,7 +53,7 @@ describe Upsert do
53
53
  now = Date.today
54
54
  u = Upsert.new($conn, :pets)
55
55
  5.times do
56
- u.row(gender: nil, birthday: now)
56
+ u.row(:gender => nil, :birthday => now)
57
57
  end
58
58
 
59
59
  Pet.count.should == 1
@@ -63,7 +63,7 @@ describe Upsert do
63
63
  Pet.count.should == 0
64
64
  u = Upsert.new($conn, :pets)
65
65
  5.times do
66
- u.row(birthday: nil)
66
+ u.row(:birthday => nil)
67
67
  end
68
68
 
69
69
  Pet.count.should == 1
@@ -73,17 +73,17 @@ describe Upsert do
73
73
  u = Upsert.new($conn, :pets)
74
74
  now = Date.today
75
75
  assert_creates(Pet, [{:name => 'Jerry', :gender => nil, :spiel => 'beagle', :birthday => now}]) do
76
- u.row(name: "Jerry", gender: nil, spiel: "samoyed")
77
- u.row({:name => 'Jerry', gender: nil}, :spiel => 'beagle', :birthday => now)
76
+ u.row(:name => "Jerry", :gender => nil, :spiel => "samoyed")
77
+ u.row({:name => 'Jerry', :gender => nil}, :spiel => 'beagle', :birthday => now)
78
78
  end
79
79
  end
80
80
 
81
81
  it "tells you if you request a column that doesn't exist" do
82
82
  u = Upsert.new($conn, :pets)
83
- lambda { u.row(gibberish: 'ba') }.should raise_error(/invalid col/i)
84
- lambda { u.row(name: 'Jerry', gibberish: 'ba') }.should raise_error(/invalid col/i)
85
- lambda { u.row({name: 'Jerry'}, gibberish: 'ba') }.should raise_error(/invalid col/i)
86
- lambda { u.row({name: 'Jerry'}, gender: 'male', gibberish: 'ba') }.should raise_error(/invalid col/i)
83
+ lambda { u.row(:gibberish => 'ba') }.should raise_error(/invalid col/i)
84
+ lambda { u.row(:name => 'Jerry', :gibberish => 'ba') }.should raise_error(/invalid col/i)
85
+ lambda { u.row(:name => 'Jerry', :gibberish => 'ba') }.should raise_error(/invalid col/i)
86
+ lambda { u.row(:name => 'Jerry', :gibberish => 'ba', :gender => 'male') }.should raise_error(/invalid col/i)
87
87
  end
88
88
 
89
89
  end
@@ -134,7 +134,7 @@ describe Upsert do
134
134
  # end
135
135
  end
136
136
 
137
- if ENV['DB'] == 'mysql'
137
+ if ENV['DB'] == 'mysql' && RUBY_VERSION >= '1.9'
138
138
  describe 'compared to activerecord-import' do
139
139
  it "is as correct as faking upserts with activerecord-import" do
140
140
  assert_same_result lotsa_records do |records|
data/spec/hstore_spec.rb CHANGED
@@ -16,7 +16,7 @@ describe Upsert do
16
16
  uggy = <<-EOS
17
17
  {"results":[{"locations":[],"providedLocation":{"location":"3001 STRATTON WAY, MADISON, WI 53719 UNITED STATES"}}],"options":{"ignoreLatLngInput":true,"maxResults":1,"thumbMaps":false},"info":{"copyright":{"text":"© 2012 MapQuest, Inc.","imageUrl":"http://api.mqcdn.com/res/mqlogo.gif","imageAltText":"© 2012 MapQuest, Inc."},"statuscode":0,"messages":[]}}
18
18
  EOS
19
- upsert.row({:name => 'Uggy'}, crazy: {uggy: uggy})
19
+ upsert.row({:name => 'Uggy'}, :crazy => {:uggy => uggy})
20
20
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Uggy'})
21
21
  crazy = PgHstore.parse row['crazy']
22
22
  crazy.should == { 'uggy' => uggy }
@@ -25,35 +25,35 @@ EOS
25
25
  it "just works" do
26
26
  upsert = Upsert.new $conn, :pets
27
27
 
28
- upsert.row({name: 'Bill'}, crazy: nil)
28
+ upsert.row({:name => 'Bill'}, :crazy => nil)
29
29
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
30
30
  row['crazy'].should == nil
31
31
 
32
- upsert.row({name: 'Bill'}, crazy: {a: 1})
32
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1})
33
33
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
34
34
  crazy = PgHstore.parse row['crazy']
35
35
  crazy.should == { 'a' => '1' }
36
36
 
37
- upsert.row({name: 'Bill'}, crazy: nil)
37
+ upsert.row({:name => 'Bill'}, :crazy => nil)
38
38
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
39
39
  row['crazy'].should == nil
40
40
 
41
- upsert.row({name: 'Bill'}, crazy: {a: 1})
41
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1})
42
42
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
43
43
  crazy = PgHstore.parse row['crazy']
44
44
  crazy.should == { 'a' => '1' }
45
45
 
46
- upsert.row({name: 'Bill'}, crazy: {whatdat: 'whodat'})
46
+ upsert.row({:name => 'Bill'}, :crazy => {:whatdat => 'whodat'})
47
47
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
48
48
  crazy = PgHstore.parse row['crazy']
49
49
  crazy.should == { 'a' => '1', 'whatdat' => 'whodat' }
50
50
 
51
- upsert.row({name: 'Bill'}, crazy: {whatdat: "D'ONOFRIO"})
51
+ upsert.row({:name => 'Bill'}, :crazy => {:whatdat => "D'ONOFRIO"})
52
52
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
53
53
  crazy = PgHstore.parse row['crazy']
54
54
  crazy.should == { 'a' => '1', 'whatdat' => "D'ONOFRIO" }
55
55
 
56
- upsert.row({name: 'Bill'}, crazy: {a: 2})
56
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 2})
57
57
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
58
58
  crazy = PgHstore.parse row['crazy']
59
59
  crazy.should == { 'a' => '2', 'whatdat' => "D'ONOFRIO" }
@@ -62,12 +62,12 @@ EOS
62
62
  it "can nullify entire hstore" do
63
63
  upsert = Upsert.new $conn, :pets
64
64
 
65
- upsert.row({name: 'Bill'}, crazy: {a: 1})
65
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1})
66
66
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
67
67
  crazy = PgHstore.parse row['crazy']
68
68
  crazy.should == { 'a' => '1' }
69
69
 
70
- upsert.row({name: 'Bill'}, crazy: nil)
70
+ upsert.row({:name => 'Bill'}, :crazy => nil)
71
71
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
72
72
  row['crazy'].should == nil
73
73
  end
@@ -75,46 +75,46 @@ EOS
75
75
  it "deletes keys that are nil" do
76
76
  upsert = Upsert.new $conn, :pets
77
77
 
78
- upsert.row({name: 'Bill'}, crazy: nil)
78
+ upsert.row({:name => 'Bill'}, :crazy => nil)
79
79
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
80
80
  row['crazy'].should == nil
81
81
 
82
- upsert.row({name: 'Bill'}, crazy: {a: 1})
82
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1})
83
83
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
84
84
  crazy = PgHstore.parse row['crazy']
85
85
  crazy.should == { 'a' => '1' }
86
86
 
87
- upsert.row({name: 'Bill'}, crazy: {})
87
+ upsert.row({:name => 'Bill'}, :crazy => {})
88
88
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
89
89
  crazy = PgHstore.parse row['crazy']
90
90
  crazy.should == { 'a' => '1' }
91
91
 
92
- upsert.row({name: 'Bill'}, crazy: {a: nil})
92
+ upsert.row({:name => 'Bill'}, :crazy => {:a => nil})
93
93
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
94
94
  crazy = PgHstore.parse row['crazy']
95
95
  crazy.should == {}
96
96
 
97
- upsert.row({name: 'Bill'}, crazy: {a: 1, b: 5})
97
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 5})
98
98
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
99
99
  crazy = PgHstore.parse row['crazy']
100
100
  crazy.should == { 'a' => '1', 'b' => '5' }
101
101
 
102
- upsert.row({name: 'Bill'}, crazy: {})
102
+ upsert.row({:name => 'Bill'}, :crazy => {})
103
103
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
104
104
  crazy = PgHstore.parse row['crazy']
105
105
  crazy.should == { 'a' => '1', 'b' => '5' }
106
106
 
107
- upsert.row({name: 'Bill'}, crazy: {a: nil})
107
+ upsert.row({:name => 'Bill'}, :crazy => {:a => nil})
108
108
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
109
109
  crazy = PgHstore.parse row['crazy']
110
110
  crazy.should == { 'b' => '5' }
111
111
 
112
- upsert.row({name: 'Bill'}, crazy: {a: 1, b: 5})
112
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 5})
113
113
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
114
114
  crazy = PgHstore.parse row['crazy']
115
115
  crazy.should == { 'a' => '1', 'b' => '5' }
116
116
 
117
- upsert.row({name: 'Bill'}, crazy: {a: nil, b: nil, c: 12})
117
+ upsert.row({:name => 'Bill'}, :crazy => {:a => nil, :b => nil, :c => 12})
118
118
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
119
119
  crazy = PgHstore.parse row['crazy']
120
120
  crazy.should == { 'c' => '12' }
@@ -123,46 +123,46 @@ EOS
123
123
  it "takes dangerous keys" do
124
124
  upsert = Upsert.new $conn, :pets
125
125
 
126
- upsert.row({name: 'Bill'}, crazy: nil)
126
+ upsert.row({:name => 'Bill'}, :crazy => nil)
127
127
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
128
128
  row['crazy'].should == nil
129
129
 
130
- upsert.row({name: 'Bill'}, crazy: {:'foo"bar' => 1})
130
+ upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => 1})
131
131
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
132
132
  crazy = PgHstore.parse row['crazy']
133
133
  crazy.should == { 'foo"bar' => '1' }
134
134
 
135
- upsert.row({name: 'Bill'}, crazy: {})
135
+ upsert.row({:name => 'Bill'}, :crazy => {})
136
136
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
137
137
  crazy = PgHstore.parse row['crazy']
138
138
  crazy.should == { 'foo"bar' => '1' }
139
139
 
140
- upsert.row({name: 'Bill'}, crazy: {:'foo"bar' => nil})
140
+ upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => nil})
141
141
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
142
142
  crazy = PgHstore.parse row['crazy']
143
143
  crazy.should == {}
144
144
 
145
- upsert.row({name: 'Bill'}, crazy: {:'foo"bar' => 1, b: 5})
145
+ upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => 1, :b => 5})
146
146
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
147
147
  crazy = PgHstore.parse row['crazy']
148
148
  crazy.should == { 'foo"bar' => '1', 'b' => '5' }
149
149
 
150
- upsert.row({name: 'Bill'}, crazy: {})
150
+ upsert.row({:name => 'Bill'}, :crazy => {})
151
151
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
152
152
  crazy = PgHstore.parse row['crazy']
153
153
  crazy.should == { 'foo"bar' => '1', 'b' => '5' }
154
154
 
155
- upsert.row({name: 'Bill'}, crazy: {:'foo"bar' => nil})
155
+ upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => nil})
156
156
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
157
157
  crazy = PgHstore.parse row['crazy']
158
158
  crazy.should == { 'b' => '5' }
159
159
 
160
- upsert.row({name: 'Bill'}, crazy: {:'foo"bar' => 1, b: 5})
160
+ upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => 1, :b => 5})
161
161
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
162
162
  crazy = PgHstore.parse row['crazy']
163
163
  crazy.should == { 'foo"bar' => '1', 'b' => '5' }
164
164
 
165
- upsert.row({name: 'Bill'}, crazy: {:'foo"bar' => nil, b: nil, c: 12})
165
+ upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => nil, :b => nil, :c => 12})
166
166
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
167
167
  crazy = PgHstore.parse row['crazy']
168
168
  crazy.should == { 'c' => '12' }
@@ -170,7 +170,7 @@ EOS
170
170
 
171
171
  it "handles multiple hstores" do
172
172
  upsert = Upsert.new $conn, :pets
173
- upsert.row({name: 'Bill'}, crazy: {a: 1, b: 9}, cool: {c: 12, d: 19})
173
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 9}, :cool => {:c => 12, :d => 19})
174
174
  row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'})
175
175
  crazy = PgHstore.parse row['crazy']
176
176
  crazy.should == { 'a' => '1', 'b' => '9' }
@@ -181,7 +181,7 @@ EOS
181
181
  it "can deletes keys from multiple hstores at once" do
182
182
  upsert = Upsert.new $conn, :pets
183
183
 
184
- upsert.row({name: 'Bill'}, crazy: {a: 1}, cool: {5 => 9})
184
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1}, :cool => {5 => 9})
185
185
  row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'})
186
186
  crazy = PgHstore.parse row['crazy']
187
187
  crazy.should == { 'a' => '1' }
@@ -189,26 +189,26 @@ EOS
189
189
  cool.should == { '5' => '9' }
190
190
 
191
191
  # NOOP
192
- upsert.row({name: 'Bill'}, crazy: {}, cool: {})
192
+ upsert.row({:name => 'Bill'}, :crazy => {}, :cool => {})
193
193
  row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'})
194
194
  crazy = PgHstore.parse row['crazy']
195
195
  crazy.should == { 'a' => '1' }
196
196
  cool = PgHstore.parse row['cool']
197
197
  cool.should == { '5' => '9' }
198
198
 
199
- upsert.row({name: 'Bill'}, crazy: {a: nil}, cool: {13 => 17})
199
+ upsert.row({:name => 'Bill'}, :crazy => {:a => nil}, :cool => {13 => 17})
200
200
  row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'})
201
201
  crazy = PgHstore.parse row['crazy']
202
202
  crazy.should == {}
203
203
  cool = PgHstore.parse row['cool']
204
204
  cool.should == { '5' => '9', '13' => '17' }
205
205
 
206
- upsert.row({name: 'Bill'}, crazy: {a: 1, b: 5})
206
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 5})
207
207
  row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'})
208
208
  crazy = PgHstore.parse row['crazy']
209
209
  crazy.should == { 'a' => '1', 'b' => '5' }
210
210
 
211
- upsert.row({name: 'Bill'}, crazy: {b: nil}, cool: {5 => nil})
211
+ upsert.row({:name => 'Bill'}, :crazy => {:b => nil}, :cool => {5 => nil})
212
212
  row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'})
213
213
  crazy = PgHstore.parse row['crazy']
214
214
  crazy.should == {'a' => '1'}
@@ -219,12 +219,12 @@ EOS
219
219
  it "deletes keys whether new or existing record" do
220
220
  upsert = Upsert.new $conn, :pets
221
221
 
222
- upsert.row({name: 'Bill'}, crazy: {z: 1, x: nil})
222
+ upsert.row({:name => 'Bill'}, :crazy => {:z => 1, :x => nil})
223
223
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
224
224
  crazy = PgHstore.parse row['crazy']
225
225
  crazy.should == { 'z' => '1' }
226
226
 
227
- upsert.row({name: 'Bill'}, crazy: {a: 1})
227
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1})
228
228
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
229
229
  crazy = PgHstore.parse row['crazy']
230
230
  crazy.should == { 'a' => '1', 'z' => '1' }
@@ -233,12 +233,12 @@ EOS
233
233
  it "can turn off eager nullify" do
234
234
  upsert = Upsert.new $conn, :pets
235
235
 
236
- upsert.row({name: 'Bill'}, {crazy: {z: 1, x: nil}}, eager_nullify: false)
236
+ upsert.row({:name => 'Bill'}, {:crazy => {:z => 1, :x => nil}}, :eager_nullify => false)
237
237
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
238
238
  crazy = PgHstore.parse row['crazy']
239
239
  crazy.should == { 'z' => '1', 'x' => nil }
240
240
 
241
- upsert.row({name: 'Bill'}, crazy: {a: 1})
241
+ upsert.row({:name => 'Bill'}, :crazy => {:a => 1})
242
242
  row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'})
243
243
  crazy = PgHstore.parse row['crazy']
244
244
  crazy.should == { 'a' => '1', 'z' => '1', 'x' => nil}
data/spec/logger_spec.rb CHANGED
@@ -26,7 +26,7 @@ describe Upsert do
26
26
  Upsert.logger = Logger.new(io)
27
27
 
28
28
  u = Upsert.new($conn, :pets)
29
- u.row(name: 'Jerry')
29
+ u.row(:name => 'Jerry')
30
30
 
31
31
  io.rewind
32
32
  log = io.read.chomp
@@ -36,7 +36,8 @@ describe Upsert do
36
36
  when /mysql/i
37
37
  log.should =~ /call #{Upsert::MergeFunction::NAME_PREFIX}_pets_SEL_name/i
38
38
  when /p.*g/i
39
- log.should =~ /select #{Upsert::MergeFunction::NAME_PREFIX}_pets_SEL_name/i
39
+ # [54ae2eea857] Possibly much more useful debug output
40
+ log.should =~ /selector:/i
40
41
  else
41
42
  raise "not sure"
42
43
  end
data/spec/spec_helper.rb CHANGED
@@ -7,14 +7,15 @@ require 'active_record'
7
7
  ActiveRecord::Base.default_timezone = :utc
8
8
 
9
9
  require 'active_record_inline_schema'
10
- require 'activerecord-import'
10
+
11
+ require 'activerecord-import' if RUBY_VERSION >= '1.9'
11
12
 
12
13
  ENV['DB'] ||= 'mysql'
13
14
 
14
15
  class RawConnectionFactory
15
16
  DATABASE = 'upsert_test'
16
17
  CURRENT_USER = `whoami`.chomp
17
- PASSWORD = 'password'
18
+ PASSWORD = ''
18
19
 
19
20
  case ENV['DB']
20
21
 
@@ -40,10 +41,11 @@ class RawConnectionFactory
40
41
  ActiveRecord::Base.establish_connection :adapter => 'postgresql', :database => DATABASE, :username => CURRENT_USER
41
42
 
42
43
  when 'mysql'
43
- Kernel.system %{ mysql -u root -ppassword -e "DROP DATABASE IF EXISTS #{DATABASE}" }
44
- Kernel.system %{ mysql -u root -ppassword -e "CREATE DATABASE #{DATABASE} CHARSET utf8" }
44
+ password_argument = (PASSWORD.empty?) ? "" : "-p#{PASSWORD}"
45
+ Kernel.system %{ mysql -u #{CURRENT_USER} #{password_argument} -e "DROP DATABASE IF EXISTS #{DATABASE}" }
46
+ Kernel.system %{ mysql -u #{CURRENT_USER} #{password_argument} -e "CREATE DATABASE #{DATABASE} CHARSET utf8" }
45
47
  if RUBY_PLATFORM == 'java'
46
- CONFIG = "jdbc:mysql://127.0.0.1/#{DATABASE}?user=root&password=password"
48
+ CONFIG = "jdbc:mysql://127.0.0.1/#{DATABASE}?user=#{CURRENT_USER}&password=#{PASSWORD}"
47
49
  require 'jdbc/mysql'
48
50
  Jdbc::MySQL.load_driver
49
51
  # java.sql.DriverManager.register_driver com.mysql.jdbc.Driver.new
@@ -51,13 +53,14 @@ class RawConnectionFactory
51
53
  java.sql.DriverManager.get_connection CONFIG
52
54
  end
53
55
  else
54
- CONFIG = { :username => 'root', :password => PASSWORD, :database => DATABASE}
55
56
  require 'mysql2'
56
57
  def new_connection
57
- Mysql2::Client.new CONFIG
58
+ config = { :username => CURRENT_USER, :database => DATABASE, :host => "127.0.0.1" }
59
+ config.merge!(:password => PASSWORD) unless PASSWORD.empty?
60
+ Mysql2::Client.new config
58
61
  end
59
62
  end
60
- ActiveRecord::Base.establish_connection "#{RUBY_PLATFORM == 'java' ? 'mysql' : 'mysql2'}://root:password@127.0.0.1/#{DATABASE}"
63
+ ActiveRecord::Base.establish_connection "#{RUBY_PLATFORM == 'java' ? 'mysql' : 'mysql2'}://#{CURRENT_USER}:#{PASSWORD}@127.0.0.1/#{DATABASE}"
61
64
 
62
65
  when 'sqlite3'
63
66
  CONFIG = { :adapter => 'sqlite3', :database => 'file::memory:?cache=shared' }
@@ -213,7 +216,7 @@ module SpecHelper
213
216
  end.inject({}) do |memo, (k, v)|
214
217
  memo[k] = case v
215
218
  when Time, DateTime
216
- v.to_time.to_f
219
+ v.to_i
217
220
  else
218
221
  v
219
222
  end
data/spec/speed_spec.rb CHANGED
@@ -46,7 +46,7 @@ describe Upsert do
46
46
  end
47
47
  end
48
48
 
49
- if ENV['DB'] == 'mysql'
49
+ if ENV['DB'] == 'mysql' && RUBY_VERSION >= '1.9'
50
50
  describe 'compared to activerecord-import' do
51
51
  it "is faster than faking upserts with activerecord-import" do
52
52
  assert_faster_than 'faking upserts with activerecord-import', lotsa_records do |records|
@@ -70,4 +70,4 @@ describe Upsert do
70
70
  end
71
71
 
72
72
  end
73
- end
73
+ end
data/upsert.gemspec CHANGED
@@ -26,12 +26,14 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency 'active_record_inline_schema'
27
27
  gem.add_development_dependency 'faker'
28
28
  gem.add_development_dependency 'yard'
29
- gem.add_development_dependency 'activerecord-import'
30
29
  gem.add_development_dependency 'pry'
31
30
  gem.add_development_dependency 'pg-hstore', ">=1.1.3"
32
31
  gem.add_development_dependency 'sequel'
32
+ gem.add_development_dependency 'rake', '~>10.1.1'
33
33
 
34
- unless RUBY_VERSION >= '1.9'
34
+ if RUBY_VERSION >= '1.9'
35
+ gem.add_development_dependency 'activerecord-import'
36
+ else
35
37
  gem.add_development_dependency 'orderedhash'
36
38
  end
37
39
 
@@ -47,7 +49,11 @@ Gem::Specification.new do |gem|
47
49
  gem.add_development_dependency 'sqlite3'
48
50
  gem.add_development_dependency 'mysql2'
49
51
  gem.add_development_dependency 'pg'
50
- gem.add_development_dependency 'redcarpet' # github-flavored markdown
51
- gem.add_development_dependency 'rake'
52
+ # github-flavored markdown
53
+ if RUBY_VERSION >= '1.9'
54
+ gem.add_development_dependency 'redcarpet'
55
+ else
56
+ gem.add_development_dependency 'redcarpet', '~> 2.3.0'
57
+ end
52
58
  end
53
59
  end
metadata CHANGED
@@ -1,237 +1,237 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upsert
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-27 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-expectations
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-mocks
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
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
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3'
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
68
  version: '3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: active_record_inline_schema
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: faker
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: yard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: activerecord-import
112
+ name: pry
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: pry
126
+ name: pg-hstore
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: 1.1.3
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: 1.1.3
139
139
  - !ruby/object:Gem::Dependency
140
- name: pg-hstore
140
+ name: sequel
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 1.1.3
145
+ version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ! '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: 1.1.3
152
+ version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: sequel
154
+ name: rake
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ! '>='
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: 10.1.1
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ! '>='
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: 10.1.1
167
167
  - !ruby/object:Gem::Dependency
168
- name: sqlite3
168
+ name: activerecord-import
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ! '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: mysql2
182
+ name: sqlite3
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ! '>='
185
+ - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ! '>='
192
+ - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
- name: pg
196
+ name: mysql2
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ! '>='
199
+ - - ">="
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ! '>='
206
+ - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  - !ruby/object:Gem::Dependency
210
- name: redcarpet
210
+ name: pg
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - ! '>='
213
+ - - ">="
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - ! '>='
220
+ - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  - !ruby/object:Gem::Dependency
224
- name: rake
224
+ name: redcarpet
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - ! '>='
227
+ - - ">="
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - ! '>='
234
+ - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  description: Make it easy to upsert on MySQL, PostgreSQL, and SQLite3. Transparently
@@ -242,8 +242,9 @@ executables: []
242
242
  extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
- - .gitignore
246
- - .yardopts
245
+ - ".gitignore"
246
+ - ".travis.yml"
247
+ - ".yardopts"
247
248
  - CHANGELOG
248
249
  - Gemfile
249
250
  - LICENSE
@@ -307,17 +308,17 @@ require_paths:
307
308
  - lib
308
309
  required_ruby_version: !ruby/object:Gem::Requirement
309
310
  requirements:
310
- - - ! '>='
311
+ - - ">="
311
312
  - !ruby/object:Gem::Version
312
313
  version: '0'
313
314
  required_rubygems_version: !ruby/object:Gem::Requirement
314
315
  requirements:
315
- - - ! '>='
316
+ - - ">="
316
317
  - !ruby/object:Gem::Version
317
318
  version: '0'
318
319
  requirements: []
319
320
  rubyforge_project:
320
- rubygems_version: 2.1.11
321
+ rubygems_version: 2.2.2
321
322
  signing_key:
322
323
  specification_version: 4
323
324
  summary: Make it easy to upsert on MySQL, PostgreSQL, and SQLite3. Transparently creates