active_record_upsert 0.8.0 → 0.9.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b01678cb29f0661418c62699e1278e500a9704d174f114a63118823798361721
|
4
|
+
data.tar.gz: d850a9160cc1b7fe9c6fa2c57843cd983734747689cb2b956d2a357714c1944d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66ea79bd414e4d03f0a2ef54d309fb65092a2e40170ee399d28df47fd5fbbe3a0c657a4c16d7615d03dd5d235444c72f8478542249ea66279a36f57076d2b8d4
|
7
|
+
data.tar.gz: c35cc444d6abac21f43e49d0c588b65347b45d6692d0f2528846f02d05a28cd2241486f9496312ccaa2621966afc5a2b4babb84c305463f02d223644a9336fcb
|
data/README.md
CHANGED
@@ -148,6 +148,14 @@ class Account < ApplicationRecord
|
|
148
148
|
end
|
149
149
|
```
|
150
150
|
|
151
|
+
Custom index can be handled with a Hash containing a literal key :
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
class Account < ApplicationRecord
|
155
|
+
upsert_keys literal: 'md5(my_long_field)'
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
151
159
|
## Tests
|
152
160
|
|
153
161
|
Make sure to have an upsert_test database:
|
@@ -176,3 +184,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jesjos
|
|
176
184
|
- Timo Schilling ([@timoschilling](https://github.com/timoschilling))
|
177
185
|
- Benedikt Deicke ([@benedikt](https://github.com/benedikt))
|
178
186
|
- Daniel Cooper ([@danielcooper](https://github.com/danielcooper))
|
187
|
+
- Laurent Vallar ([@val](https://github.com/val))
|
188
|
+
- Emmanuel Quentin ([@manuquentin](https://github.com/manuquentin))
|
@@ -75,7 +75,7 @@ module ActiveRecordUpsert
|
|
75
75
|
options = keys.extract_options!
|
76
76
|
keys = keys.first if keys.size == 1 # support single string/symbol, multiple string/symbols, and array
|
77
77
|
return if keys.nil?
|
78
|
-
@_upsert_keys = Array(keys)
|
78
|
+
@_upsert_keys = Array(keys)
|
79
79
|
@_upsert_options = options
|
80
80
|
end
|
81
81
|
|
@@ -12,9 +12,11 @@
|
|
12
12
|
module Arel
|
13
13
|
module Crud
|
14
14
|
def compile_upsert(upsert_keys, upsert_options, upsert_values, insert_values, wheres)
|
15
|
+
# Support non-attribute key (like `md5(my_attribute)``)
|
16
|
+
target = self[upsert_options.key?(:literal) ? ::Arel::Nodes::SqlLiteral.new(upsert_options[:literal]) : upsert_keys.join(',')]
|
15
17
|
on_conflict_do_update = OnConflictDoUpdateManager.new
|
16
18
|
|
17
|
-
on_conflict_do_update.target =
|
19
|
+
on_conflict_do_update.target = target
|
18
20
|
on_conflict_do_update.target_condition = upsert_options[:where]
|
19
21
|
on_conflict_do_update.wheres = wheres
|
20
22
|
on_conflict_do_update.set(upsert_values)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_upsert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesper Josefsson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.7.
|
133
|
+
rubygems_version: 2.7.7
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: Real PostgreSQL 9.5+ upserts using ON CONFLICT for ActiveRecord
|