insert_select 1.0.0 → 1.0.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: d101071399faca09bdda11935c64dd05cd278c5d6f09cb868297bd8a39763050
4
- data.tar.gz: 955f3d4f643fc7d63898d6b790e442a58df26494e66893c4bf6f61cfa10d11fb
3
+ metadata.gz: 5f35ad1a5ba6691ef951e0b312f72a88f9cf1f63a3c78d365ba609ce328cffb4
4
+ data.tar.gz: 8d9bdf2e2096814a94d483e156e99e315fbac5f82ae5bc06df57715afd9f36ec
5
5
  SHA512:
6
- metadata.gz: e6be590eef3ffd3f4f746acc8334dd21175b1621c4a90a1dff4e8597e7bd6505f3d4b684c16e304fde6f86dd98f67cd80458f28b08fa0c47cb9fe06921caffa0
7
- data.tar.gz: 75ec347e6e56e2eb405545c741645e81ac04ba1932a5c00515fa0411aebd3b6fc7c38a5213bf5fcce2c4470fd0f926a596a1deb18f8fb08322936ef243cb7758
6
+ metadata.gz: ada0f0f8289682ac790410639eaeca097cdf95ae3d1345b4ccadc0e3ec0133cef30b4c966223d29f6212047b5ab78f59d14f3032b6bf98ac9e8c0d6abb2760d6
7
+ data.tar.gz: 60f34464bab7946821a59620bcee6250407e674e54320a91f0f3310472ac81832159a7ecd684c1f13845f43677695b35de90102819e00e307fee03876b8e8eef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- insert_select (1.0.0)
4
+ insert_select (1.0.1)
5
5
  activerecord
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -34,7 +34,7 @@ gem install insert_select
34
34
 
35
35
  ## Usage
36
36
 
37
- ### Copy all data from OldUser to NewUser
37
+ #### Copy all data from OldUser to NewUser
38
38
 
39
39
  ```ruby
40
40
  NewUser.insert_select_from(OldUser)
@@ -42,7 +42,7 @@ NewUser.insert_select_from(OldUser)
42
42
  #=> INSERT INTO "new_users" SELECT "old_users".* FROM "old_users"
43
43
  ```
44
44
 
45
- ### Filter the columns to be copied
45
+ #### Filter the columns to be copied
46
46
 
47
47
  ```ruby
48
48
  NewUser.insert_select_from(OldUser.select(:name))
@@ -50,7 +50,7 @@ NewUser.insert_select_from(OldUser.select(:name))
50
50
  #=> INSERT INTO "new_users" ("name") SELECT "old_users"."name" FROM "old_users"
51
51
  ```
52
52
 
53
- ### Copy data between different column names
53
+ #### Copy data between different column names
54
54
 
55
55
  You can specify column name mappings between tables.
56
56
  ```ruby
@@ -59,27 +59,27 @@ AnotherUser.insert_select_from(OldUser, mapping: { old_name: :another_name })
59
59
  #=> INSERT INTO "another_users" ("another_name") SELECT "old_users"."name" FROM "old_users"
60
60
  ```
61
61
 
62
- ### Set a constant value
62
+ #### Set a constant value
63
63
  ```ruby
64
64
  AnotherUser.create_with(another_constant_column: "20").insert_select_from(OldUser, mapping: { old_name: :another_name })
65
65
 
66
66
  #=> INSERT INTO "another_users" ("another_name", "another_constant_column") SELECT "old_users"."name", "20" FROM "old_users"
67
67
  ```
68
68
 
69
- ### Use a WHERE clause to filter the data
69
+ #### Use a WHERE clause to filter the data
70
70
  ```ruby
71
71
  NewUser.insert_select_from(OldUser.where("age > ?", 20))
72
72
 
73
73
  #=> INSERT INTO "new_users" SELECT "old_users".*, FROM "old_users" WHERE ("age" > 20)
74
74
  ```
75
75
 
76
- ### Use the RETURNING clause (only for PostgreSQL connection)
76
+ #### Use the RETURNING clause (only for PostgreSQL connection)
77
77
  ```ruby
78
78
  NewUser.insert_select_from(OldUser, returning: [:id])
79
79
 
80
80
  #=> INSERT INTO "new_users" SELECT "old_users".* FROM "old_users" RETURNING "id"
81
81
  ```
82
- ### bang method
82
+ #### Bang method
83
83
  In default, any duplicated records are skipped in the `insert_select_from` method.
84
84
  If you want to raise an error when a duplicated record is found, use the bang method.
85
85
 
@@ -38,7 +38,7 @@ module InsertSelect
38
38
  end
39
39
 
40
40
  def insert_select_from!(relation, mapping: {}, returning: nil)
41
- InsertSelect::ActiveRecord::InsertSelectFrom.new(self, relation, mapping: mapping, on_duplicate: nil, returning: returning).execute
41
+ InsertSelect::ActiveRecord::InsertSelectFrom.new(self, relation, mapping: mapping, on_duplicate: :raise, returning: returning).execute
42
42
  end
43
43
 
44
44
  def except(*columns)
@@ -59,7 +59,10 @@ module InsertSelect
59
59
  end
60
60
 
61
61
  def constant_values
62
- constant_mapping.values
62
+ constant_mapping.map do |k, v|
63
+ type = model.type_for_attribute(k.to_s)
64
+ type.serialize(v)
65
+ end
63
66
  end
64
67
 
65
68
  def reselect_relation!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InsertSelect
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insert_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - a5-stable
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-01 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord