activerecord-analyze 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/activerecord-analyze/main.rb +5 -1
- data/lib/activerecord-analyze/version.rb +1 -1
- 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: 125c8ead9447324802fcd4cd6c32c890aecf46c98f6efb3b41ab21d1a51afedd
|
4
|
+
data.tar.gz: f7314c778b981e2e9ddc89a737d5a24155ed99bd77a9c94a7e350e33b8002d05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9952cb78fcc8076ca6be19f697377b4ded8b2c090ba51affb04e6a6e67a1a83ad5c3900ff4fbf8ef27fa4ad491e881296156ccc79e0424f794f783c6ac050ce3
|
7
|
+
data.tar.gz: f3a1cf3d8166520a32d1ae83e1c9803500a887abd2ced53d83ddabcace23ada512e2003437d6ed93667645154fa4acf103bfca445b47698790484e8ab02f98bb
|
data/README.md
CHANGED
@@ -9,6 +9,8 @@ module ActiveRecord
|
|
9
9
|
"FORMAT JSON,"
|
10
10
|
when :hash
|
11
11
|
"FORMAT JSON,"
|
12
|
+
when :pretty
|
13
|
+
"FORMAT JSON,"
|
12
14
|
when :yaml
|
13
15
|
"FORMAT YAML,"
|
14
16
|
when :text
|
@@ -66,7 +68,7 @@ module ActiveRecord
|
|
66
68
|
class Relation
|
67
69
|
def analyze(opts = {})
|
68
70
|
res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
|
69
|
-
if [:json, :hash].include?(opts[:format])
|
71
|
+
if [:json, :hash, :pretty].include?(opts[:format])
|
70
72
|
start = res.index("[\n")
|
71
73
|
finish = res.rindex("]")
|
72
74
|
raw_json = res.slice(start, finish - start + 1)
|
@@ -75,6 +77,8 @@ module ActiveRecord
|
|
75
77
|
JSON.parse(raw_json).to_json
|
76
78
|
elsif opts[:format] == :hash
|
77
79
|
JSON.parse(raw_json)
|
80
|
+
elsif opts[:format] == :pretty
|
81
|
+
JSON.pretty_generate(JSON.parse(raw_json))
|
78
82
|
end
|
79
83
|
else
|
80
84
|
res
|
data/spec/main_spec.rb
CHANGED
@@ -41,6 +41,15 @@ describe "ActiveRecord analyze" do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
describe "format pretty" do
|
45
|
+
it "works" do
|
46
|
+
result = User.all.analyze(format: :pretty)
|
47
|
+
expect(JSON.parse(result)[0].keys.sort).to eq [
|
48
|
+
"Execution Time", "Plan", "Planning Time", "Triggers"
|
49
|
+
]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
44
53
|
describe "supports options" do
|
45
54
|
it "works" do
|
46
55
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|