arel-mysql-index-hint 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: b494fd4bb3092702e7964b5c9cfc1b0b2f9b6e69
4
- data.tar.gz: 39d422ba66f4ef1cd670a1228aeb19ace36cd1ae
3
+ metadata.gz: 758e3e6dbf40d9363f4663cf9924b01ce6cdabf5
4
+ data.tar.gz: 0b39b9b861187a818a2b072397cef9fbd0a2fa8a
5
5
  SHA512:
6
- metadata.gz: 0c4b471e7da946caf78029c2d3f8f0c41fada63d10db3b2a741a39d2413eeb565cdf37db1c3040a8c5ba7e825be69e280b32eb2684eb501ac885a8a6a7848cae
7
- data.tar.gz: c0e5a925a0177f4f4fb1dcedc5a6d9b58a5b3563ee83b918360a1ef2b74a56329822f6d18253c98ed5b2a9cae16b0b616843ab3e0fddb54df54af805a5bbcfb1
6
+ metadata.gz: cccbf44e580a68b70b041764f5526552f32133e091f67159e6b976239fb4d964c2e0e66ad31f0bffa009e4e78f23af2ec73dfa6d64f2e76348815a3a79f7cbee
7
+ data.tar.gz: 61d096700cc04ea3fb8d78e403d64e6751094a12156af6d6f4ffab3ee1e1aa3f42a7fbb5c0eb234ecba527d6445e2b4f970f1878ef432122c4bd827f015550a9
data/README.md CHANGED
@@ -25,6 +25,9 @@ Or install it yourself as:
25
25
  ## Usage
26
26
 
27
27
  ```ruby
28
+ Article.hint(idx_article: :force)
29
+ # => "SELECT `articles`.* FROM `articles` force INDEX (idx_article)"
30
+
28
31
  Article.joins(:comments).hint(articles: {idx_article: :use})
29
32
  # => "SELECT `articles`.* FROM `articles` use INDEX (idx_article) INNER JOIN `comments` ON `comments`
30
33
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "arel-mysql-index-hint"
4
- spec.version = "0.1.0"
4
+ spec.version = "0.1.1"
5
5
  spec.authors = ["Genki Sugawara"]
6
6
  spec.email = ["sgwr_dts@yahoo.co.jp"]
7
7
  spec.summary = %q{Add index hint to MySQL query in Arel.}
@@ -26,7 +26,16 @@ class Arel::Visitors::MySQL
26
26
 
27
27
  def get_index_hint(table)
28
28
  index_hint_by_table = Thread.current[INDEX_HINT_BY_TABLE_THREAD_KEY]
29
- index_hint_by_table.try(:[], table)
29
+
30
+ if index_hint_by_table.nil? or index_hint_by_table.empty?
31
+ return nil
32
+ end
33
+
34
+ if index_hint_by_table.values.any? {|i| i.is_a?(Hash) }
35
+ index_hint_by_table[table]
36
+ else
37
+ index_hint_by_table
38
+ end
30
39
  end
31
40
 
32
41
  def clear_index_hint_by_table
@@ -0,0 +1,19 @@
1
+ describe "arel-mysql-index-hint" do
2
+ context "unnested hint" do
3
+ subject do
4
+ User.
5
+ hint(index_users_on_email: hint_type).
6
+ to_sql
7
+ end
8
+
9
+ let(:sql) do
10
+ "SELECT `users`.* " +
11
+ "FROM `users` " +
12
+ "#{hint_type} INDEX (index_users_on_email)"
13
+ end
14
+
15
+ let(:hint_type) { :force }
16
+
17
+ it { is_expected.to eq sql }
18
+ end
19
+ end
@@ -74,7 +74,6 @@ describe "arel-mysql-index-hint" do
74
74
 
75
75
  it do
76
76
  subject
77
-
78
77
  expect(sql_log).to include sql
79
78
  end
80
79
  end
@@ -96,7 +95,6 @@ describe "arel-mysql-index-hint" do
96
95
 
97
96
  it do
98
97
  subject
99
-
100
98
  expect(sql_log).to include sql
101
99
  end
102
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel-mysql-index-hint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -146,6 +146,7 @@ files:
146
146
  - spec/arel-mysql-index-hint/includes_spec.rb
147
147
  - spec/arel-mysql-index-hint/joins_spec.rb
148
148
  - spec/arel-mysql-index-hint/preload_spec.rb
149
+ - spec/arel-mysql-index-hint/unnested_hint_spec.rb
149
150
  - spec/arel-mysql-index-hint/without_join_spec.rb
150
151
  - spec/init.sql
151
152
  - spec/models.rb
@@ -179,6 +180,7 @@ test_files:
179
180
  - spec/arel-mysql-index-hint/includes_spec.rb
180
181
  - spec/arel-mysql-index-hint/joins_spec.rb
181
182
  - spec/arel-mysql-index-hint/preload_spec.rb
183
+ - spec/arel-mysql-index-hint/unnested_hint_spec.rb
182
184
  - spec/arel-mysql-index-hint/without_join_spec.rb
183
185
  - spec/init.sql
184
186
  - spec/models.rb