activerecord-analyze 0.6.0 → 0.7.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 +6 -6
- data/lib/activerecord-analyze/main.rb +8 -1
- data/lib/activerecord-analyze/version.rb +1 -1
- data/spec/main_spec.rb +14 -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: bc476a2e8768df2625298f3b8d3ea7ed574fcfa86c85daf7bdc8793c7773a13c
|
4
|
+
data.tar.gz: acec1d6f2dd3fb3862cc7def00e18f3696f7de11060c6ce1ef91d6da67175375
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01ec2a670e10f7a44ae251bfd90f5f15f81ad8e1c280d99439a955e7553f30c67309cd3aeecd5e8c6a1bc844831e66f37bd5edbbc8f92aa5f284035eff943c30
|
7
|
+
data.tar.gz: 42f5fd9278bfb98caaf549d064a2d664c7c1d1cb1629fde8568144dbfd79d729ae6f3506915e26634d17fbf57ab1089d59c2f927697f218d0fa091c8976009f0
|
data/README.md
CHANGED
@@ -23,12 +23,12 @@ 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
|
-
TIMING [ boolean ]
|
31
|
-
SUMMARY [ boolean ]
|
26
|
+
BUFFERS [ boolean ] (default: true)
|
27
|
+
VERBOSE [ boolean ] (default: true)
|
28
|
+
COSTS [ boolean ] (default: false)
|
29
|
+
SETTINGS [ boolean ] (default: false)
|
30
|
+
TIMING [ boolean ] (default: false)
|
31
|
+
SUMMARY [ boolean ] (default: false)
|
32
32
|
FORMAT { TEXT | XML | JSON | YAML }
|
33
33
|
```
|
34
34
|
|
@@ -3,6 +3,13 @@ module ActiveRecord
|
|
3
3
|
module PostgreSQL
|
4
4
|
module DatabaseStatements
|
5
5
|
def analyze(arel, binds = [], opts = {})
|
6
|
+
default_opts = {
|
7
|
+
buffers: true,
|
8
|
+
verbose: true
|
9
|
+
}
|
10
|
+
|
11
|
+
opts = default_opts.merge(opts)
|
12
|
+
|
6
13
|
format_sql = if fmt = opts[:format].presence
|
7
14
|
case fmt
|
8
15
|
when :json
|
@@ -67,7 +74,7 @@ module ActiveRecord
|
|
67
74
|
def analyze(opts = {})
|
68
75
|
res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
|
69
76
|
if [:json, :hash].include?(opts[:format])
|
70
|
-
start = res.index("[")
|
77
|
+
start = res.index("[\n")
|
71
78
|
finish = res.rindex("]")
|
72
79
|
raw_json = res.slice(start, finish - start + 1)
|
73
80
|
|
data/spec/main_spec.rb
CHANGED
@@ -40,4 +40,18 @@ describe "ActiveRecord analyze" do
|
|
40
40
|
]
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
describe "supports options" do
|
45
|
+
it "works" do
|
46
|
+
result = User.all.limit(10).where.not(email: nil).analyze(
|
47
|
+
format: :hash,
|
48
|
+
costs: true,
|
49
|
+
timing: true,
|
50
|
+
summary: true
|
51
|
+
)
|
52
|
+
expect(result[0].keys.sort).to eq [
|
53
|
+
"Execution Time", "Plan", "Planning Time", "Triggers"
|
54
|
+
]
|
55
|
+
end
|
56
|
+
end
|
43
57
|
end
|
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.7.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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|