activerecord-analyze 0.8.0 → 0.9.0
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 +4 -4
- data/README.md +8 -8
- data/lib/activerecord-analyze/main.rb +3 -3
- data/lib/activerecord-analyze/version.rb +1 -1
- data/spec/main_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 054f9f2dad0f0e6a87b82d1722a95889688d3a3b712a4077c0d5892d693ef52f
|
4
|
+
data.tar.gz: c08fe69a2a34e6f9b8b51ab40afa24810262e681a9f01109786c8fdcd5bf0285
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6a5ad936771e8a0d6d1fa73c0ac68b2146b7f4d7e6e3c9667def0f7c5450b7ab7109885db4f6590217227e84d821f4d3f976c235dd1f02a6d52d5335db45b04
|
7
|
+
data.tar.gz: c2e987200963f0acf13eb734a6ae1bdd0212bcc68bae3aad1274fe8c0cd27f0cdd28d714ade1d1f15e76dc6b7d7d31fc83340ad80c541874e445ac4807776934
|
data/README.md
CHANGED
@@ -23,13 +23,13 @@ gem 'activerecord-analyze'
|
|
23
23
|
The `analyze` method supports the following EXPLAIN query options ([PostgreSQL docs reference](https://www.postgresql.org/docs/12/sql-explain.html)):
|
24
24
|
|
25
25
|
```
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
buffers: [ boolean ]
|
27
|
+
verbose: [ boolean ]
|
28
|
+
costs: [ boolean ]
|
29
|
+
settings: [ boolean ]
|
30
|
+
timing: [ boolean ]
|
31
|
+
summary: [ boolean ]
|
32
|
+
format: { :text | :json | :xml | :yaml | :pretty_json }
|
33
33
|
```
|
34
34
|
|
35
35
|
You can execute it like that:
|
@@ -37,7 +37,7 @@ You can execute it like that:
|
|
37
37
|
```ruby
|
38
38
|
|
39
39
|
puts User.all.analyze(
|
40
|
-
format: :
|
40
|
+
format: :pretty_json, # :pretty_json format option generates a formatted JSON output
|
41
41
|
verbose: true,
|
42
42
|
costs: true,
|
43
43
|
settings: true,
|
@@ -9,7 +9,7 @@ module ActiveRecord
|
|
9
9
|
"FORMAT JSON,"
|
10
10
|
when :hash
|
11
11
|
"FORMAT JSON,"
|
12
|
-
when :
|
12
|
+
when :pretty_json
|
13
13
|
"FORMAT JSON,"
|
14
14
|
when :yaml
|
15
15
|
"FORMAT YAML,"
|
@@ -68,7 +68,7 @@ module ActiveRecord
|
|
68
68
|
class Relation
|
69
69
|
def analyze(opts = {})
|
70
70
|
res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
|
71
|
-
if [:json, :hash, :
|
71
|
+
if [:json, :hash, :pretty_json].include?(opts[:format])
|
72
72
|
start = res.index("[\n")
|
73
73
|
finish = res.rindex("]")
|
74
74
|
raw_json = res.slice(start, finish - start + 1)
|
@@ -77,7 +77,7 @@ module ActiveRecord
|
|
77
77
|
JSON.parse(raw_json).to_json
|
78
78
|
elsif opts[:format] == :hash
|
79
79
|
JSON.parse(raw_json)
|
80
|
-
elsif opts[:format] == :
|
80
|
+
elsif opts[:format] == :pretty_json
|
81
81
|
JSON.pretty_generate(JSON.parse(raw_json))
|
82
82
|
end
|
83
83
|
else
|
data/spec/main_spec.rb
CHANGED
@@ -43,7 +43,7 @@ describe "ActiveRecord analyze" do
|
|
43
43
|
|
44
44
|
describe "format pretty" do
|
45
45
|
it "works" do
|
46
|
-
result = User.all.analyze(format: :
|
46
|
+
result = User.all.analyze(format: :pretty_json)
|
47
47
|
expect(JSON.parse(result)[0].keys.sort).to eq [
|
48
48
|
"Execution Time", "Plan", "Planning Time", "Triggers"
|
49
49
|
]
|