activerecord-mysql-index-hint 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b947256880defc67e564ff3b5710672ef010b8d8
4
+ data.tar.gz: acd5aeea0b4cdc5aa6ef031a96831b678c5f7c7f
5
+ SHA512:
6
+ metadata.gz: e2375a761ac04b91400e5483b492612c242ce50a07e516def9dc5dc5101f941482ec662d890c3901e4d9fea9b1d8bfc274ba870328711945d46d8682af6729ad
7
+ data.tar.gz: 1fb48165d7f17a309cc09090738b8d39bd3964f44d36bad6dd38917fee7b9ea510b812c644282c4bf6d2c758df93a17afe27066d04d12c66f32c18a7f75658a2
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ gemfiles/*.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ install: bundle install
5
+ script: bundle exec rake spec
6
+ gemfile:
7
+ - gemfiles/3.2.gemfile
8
+ - gemfiles/4.0.gemfile
@@ -0,0 +1,9 @@
1
+ appraise "3.2" do
2
+ gem "activerecord", "~> 3.2.15"
3
+ gem "activerecord-mysql-index-hint", :path => "../"
4
+ end
5
+
6
+ appraise "4.0" do
7
+ gem "activerecord", "~> 4.0.0"
8
+ gem "activerecord-mysql-index-hint", :path => "../"
9
+ end
@@ -0,0 +1,3 @@
1
+ # ChangeLog
2
+ ## 0.0.1
3
+ - First release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord-mysql-index-hint.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Issei Naruta
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ [![Build Status](https://travis-ci.org/mirakui/activerecord-mysql-index-hint.png)](https://travis-ci.org/mirakui/activerecord-mysql-index-hint)
2
+
3
+ # activerecord-mysql-index-hint
4
+
5
+ MySQL index hint support for ActiveRecord
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'activerecord-mysql-index-hint'
12
+
13
+ ## Usage
14
+
15
+ class Product < ActiveRecord::Base
16
+ end
17
+
18
+ Product.where(user_id: 1).force_index(:idx_user_id).first
19
+ # => SELECT `products`.* FROM `products` FORCE INDEX(`idx_user_id`) WHERE `products`.`user_id` = 1 LIMIT 1
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'appraisal'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activerecord-mysql-index-hint/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord-mysql-index-hint"
8
+ spec.version = ActiveRecordMysqlIndexHint::VERSION
9
+ spec.authors = ["Issei Naruta"]
10
+ spec.email = ["naruta@cookpad.com"]
11
+ spec.description = %q{MySQL index hint support for ActiveRecord}
12
+ spec.summary = %q{MySQL index hint support for ActiveRecord}
13
+ spec.homepage = "https://github.com/mirakui/activerecord-mysql-index-hint"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^spec/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'activerecord', '>= 3.1'
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'appraisal'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'mysql2'
26
+ end
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.15"
6
+ gem "activerecord-mysql-index-hint", :path=>"../"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+ gem "activerecord-mysql-index-hint", :path=>"../"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,26 @@
1
+ require 'active_record'
2
+ require 'active_record/relation/query_methods'
3
+
4
+ module ActiveRecordMysqlIndexHint
5
+ def use_index(*args)
6
+ from_with_index_hint 'USE', *args
7
+ end
8
+
9
+ def force_index(*args)
10
+ from_with_index_hint 'FORCE', *args
11
+ end
12
+
13
+ def ignore_index(*args)
14
+ from_with_index_hint 'IGNORE', *args
15
+ end
16
+
17
+ private
18
+ def from_with_index_hint(hint_type, *args)
19
+ return self if args.blank?
20
+ indexes = args.map {|index| connection.quote_column_name index }
21
+ self.from("#{quoted_table_name} #{hint_type} INDEX(#{indexes.join(', ')})")
22
+ end
23
+ end
24
+
25
+ ActiveRecord::Base.send :extend, ActiveRecordMysqlIndexHint
26
+ ActiveRecord::Relation.send :include, ActiveRecordMysqlIndexHint
@@ -0,0 +1,3 @@
1
+ module ActiveRecordMysqlIndexHint
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,68 @@
1
+ require 'active_record'
2
+ require 'mysql2'
3
+ require 'active_record/connection_adapters/mysql2_adapter'
4
+ require 'activerecord-mysql-index-hint'
5
+
6
+ module Mysql2
7
+ class Client
8
+ def initialize(opts={})
9
+ @query_options = @@default_query_options.dup.merge opts
10
+ end
11
+ end
12
+ end
13
+
14
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter.class_eval do
15
+ def quote_string(string)
16
+ string
17
+ end
18
+ def configure_connection
19
+ end
20
+ end
21
+
22
+ Arel::Visitors::ToSql.class_eval do
23
+ def column_for o
24
+ nil
25
+ end
26
+ end
27
+
28
+ class Product < ActiveRecord::Base
29
+ establish_connection 'mysql2://user@host/db'
30
+ end
31
+
32
+ describe 'ActiveRecord Index Hint' do
33
+ context 'with AR::Relation' do
34
+ it do
35
+ expect(
36
+ Product.limit(1).use_index(:idx1).to_sql
37
+ ).to eq('SELECT `products`.* FROM `products` USE INDEX(`idx1`) LIMIT 1')
38
+ end
39
+
40
+ it do
41
+ expect(
42
+ Product.limit(1).force_index(:idx1).to_sql
43
+ ).to eq('SELECT `products`.* FROM `products` FORCE INDEX(`idx1`) LIMIT 1')
44
+ end
45
+
46
+ it do
47
+ expect(
48
+ Product.limit(1).ignore_index(:idx1).to_sql
49
+ ).to eq('SELECT `products`.* FROM `products` IGNORE INDEX(`idx1`) LIMIT 1')
50
+ end
51
+ end
52
+
53
+ context 'with AR::Base' do
54
+ it do
55
+ expect(
56
+ Product.use_index(:idx1).limit(1).to_sql
57
+ ).to eq('SELECT `products`.* FROM `products` USE INDEX(`idx1`) LIMIT 1')
58
+ end
59
+ end
60
+
61
+ context 'with multiple indexes' do
62
+ it do
63
+ expect(
64
+ Product.limit(1).use_index(:idx1, :idx2).to_sql
65
+ ).to eq('SELECT `products`.* FROM `products` USE INDEX(`idx1`, `idx2`) LIMIT 1')
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-mysql-index-hint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Issei Naruta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mysql2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: MySQL index hint support for ActiveRecord
98
+ email:
99
+ - naruta@cookpad.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
+ - Appraisals
108
+ - ChangeLog.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - activerecord-mysql-index-hint.gemspec
114
+ - gemfiles/3.2.gemfile
115
+ - gemfiles/4.0.gemfile
116
+ - lib/activerecord-mysql-index-hint.rb
117
+ - lib/activerecord-mysql-index-hint/version.rb
118
+ - spec/activerecord-mysql-index-hint_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://github.com/mirakui/activerecord-mysql-index-hint
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.0.3
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: MySQL index hint support for ActiveRecord
144
+ test_files:
145
+ - spec/activerecord-mysql-index-hint_spec.rb
146
+ - spec/spec_helper.rb