activerecord_upsert 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +16 -8
- data/.travis/gemfiles/{Gemfile-no-cpk → rails5-no-cpk.gemfile} +2 -0
- data/.travis/gemfiles/rails5.gemfile +7 -0
- data/.travis/gemfiles/rails6-no-cpk.gemfile +6 -0
- data/.travis/gemfiles/rails6.gemfile +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +2 -1
- data/README.md +2 -2
- data/activerecord_upsert.gemspec +2 -2
- data/lib/active_record_upsert.rb +2 -8
- data/lib/active_record_upsert/active_record.rb +18 -0
- data/lib/active_record_upsert/{active_record → active_record5}/relation.rb +1 -1
- data/lib/active_record_upsert/active_record6/relation.rb +15 -0
- data/lib/active_record_upsert/version.rb +1 -1
- metadata +15 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f720ddde1a95fa6611eb84c3a799c4cf64f9c72a2bbbb595f88f91fccda921e3
|
4
|
+
data.tar.gz: 4a360f14abccbdd55d0fdc77178c7c4d03e1f26d36126baacc1012866dfc38ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b264d9f72178e27d6bc476fe5734452557bcbc609ab50c46ac23d097f86f88951b745828b90cd8455e54f3c44119090426b537bbf5425174d7ece3453e26abd6
|
7
|
+
data.tar.gz: b87c93ff47ff37470a966ae85b314a8319cb374a6a5889d7f8cf06376ebece93c28c768b55802fac3006abaecc5d388644bba891acb75f33fea0f587df935284
|
data/.travis.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
os: linux
|
2
|
+
|
2
3
|
language: ruby
|
3
4
|
services:
|
4
5
|
- mysql
|
@@ -11,15 +12,22 @@ rvm:
|
|
11
12
|
- 2.4.9
|
12
13
|
- 2.5.7
|
13
14
|
- 2.6.5
|
14
|
-
- 2.7.0
|
15
|
+
- 2.7.0
|
15
16
|
gemfile:
|
16
|
-
-
|
17
|
-
- .travis/gemfiles/
|
17
|
+
- .travis/gemfiles/rails5.gemfile
|
18
|
+
- .travis/gemfiles/rails5-no-cpk.gemfile
|
19
|
+
- .travis/gemfiles/rails6.gemfile
|
20
|
+
- .travis/gemfiles/rails6-no-cpk.gemfile
|
18
21
|
before_install:
|
19
22
|
- gem install bundler -v 2.0.2
|
20
23
|
- mysql -e 'CREATE DATABASE active_record_upsert_test;'
|
21
24
|
matrix:
|
22
|
-
|
23
|
-
- rvm: 2.
|
24
|
-
|
25
|
-
|
25
|
+
exclude:
|
26
|
+
- rvm: 2.3.8
|
27
|
+
gemfile: .travis/gemfiles/rails6.gemfile
|
28
|
+
- rvm: 2.3.8
|
29
|
+
gemfile: .travis/gemfiles/rails6-no-cpk.gemfile
|
30
|
+
- rvm: 2.4.9
|
31
|
+
gemfile: .travis/gemfiles/rails6.gemfile
|
32
|
+
- rvm: 2.4.9
|
33
|
+
gemfile: .travis/gemfiles/rails6-no-cpk.gemfile
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/dvandersluis/activerecord_upsert.svg?branch=master)](https://travis-ci.org/dvandersluis/activerecord_upsert)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/activerecord_upsert.svg)](https://badge.fury.io/rb/activerecord_upsert)
|
5
5
|
|
6
|
-
Adds the ability to use MySQL's `ON DUPLICATE KEY UPDATE` to upsert records in ActiveRecord.
|
6
|
+
Adds the ability to use MySQL's `ON DUPLICATE KEY UPDATE` with arbitrary values in order to upsert records in ActiveRecord.
|
7
7
|
|
8
|
-
|
8
|
+
Supports Rails 5.2 and 6, and should not conflict with Rails 6's `Model.upsert` or `Model.upsert_all`, because this gem adds `upsert` to `ActiveRecord::Relation`.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
data/activerecord_upsert.gemspec
CHANGED
@@ -29,12 +29,12 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ['lib']
|
30
30
|
|
31
31
|
spec.add_dependency 'mysql2'
|
32
|
-
spec.add_dependency 'activerecord', '>= 5.2', '<
|
32
|
+
spec.add_dependency 'activerecord', '>= 5.2', '< 7'
|
33
33
|
|
34
34
|
spec.add_development_dependency('bundler', '~> 2.0')
|
35
35
|
spec.add_development_dependency('database_cleaner', '~> 1.7.0')
|
36
36
|
spec.add_development_dependency('pry', '~> 0.12.0')
|
37
|
-
spec.add_development_dependency('rake', '
|
37
|
+
spec.add_development_dependency('rake', '>= 12.3.3')
|
38
38
|
spec.add_development_dependency('rspec', '~> 3.0')
|
39
39
|
spec.add_development_dependency('rubocop', '~> 0.75.0')
|
40
40
|
spec.add_development_dependency('rubocop-rspec', '~> 1.36.0')
|
data/lib/active_record_upsert.rb
CHANGED
@@ -6,16 +6,10 @@ require 'active_record'
|
|
6
6
|
require 'active_record_upsert/arel/insert_manager'
|
7
7
|
require 'active_record_upsert/arel/insert_statement'
|
8
8
|
require 'active_record_upsert/arel/visitors/mysql'
|
9
|
-
|
10
|
-
require 'active_record_upsert/active_record/persistence'
|
11
|
-
require 'active_record_upsert/active_record/relation'
|
12
|
-
|
13
|
-
module ActiveRecordUpsert
|
14
|
-
end
|
9
|
+
require 'active_record_upsert/active_record'
|
15
10
|
|
16
11
|
Arel::Nodes::InsertStatement.include ActiveRecordUpsert::Arel::InsertStatement
|
17
12
|
Arel::InsertManager.include ActiveRecordUpsert::Arel::InsertManager
|
18
13
|
Arel::Visitors::MySQL.prepend ActiveRecordUpsert::Arel::Visitors::MySQL
|
19
14
|
|
20
|
-
ActiveRecord::
|
21
|
-
ActiveRecord::Persistence::ClassMethods.include ActiveRecordUpsert::ActiveRecord::Persistence
|
15
|
+
ActiveRecord::Base.include ActiveRecordUpsert::ActiveRecord
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ActiveRecordUpsert
|
2
|
+
module ActiveRecord
|
3
|
+
def self.included(*)
|
4
|
+
require 'active_record_upsert/active_record/persistence'
|
5
|
+
::ActiveRecord::Base.extend ActiveRecordUpsert::ActiveRecord::Persistence
|
6
|
+
|
7
|
+
if ::ActiveRecord::VERSION::MAJOR == 5
|
8
|
+
require 'active_record_upsert/active_record5/relation'
|
9
|
+
|
10
|
+
::ActiveRecord::Relation.include ActiveRecordUpsert::ActiveRecord5::Relation
|
11
|
+
elsif ::ActiveRecord::VERSION::MAJOR == 6
|
12
|
+
require 'active_record_upsert/active_record6/relation'
|
13
|
+
|
14
|
+
::ActiveRecord::Relation.include ActiveRecordUpsert::ActiveRecord6::Relation
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecordUpsert
|
2
|
+
module ActiveRecord6
|
3
|
+
module Relation
|
4
|
+
def upsert(on_duplicate = nil)
|
5
|
+
scoping { klass._upsert_record(values_for_create, on_duplicate) }
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def values_for_create
|
11
|
+
klass.current_scope.values[:where].to_h
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_upsert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vandersluis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '5.2'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '7'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '5.2'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '7'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,16 +90,16 @@ dependencies:
|
|
90
90
|
name: rake
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: 12.3.3
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - "
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
102
|
+
version: 12.3.3
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: rspec
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,7 +167,10 @@ files:
|
|
167
167
|
- ".rspec"
|
168
168
|
- ".rubocop.yml"
|
169
169
|
- ".travis.yml"
|
170
|
-
- ".travis/gemfiles/
|
170
|
+
- ".travis/gemfiles/rails5-no-cpk.gemfile"
|
171
|
+
- ".travis/gemfiles/rails5.gemfile"
|
172
|
+
- ".travis/gemfiles/rails6-no-cpk.gemfile"
|
173
|
+
- ".travis/gemfiles/rails6.gemfile"
|
171
174
|
- CHANGELOG.md
|
172
175
|
- Gemfile
|
173
176
|
- README.md
|
@@ -176,8 +179,10 @@ files:
|
|
176
179
|
- bin/console
|
177
180
|
- bin/setup
|
178
181
|
- lib/active_record_upsert.rb
|
182
|
+
- lib/active_record_upsert/active_record.rb
|
179
183
|
- lib/active_record_upsert/active_record/persistence.rb
|
180
|
-
- lib/active_record_upsert/
|
184
|
+
- lib/active_record_upsert/active_record5/relation.rb
|
185
|
+
- lib/active_record_upsert/active_record6/relation.rb
|
181
186
|
- lib/active_record_upsert/arel/insert_manager.rb
|
182
187
|
- lib/active_record_upsert/arel/insert_statement.rb
|
183
188
|
- lib/active_record_upsert/arel/visitors/mysql.rb
|