active_record_upsert 0.8.0 → 0.9.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ebd4ad13239063f0e7108c42cb390feba52c688bf8ad4819f9a219d18d101a2
4
- data.tar.gz: f6435a0f03792a85e2644690dac99ab7c0300288862febd5e2b35cb5f9bcf1fe
3
+ metadata.gz: b01678cb29f0661418c62699e1278e500a9704d174f114a63118823798361721
4
+ data.tar.gz: d850a9160cc1b7fe9c6fa2c57843cd983734747689cb2b956d2a357714c1944d
5
5
  SHA512:
6
- metadata.gz: 3f36a02374d2f9c65359fc3354700d2c219bdc0c31cdb9566057e12205433f49abc380f7b67b394974bfc46e519516d3efd9eb0a249847b4a2a7902fcfda55fe
7
- data.tar.gz: 01698ff04fb0f5285b8a95fec88c3c1a132da383d3de4f13e450b841e21a2d255a24a6ec0490cb90eb95d66071bfe7faf6373a2b15ebca0d35e1bc3d13161e1c
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).map(&:to_s)
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 = self[upsert_keys.join(',')]
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)
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordUpsert
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.1"
3
3
  end
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.8.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-04-24 00:00:00.000000000 Z
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.6
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