activerecord-analyze 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 309228bac640cf76afc26a1c224e0e88427e4941e7ab5b5427e9bc969a031b6b
4
- data.tar.gz: a71f6053f7562b8e50e86701f7fa37876a732576463c5e0a9d19d85a14615233
3
+ metadata.gz: bb482e02b102f39912a33db2441ad138c265a5a164b0c5250a1c7529be158fac
4
+ data.tar.gz: 6425028186c884de0fdb1c897ad1a2c9419c2d039904ace3158650a540810946
5
5
  SHA512:
6
- metadata.gz: 13f73a221903084b66760dd62bede7d93559c87bb92750c3675843ac97137b99f7f42a61010697e2368527e5c80a27d2cb8352c9bad570f154a1be2b468a81fc
7
- data.tar.gz: 38338c77c2829e621529b1fc5c7a7b045fa0d58cf1f12f5e6b19dafbb64af4ad135ea839bf9e3a0292ad6a2e46796c932c6d4a960083e8ea8f274f3ba3c75d88
6
+ metadata.gz: c397a9790a1ee56652d2ab5fc300594054def2f1f9f091dfe8572883abfffa4d74079d0b5fbb1043a2d933fb399fe31ead2f8d117b314db951a4a68caf7b1656
7
+ data.tar.gz: 7bebc96dd4bc6a4fb4b3c257d980ae6007a6aea82567c9d19bd5c003011e15c01bb1b08654186e48c58d6a90e6ae443f68349f8166b94c80d2ba3c1d538086c2
data/.circleci/config.yml CHANGED
@@ -5,7 +5,7 @@ jobs:
5
5
  - image: circleci/ruby:2.6.5
6
6
  environment:
7
7
  DATABASE_URL: postgresql://postgres:secret@localhost:5432/activerecord-analyze-test
8
- - image: circleci/postgres:11.5
8
+ - image: cimg/postgres:12.10
9
9
  environment:
10
10
  POSTGRES_USER: postgres
11
11
  POSTGRES_DB: activerecord-analyze-test
data/README.md CHANGED
@@ -116,7 +116,7 @@ You can also use a raw SQL query string to generate an EXPLAIN ANALYZE output:
116
116
  ```ruby
117
117
  query = "SELECT * FROM users WHERE email = 'email@example.com'"
118
118
 
119
- puts ActiveRecordAnalyze.analyze_sql(query, { format: :json})
119
+ puts ActiveRecordAnalyze.analyze_sql(query, { format: :json })
120
120
 
121
121
  # [
122
122
  # {
@@ -15,7 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = gem.files.grep(%r{^(spec)/})
16
16
  gem.require_paths = ["lib"]
17
17
  gem.license = "MIT"
18
- gem.add_dependency "rails", ">= 5.1.0"
18
+ gem.add_dependency "activerecord"
19
+ gem.add_dependency "railties"
19
20
  gem.add_development_dependency "rake"
20
21
  gem.add_development_dependency "pg"
21
22
  gem.add_development_dependency "rspec"
@@ -16,6 +16,17 @@ end
16
16
  module ActiveRecord
17
17
  class Relation
18
18
  def analyze(opts = {})
19
+ if opts[:full_debug] == true
20
+ opts = {
21
+ format: :pretty_json,
22
+ verbose: true,
23
+ costs: true,
24
+ buffers: true,
25
+ timing: true,
26
+ summary: true
27
+ }
28
+ end
29
+
19
30
  res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
20
31
  if [:json, :hash, :pretty_json].include?(opts[:format])
21
32
  start = res.index("[\n")
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordAnalyze
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -4,6 +4,17 @@ require 'activerecord-analyze/main'
4
4
 
5
5
  module ActiveRecordAnalyze
6
6
  def self.analyze_sql(raw_sql, opts = {})
7
+ if opts[:full_debug] == true
8
+ opts = {
9
+ format: :pretty_json,
10
+ verbose: true,
11
+ costs: true,
12
+ buffers: true,
13
+ timing: true,
14
+ summary: true
15
+ }
16
+ end
17
+
7
18
  prefix = "EXPLAIN #{build_prefix(opts)}"
8
19
 
9
20
  result = ActiveRecord::Base.connection.execute("#{prefix} #{raw_sql}").to_a
@@ -80,4 +80,23 @@ describe "ActiveRecord analyze" do
80
80
  ]
81
81
  end
82
82
  end
83
+
84
+ describe "supports full_debug option" do
85
+ let(:raw_sql) do
86
+ "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"email\" IS NOT NULL LIMIT 10"
87
+ end
88
+
89
+ let(:opts) do
90
+ {
91
+ full_debug: true
92
+ }
93
+ end
94
+
95
+ it "works" do
96
+ puts result
97
+ expect(JSON.parse(result)[0].keys.sort).to eq [
98
+ "Execution Time", "Plan", "Planning Time", "Triggers"
99
+ ]
100
+ end
101
+ end
83
102
  end
data/spec/main_spec.rb CHANGED
@@ -50,6 +50,15 @@ describe "ActiveRecord analyze" do
50
50
  end
51
51
  end
52
52
 
53
+ describe "full_debug" do
54
+ it "works" do
55
+ result = User.all.analyze(full_debug: true)
56
+ expect(JSON.parse(result)[0].keys.sort).to eq [
57
+ "Execution Time", "Plan", "Planning Time", "Triggers"
58
+ ]
59
+ end
60
+ end
61
+
53
62
  describe "supports options" do
54
63
  it "works" do
55
64
  result = User.all.limit(10).where.not(email: nil).analyze(
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-analyze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-23 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.0
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +108,7 @@ homepage: http://github.com/pawurb/activerecord-analyze
94
108
  licenses:
95
109
  - MIT
96
110
  metadata: {}
97
- post_install_message:
111
+ post_install_message:
98
112
  rdoc_options: []
99
113
  require_paths:
100
114
  - lib
@@ -109,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  requirements: []
112
- rubygems_version: 3.0.3
113
- signing_key:
126
+ rubygems_version: 3.1.6
127
+ signing_key:
114
128
  specification_version: 4
115
129
  summary: Add EXPLAIN ANALYZE to Active Record query objects
116
130
  test_files: