activerecord-insert_many 0.4.1 → 0.4.2

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
  SHA1:
3
- metadata.gz: 6dbaae41683d3696dc009ab77f2336300b575aca
4
- data.tar.gz: 5e27992b665f5eabba30d6c4a78142c26ae38ffb
3
+ metadata.gz: 4f3a11efa931742fc96cb84de9f2f605fd9e1e42
4
+ data.tar.gz: e12ef9f2fac223018001c3c6cb1e09d726e54eb4
5
5
  SHA512:
6
- metadata.gz: 71cfbc32243757c8a395c3db1728fd850fc342b91e7cf87c151891be13b61cad1ec705e5c8d4275d38724b52fb1e82749a6f46af8493650147838c18c93185e0
7
- data.tar.gz: 568d4744662f878b7edea647faad93878b7cb0affd753030fd134bd54c60046f49055e8abf85c7c59ecc8cbd7ce4438a95c030c88c673625719470d34154df90
6
+ metadata.gz: 2e107a6951bd83c3fd519beccac395f6bbc3f89935c01c361601a00dd4784748a64835d8caa088f1aff4da9d266d431b9fe3a43ec3298339bf3bfdf138aeeedf
7
+ data.tar.gz: 48e70bc7be5c1027b80c45c8fb50c45a06cc1ae2fd65061a5e753718ea7db5acabc257cc1f8c6d63a1919543b2934b43920cdcfd25184135065539e20efa022a
@@ -66,14 +66,17 @@ module ActiveRecord
66
66
  conflict_columns = Array.wrap(conflict.fetch(:column, schema_cache.primary_keys(table_name)))
67
67
  raise ArgumentError, "To use the :on_conflict option, you must specify :column" unless conflict_columns.any?
68
68
 
69
+ conflict_do = conflict.fetch(:do)
70
+ raise ArgumentError, "#{conflict_do.inspect} is an unknown value for conflict[:do]; must be :nothing or :update" unless [:nothing, :update].member?(conflict_do)
71
+
69
72
  conflict_columns = conflict_columns.map(&method(:quote_column_name))
70
- case conflict_do = conflict.fetch(:do)
71
- when :nothing
72
- sql << " ON CONFLICT(#{conflict_columns.join(",")}) DO NOTHING"
73
- when :update
74
- sql << " ON CONFLICT(#{conflict_columns.join(",")}) DO UPDATE SET #{(key_list - conflict_columns).map { |key| "#{key} = excluded.#{key}" }.join(", ")}"
73
+ sql << " ON CONFLICT(#{conflict_columns.join(",")})"
74
+ sql << " WHERE #{conflict[:where]}" if conflict[:where]
75
+
76
+ if conflict_do == :nothing
77
+ sql << " DO NOTHING"
75
78
  else
76
- raise ArgumentError, "#{conflict_do.inspect} is an unknown value for conflict[:do]; must be :nothing or :update"
79
+ sql << " DO UPDATE SET #{(key_list - conflict_columns).map { |key| "#{key} = excluded.#{key}" }.join(", ")}"
77
80
  end
78
81
  end
79
82
 
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module InsertMany
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-insert_many
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Booth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-06-07 00:00:00.000000000 Z
12
+ date: 2018-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord