upsert 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/CHANGELOG +6 -0
- data/lib/upsert/merge_function.rb +2 -2
- data/lib/upsert/version.rb +1 -1
- data/lib/upsert.rb +2 -2
- data/spec/database_spec.rb +7 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/speed_spec.rb +24 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daedfd442f5d2ab0860de0da472d49f3a495ee16
|
4
|
+
data.tar.gz: 2d0933c0b5c846f7960e1ffa8654da2762003f9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c32e5e356d6c119e82f2c05044b1097478cd1506dac1388722beff49f9b2ba5d953da9f00c6e5337a1a2ace620a64500a151d6d7b39ab5eac2440ab6d9be6c95
|
7
|
+
data.tar.gz: d5012449fb92e493ee360c631e16571fdd9660fdb816ff33f08ed48f49c1d7e1b8b31cc1f446b81cd44ff68f8b2ae3b859ba2ac128ab64032db976aa2db7eb34
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -13,9 +13,9 @@ class Upsert
|
|
13
13
|
NAME_PREFIX,
|
14
14
|
table_name,
|
15
15
|
'SEL',
|
16
|
-
selector_keys.join('_A_'),
|
16
|
+
selector_keys.join('_A_').gsub(" ","_"),
|
17
17
|
'SET',
|
18
|
-
setter_keys.join('_A_')
|
18
|
+
setter_keys.join('_A_').gsub(" ","_")
|
19
19
|
].join('_')
|
20
20
|
if parts.length > MAX_NAME_LENGTH
|
21
21
|
# maybe i should md5 instead
|
data/lib/upsert/version.rb
CHANGED
data/lib/upsert.rb
CHANGED
@@ -182,7 +182,7 @@ class Upsert
|
|
182
182
|
# @param [Mysql2::Client,Sqlite3::Database,PG::Connection,#metal] connection A supported database connection.
|
183
183
|
# @param [String,Symbol] table_name The name of the table into which you will be upserting.
|
184
184
|
# @param [Hash] options
|
185
|
-
# @option options [TrueClass,FalseClass] :assume_function_exists (
|
185
|
+
# @option options [TrueClass,FalseClass] :assume_function_exists (true) Assume the function has already been defined correctly by another process.
|
186
186
|
def initialize(connection, table_name, options = {})
|
187
187
|
@table_name = table_name.to_s
|
188
188
|
metal = Upsert.metal connection
|
@@ -195,7 +195,7 @@ class Upsert
|
|
195
195
|
@connection = Connection.const_get(adapter).new self, metal
|
196
196
|
@merge_function_class = MergeFunction.const_get adapter
|
197
197
|
@merge_function_cache = {}
|
198
|
-
@assume_function_exists = options.fetch :assume_function_exists,
|
198
|
+
@assume_function_exists = options.fetch :assume_function_exists, true
|
199
199
|
end
|
200
200
|
|
201
201
|
# Upsert a row given a selector and a setter.
|
data/spec/database_spec.rb
CHANGED
@@ -83,6 +83,13 @@ describe Upsert do
|
|
83
83
|
upsert.row({:id => jerry.id}, :gender => :male)
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
it "works for column names with spaces in them" do
|
88
|
+
upsert = Upsert.new $conn, :people
|
89
|
+
assert_creates(Person, [{:"First Name" => 'Major', :"Last Name" => 'Major'}]) do
|
90
|
+
upsert.row({:"First Name" => 'Major'}, :"Last Name" => 'Major')
|
91
|
+
end
|
92
|
+
end
|
86
93
|
end
|
87
94
|
describe :batch do
|
88
95
|
it "works for multiple rows (base case)" do
|
data/spec/spec_helper.rb
CHANGED
@@ -119,6 +119,7 @@ class Pet < ActiveRecord::Base
|
|
119
119
|
end
|
120
120
|
Pet.auto_upgrade!
|
121
121
|
|
122
|
+
|
122
123
|
class Task < ActiveRecord::Base
|
123
124
|
col :name
|
124
125
|
col :created_at, :type => :datetime
|
@@ -126,6 +127,12 @@ class Task < ActiveRecord::Base
|
|
126
127
|
end
|
127
128
|
Task.auto_upgrade!
|
128
129
|
|
130
|
+
class Person < ActiveRecord::Base
|
131
|
+
col :"First Name"
|
132
|
+
col :"Last Name"
|
133
|
+
end
|
134
|
+
Person.auto_upgrade!
|
135
|
+
|
129
136
|
require 'zlib'
|
130
137
|
require 'benchmark'
|
131
138
|
require 'faker'
|
data/spec/speed_spec.rb
CHANGED
@@ -45,29 +45,30 @@ describe Upsert do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
48
|
+
|
49
|
+
# FIXME apparently no longer faster?
|
50
|
+
# if ENV['DB'] == 'mysql' && RUBY_VERSION >= '1.9'
|
51
|
+
# describe 'compared to activerecord-import' do
|
52
|
+
# it "is faster than faking upserts with activerecord-import" do
|
53
|
+
# assert_faster_than 'faking upserts with activerecord-import', lotsa_records do |records|
|
54
|
+
# columns = nil
|
55
|
+
# all_values = []
|
56
|
+
# records.each do |selector, setter|
|
57
|
+
# columns ||= (selector.keys + setter.keys).uniq
|
58
|
+
# all_values << columns.map do |k|
|
59
|
+
# if setter.has_key?(k)
|
60
|
+
# # prefer the setter so that you can change rows
|
61
|
+
# setter[k]
|
62
|
+
# else
|
63
|
+
# selector[k]
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
# Pet.import columns, all_values, :timestamps => false, :on_duplicate_key_update => columns
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
# end
|
71
72
|
|
72
73
|
end
|
73
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upsert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seamus Abshere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|