activerecord-analyze 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/lib/activerecord-analyze/main.rb +11 -0
- data/lib/activerecord-analyze/version.rb +1 -1
- data/lib/activerecord-analyze.rb +11 -0
- data/spec/analyze_sql_spec.rb +19 -0
- data/spec/main_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb482e02b102f39912a33db2441ad138c265a5a164b0c5250a1c7529be158fac
|
4
|
+
data.tar.gz: 6425028186c884de0fdb1c897ad1a2c9419c2d039904ace3158650a540810946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
8
|
+
- image: cimg/postgres:12.10
|
9
9
|
environment:
|
10
10
|
POSTGRES_USER: postgres
|
11
11
|
POSTGRES_DB: activerecord-analyze-test
|
@@ -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")
|
data/lib/activerecord-analyze.rb
CHANGED
@@ -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
|
data/spec/analyze_sql_spec.rb
CHANGED
@@ -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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-analyze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|