insert_select 1.0.0 → 1.0.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -7
- data/lib/insert_select/active_record.rb +1 -1
- data/lib/insert_select/builder.rb +4 -1
- data/lib/insert_select/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f35ad1a5ba6691ef951e0b312f72a88f9cf1f63a3c78d365ba609ce328cffb4
|
4
|
+
data.tar.gz: 8d9bdf2e2096814a94d483e156e99e315fbac5f82ae5bc06df57715afd9f36ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ada0f0f8289682ac790410639eaeca097cdf95ae3d1345b4ccadc0e3ec0133cef30b4c966223d29f6212047b5ab78f59d14f3032b6bf98ac9e8c0d6abb2760d6
|
7
|
+
data.tar.gz: 60f34464bab7946821a59620bcee6250407e674e54320a91f0f3310472ac81832159a7ecd684c1f13845f43677695b35de90102819e00e307fee03876b8e8eef
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ gem install insert_select
|
|
34
34
|
|
35
35
|
## Usage
|
36
36
|
|
37
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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:
|
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)
|
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.
|
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-
|
11
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|