query_optimizer 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: be3cff45e146082c521b71a9275046c62034c9f6
4
- data.tar.gz: 1594b2134c8f7a1612c7c00cf4f394b3e8182691
3
+ metadata.gz: 3d39bb02dc7d380c9fa32d98e39a0feda065ae7f
4
+ data.tar.gz: 275ebf3273e53b7ea9a78b21ae8326d65393c6bb
5
5
  SHA512:
6
- metadata.gz: b02a9208c6a2ea5741f47e26148e3e995d3dc3215482e491cf873e595535e33e382a5769b09345744d68e14111e16b13a10bff229499506b9a42d182c109091a
7
- data.tar.gz: 2cb455105cd58e1f7efff6f8ae6a5e8e4e9b9381d8986635e40030978437a870376ff04bc5996cffcdcced6157e08db59f12c7ec1739dc6caec07c0919947f1b
6
+ metadata.gz: d41155b5ea2e718eafdc725ed953816052356376f7cf1fbabcd4ccf2df2759b1ff1fd110289f8356c4880f3cf66c087c6e4b92e54f7d52d6d6205380d66b0135
7
+ data.tar.gz: f865c563f6050da8534d828959827c738c3b81803ce20f57483ef14bc9fe0020b7b246cf9c0fcb710314b9288ea9b5bb4e4e7f4b0ae7aba6772aeb9e6f8f54f4
data/Manifest CHANGED
@@ -1,5 +1,7 @@
1
1
  LICENSE
2
- Manifest
3
2
  README.md
3
+ README.rdoc
4
4
  Rakefile
5
5
  lib/query_optimizer.rb
6
+ query_optimizer.gemspec
7
+ Manifest
data/README.md CHANGED
@@ -1,2 +1,5 @@
1
1
  # query_optimizer
2
- This is rails gem which will minimize query for many_to_many relationship
2
+ This is rails gem which will minimize query for many_to_many relationship .
3
+ Minimize query by query_optimizer just pass your model name as QueryOptimizer.optimize_query(Model1,Model2)
4
+
5
+ Refer https://github.com/akshaygoyal88/query_optimizer/blob/master/README.rdoc for usage
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
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
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('query_optimizer', '0.1.0') do |p|
5
+ Echoe.new('query_optimizer', '0.1.1') do |p|
6
6
  p.description = "Minimize query for fetching table row"
7
7
  p.url = "http://github.com/akshaygoyal88/query_optimizer"
8
8
  p.author = "Akshay Goyal"
@@ -1,7 +1,7 @@
1
1
  module QueryOptimizer
2
2
  def self.optimize_query(model1,model2)
3
- table1 = model1.to_s.downcase.pluralize
4
- table2 = model2.to_s.downcase.pluralize
3
+ table1 = model1.table_name
4
+ table2 = model2.table_name
5
5
  results = ActiveRecord::Base.connection.execute("SELECT #{table1}.*,#{table2}.* FROM #{table1} INNER JOIN #{table2} on #{table1}.id=#{table2}.post_id")
6
6
  table1_columns = model1.column_names
7
7
  table2_columns = model2.column_names
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: query_optimizer 0.1.0 ruby lib
2
+ # stub: query_optimizer 0.1.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "query_optimizer"
6
- s.version = "0.1.0"
6
+ s.version = "0.1.1"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.date = "2015-10-18"
12
12
  s.description = "Minimize query for fetching table row"
13
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"]
14
+ s.extra_rdoc_files = ["LICENSE", "README.md", "README.rdoc", "lib/query_optimizer.rb"]
15
+ s.files = ["LICENSE", "Manifest", "README.md", "README.rdoc", "Rakefile", "lib/query_optimizer.rb", "query_optimizer.gemspec"]
16
16
  s.homepage = "http://github.com/akshaygoyal88/query_optimizer"
17
17
  s.rdoc_options = ["--line-numbers", "--title", "Query_optimizer", "--main", "README.md"]
18
18
  s.rubyforge_project = "query_optimizer"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_optimizer
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
  - Akshay Goyal
@@ -17,11 +17,13 @@ extensions: []
17
17
  extra_rdoc_files:
18
18
  - LICENSE
19
19
  - README.md
20
+ - README.rdoc
20
21
  - lib/query_optimizer.rb
21
22
  files:
22
23
  - LICENSE
23
24
  - Manifest
24
25
  - README.md
26
+ - README.rdoc
25
27
  - Rakefile
26
28
  - lib/query_optimizer.rb
27
29
  - query_optimizer.gemspec