activerecord-analyze 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +2 -0
- data/Rakefile +1 -0
- data/activerecord-analyze.gemspec +19 -0
- data/lib/activerecord-analyze.rb +2 -0
- data/lib/activerecord-analyze/main.rb +44 -0
- data/lib/activerecord-analyze/version.rb +3 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c1961ed7400cf716abcc28764176bdf02b4c3eb
|
4
|
+
data.tar.gz: c982bed6eb37c9413bbec9785416f96b9c55490c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f57e1be57c643f06a0ba3036a0e2709ce9ac799c3a02ca7a0c1cce99d92340b9b0a7d574f8c8652d52ee522a3c5edbccec8ea5f8d1d8fbd21468c1c20372ec7
|
7
|
+
data.tar.gz: 432321449fdff40d5f410cb635b4f20448437c471526c87de4eaa25782cae474a816abf4f64a871804a8009d8d80e68989cac75fa09d342b7fa590ac89d59163
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018 Paweł Urbanek
|
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.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activerecord-analyze/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "activerecord-analyze"
|
8
|
+
gem.version = ActiveRecordAnalyze::VERSION
|
9
|
+
gem.authors = ["pawurb"]
|
10
|
+
gem.email = ["p.urbanek89@gmail.com"]
|
11
|
+
gem.summary = %q{ Add EXPLAIN ANALYZE to Active Record query objects }
|
12
|
+
gem.description = %q{ Gem adds an "analyze" method to all Active Record query objects. Compatible with PostgreSQL database. }
|
13
|
+
gem.homepage = "http://github.com/pawurb/activerecord-analyze"
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.add_dependency "rails", "~> 5.1.0"
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module PostgreSQL
|
4
|
+
module DatabaseStatements
|
5
|
+
def analyze(arel, binds = [])
|
6
|
+
sql = "EXPLAIN ANALYZE #{to_sql(arel, binds)}"
|
7
|
+
PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN ANALYZE", binds))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ActiveRecord
|
15
|
+
class Relation
|
16
|
+
def analyze
|
17
|
+
exec_analyze(collecting_queries_for_explain { exec_queries })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ActiveRecord
|
23
|
+
module Explain
|
24
|
+
def exec_analyze(queries) # :nodoc:
|
25
|
+
str = queries.map do |sql, binds|
|
26
|
+
msg = "EXPLAIN ANALYZE for: #{sql}".dup
|
27
|
+
unless binds.empty?
|
28
|
+
msg << " "
|
29
|
+
msg << binds.map { |attr| render_bind(attr) }.inspect
|
30
|
+
end
|
31
|
+
msg << "\n"
|
32
|
+
msg << connection.analyze(sql, binds)
|
33
|
+
end.join("\n")
|
34
|
+
|
35
|
+
# Overriding inspect to be more human readable, especially in the console.
|
36
|
+
def str.inspect
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
str
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-analyze
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pawurb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.0
|
27
|
+
description: ' Gem adds an "analyze" method to all Active Record query objects. Compatible
|
28
|
+
with PostgreSQL database. '
|
29
|
+
email:
|
30
|
+
- p.urbanek89@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- activerecord-analyze.gemspec
|
41
|
+
- lib/activerecord-analyze.rb
|
42
|
+
- lib/activerecord-analyze/main.rb
|
43
|
+
- lib/activerecord-analyze/version.rb
|
44
|
+
homepage: http://github.com/pawurb/activerecord-analyze
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.6.14
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Add EXPLAIN ANALYZE to Active Record query objects
|
68
|
+
test_files: []
|