query_optimizer 0.0.1 → 0.1.0
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/Manifest +1 -3
- data/README.md +2 -31
- data/Rakefile +13 -1
- data/lib/query_optimizer.rb +3 -4
- data/query_optimizer.gemspec +18 -20
- metadata +20 -47
- data/.gitignore +0 -14
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.rdoc +0 -48
- data/lib/query_optimizer/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be3cff45e146082c521b71a9275046c62034c9f6
|
4
|
+
data.tar.gz: 1594b2134c8f7a1612c7c00cf4f394b3e8182691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b02a9208c6a2ea5741f47e26148e3e995d3dc3215482e491cf873e595535e33e382a5769b09345744d68e14111e16b13a10bff229499506b9a42d182c109091a
|
7
|
+
data.tar.gz: 2cb455105cd58e1f7efff6f8ae6a5e8e4e9b9381d8986635e40030978437a870376ff04bc5996cffcdcced6157e08db59f12c7ec1739dc6caec07c0919947f1b
|
data/Manifest
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,2 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'query_optimizer'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install query_optimizer
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
24
|
-
|
25
|
-
## Contributing
|
26
|
-
|
27
|
-
1. Fork it ( https://github.com/[my-github-username]/query_optimizer/fork )
|
28
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
-
5. Create a new Pull Request
|
1
|
+
# query_optimizer
|
2
|
+
This is rails gem which will minimize query for many_to_many relationship
|
data/Rakefile
CHANGED
@@ -1,2 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
2
4
|
|
5
|
+
Echoe.new('query_optimizer', '0.1.0') do |p|
|
6
|
+
p.description = "Minimize query for fetching table row"
|
7
|
+
p.url = "http://github.com/akshaygoyal88/query_optimizer"
|
8
|
+
p.author = "Akshay Goyal"
|
9
|
+
p.email = "akshay.goyal1008@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/lib/query_optimizer.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module QueryOptimizer
|
2
2
|
def self.optimize_query(model1,model2)
|
3
|
-
table1 = model1.
|
4
|
-
table2 = model2.
|
5
|
-
|
6
|
-
results = ActiveRecord::Base.connection.execute("SELECT #{table1}.*,#{table2}.* FROM #{table1} INNER JOIN #{table2} on #{table1}.id=#{table2}.#{get_singular_name}_id")
|
3
|
+
table1 = model1.to_s.downcase.pluralize
|
4
|
+
table2 = model2.to_s.downcase.pluralize
|
5
|
+
results = ActiveRecord::Base.connection.execute("SELECT #{table1}.*,#{table2}.* FROM #{table1} INNER JOIN #{table2} on #{table1}.id=#{table2}.post_id")
|
7
6
|
table1_columns = model1.column_names
|
8
7
|
table2_columns = model2.column_names
|
9
8
|
table1_columns = table1_columns.map { |word| "#{table1}_#{word}" }
|
data/query_optimizer.gemspec
CHANGED
@@ -1,23 +1,21 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'query_optimizer/version'
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: query_optimizer 0.1.0 ruby lib
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
spec.authors = ["Akshay"]
|
10
|
-
spec.email = ["akshay.goyal1008@gmail.com"]
|
11
|
-
spec.summary = %q{This is rails gem which will minimize query for many_to_many relationship}
|
12
|
-
spec.description = %q{This is rails gem which will minimize query for many_to_many relationship.}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "query_optimizer"
|
6
|
+
s.version = "0.1.0"
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib"]
|
10
|
+
s.authors = ["Akshay Goyal"]
|
11
|
+
s.date = "2015-10-18"
|
12
|
+
s.description = "Minimize query for fetching table row"
|
13
|
+
s.email = "akshay.goyal1008@gmail.com"
|
14
|
+
s.extra_rdoc_files = ["LICENSE", "README.md", "lib/query_optimizer.rb"]
|
15
|
+
s.files = ["LICENSE", "Manifest", "README.md", "Rakefile", "lib/query_optimizer.rb", "query_optimizer.gemspec"]
|
16
|
+
s.homepage = "http://github.com/akshaygoyal88/query_optimizer"
|
17
|
+
s.rdoc_options = ["--line-numbers", "--title", "Query_optimizer", "--main", "README.md"]
|
18
|
+
s.rubyforge_project = "query_optimizer"
|
19
|
+
s.rubygems_version = "2.2.2"
|
20
|
+
s.summary = "Minimize query for fetching table row"
|
23
21
|
end
|
metadata
CHANGED
@@ -1,67 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Akshay
|
7
|
+
- Akshay Goyal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-10-18 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.7'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '10.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.0'
|
41
|
-
description: This is rails gem which will minimize query for many_to_many relationship.
|
42
|
-
email:
|
43
|
-
- akshay.goyal1008@gmail.com
|
12
|
+
dependencies: []
|
13
|
+
description: Minimize query for fetching table row
|
14
|
+
email: akshay.goyal1008@gmail.com
|
44
15
|
executables: []
|
45
16
|
extensions: []
|
46
|
-
extra_rdoc_files:
|
17
|
+
extra_rdoc_files:
|
18
|
+
- LICENSE
|
19
|
+
- README.md
|
20
|
+
- lib/query_optimizer.rb
|
47
21
|
files:
|
48
|
-
- ".gitignore"
|
49
|
-
- Gemfile
|
50
22
|
- LICENSE
|
51
|
-
- LICENSE.txt
|
52
23
|
- Manifest
|
53
24
|
- README.md
|
54
|
-
- README.rdoc
|
55
25
|
- Rakefile
|
56
26
|
- lib/query_optimizer.rb
|
57
|
-
- lib/query_optimizer/version.rb
|
58
27
|
- query_optimizer.gemspec
|
59
|
-
homepage:
|
60
|
-
licenses:
|
61
|
-
- MIT
|
28
|
+
homepage: http://github.com/akshaygoyal88/query_optimizer
|
29
|
+
licenses: []
|
62
30
|
metadata: {}
|
63
31
|
post_install_message:
|
64
|
-
rdoc_options:
|
32
|
+
rdoc_options:
|
33
|
+
- "--line-numbers"
|
34
|
+
- "--title"
|
35
|
+
- Query_optimizer
|
36
|
+
- "--main"
|
37
|
+
- README.md
|
65
38
|
require_paths:
|
66
39
|
- lib
|
67
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -73,11 +46,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
46
|
requirements:
|
74
47
|
- - ">="
|
75
48
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
49
|
+
version: '1.2'
|
77
50
|
requirements: []
|
78
|
-
rubyforge_project:
|
51
|
+
rubyforge_project: query_optimizer
|
79
52
|
rubygems_version: 2.2.2
|
80
53
|
signing_key:
|
81
54
|
specification_version: 4
|
82
|
-
summary:
|
55
|
+
summary: Minimize query for fetching table row
|
83
56
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2015 Akshay
|
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.
|
data/README.rdoc
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
{<img src="https://badge.fury.io/rb/query_optimizer.png" alt="Gem Version" />}[http://badge.fury.io/rb/query_optimizer]
|
2
|
-
|
3
|
-
= query_optimizer
|
4
|
-
|
5
|
-
* http://github.com/akshaygoyal88/query_optimizer
|
6
|
-
|
7
|
-
== FEATURES:
|
8
|
-
|
9
|
-
query_optimizer is the best gem for optimizing query in rails for has_many and belongs_to relationship two tables.
|
10
|
-
In rails If you want all posts and its related comments in a single query than you can't get it
|
11
|
-
as Post.incldes(:comments) or Post.joins(:comments) will return only posts array and Comment.incldes(:posts) will return only comments array
|
12
|
-
For fetching each post comment you have to fire query from view as below output of post.comments in each with index loop.
|
13
|
-
|
14
|
-
Started GET "/" for 127.0.0.1 at 2015-10-18 14:12:11 +0530
|
15
|
-
Processing by PostsController#index as HTML
|
16
|
-
Post Load (0.5ms) SELECT `posts`.* FROM `posts`
|
17
|
-
Comment Load (0.3ms) SELECT `comments`.* FROM `comments` WHERE `comments`.`post_id` = 44
|
18
|
-
Rendered comments/_comment.html.erb (0.5ms)
|
19
|
-
Rendered posts/_post.html.erb (6.3ms)
|
20
|
-
Comment Load (0.6ms) SELECT `comments`.* FROM `comments` WHERE `comments`.`post_id` = 45
|
21
|
-
Rendered comments/_comment.html.erb (0.3ms)
|
22
|
-
Rendered posts/_post.html.erb (5.2ms)
|
23
|
-
Comment Load (0.6ms) SELECT `comments`.* FROM `comments` WHERE `comments`.`post_id` = 46
|
24
|
-
Rendered comments/_comment.html.erb (0.3ms)
|
25
|
-
Rendered posts/_post.html.erb (5.6ms)
|
26
|
-
Comment Load (0.6ms) SELECT `comments`.* FROM `comments` WHERE `comments`.`post_id` = 47
|
27
|
-
Rendered collection (0.0ms)
|
28
|
-
Rendered posts/_post.html.erb (4.1ms)
|
29
|
-
Rendered posts/index.html.erb within layouts/application (31.7ms)
|
30
|
-
|
31
|
-
== DESCRIPTION:
|
32
|
-
so to minimize query you can use query_optimizer you can just pass your model name as QueryOptimizer.optimize_query(Model1,Model2)
|
33
|
-
|
34
|
-
require 'query_optimizer'
|
35
|
-
QueryOptimizer.optimize_query(Post,Comment)
|
36
|
-
|
37
|
-
(1.1ms) SELECT posts.*,comments.* FROM posts INNER JOIN comments on posts.id=comments.post_id
|
38
|
-
=> [{"posts_id"=>44, "posts_name"=>"name1", "posts_description"=>"desc1", "posts_created_at"=>2015-02-01 10:40:05 UTC, "posts_updated_at"=>2015-02-01 10:40:05 UTC, "comments_id"=>4, "comments_name"=>"gdfdhddffdd", "comments_description"=>nil, "comments_post_id"=>44, "comments_created_at"=>2015-10-10 16:49:12 UTC, "comments_updated_at"=>2015-10-10 16:49:12 UTC}, {"posts_id"=>45, "posts_name"=>"name2", "posts_description"=>"desc2", "posts_created_at"=>2015-02-01 10:40:05 UTC, "posts_updated_at"=>2015-02-01 10:40:05 UTC, "comments_id"=>5, "comments_name"=>"dhdfdfhdhdfhfd", "comments_description"=>nil, "comments_post_id"=>45, "comments_created_at"=>2015-10-10 16:49:19 UTC, "comments_updated_at"=>2015-10-10 16:49:19 UTC}, {"posts_id"=>44, "posts_name"=>"name3", "posts_description"=>"desc3", "posts_created_at"=>2015-02-01 10:40:05 UTC, "posts_updated_at"=>2015-02-01 10:40:05 UTC, "comments_id"=>6, "comments_name"=>"hfdhdfhdf", "comments_description"=>nil, "comments_post_id"=>44, "comments_created_at"=>2015-10-10 16:51:26 UTC, "comments_updated_at"=>2015-10-10 16:51:26 UTC}, {"posts_id"=>46, "posts_name"=>"name3", "posts_description"=>"desc3", "posts_created_at"=>2015-02-01 10:41:14 UTC, "posts_updated_at"=>2015-02-01 10:41:14 UTC, "comments_id"=>7, "comments_name"=>"dhdfdfhdfhdf", "comments_description"=>nil, "comments_post_id"=>46, "comments_created_at"=>2015-10-10 16:51:32 UTC, "comments_updated_at"=>2015-10-10 16:51:32 UTC}]
|
39
|
-
|
40
|
-
It will return posts and its related comments in a single array
|
41
|
-
|
42
|
-
== REQUIREMENTS:
|
43
|
-
|
44
|
-
* rails
|
45
|
-
|
46
|
-
== INSTALL:
|
47
|
-
|
48
|
-
* gem install query_optimizer
|