activerecord-analyze 0.6.0 → 0.7.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: ef55b677ccdab275d0b76db680c55e8c8534b7e03245dc76f622eca81cb3b244
4
- data.tar.gz: 3ee9e2dc7ce0251cab913d79ee3c5b5760b571d27bdf98b132cb8d8751c7c7da
3
+ metadata.gz: bc476a2e8768df2625298f3b8d3ea7ed574fcfa86c85daf7bdc8793c7773a13c
4
+ data.tar.gz: acec1d6f2dd3fb3862cc7def00e18f3696f7de11060c6ce1ef91d6da67175375
5
5
  SHA512:
6
- metadata.gz: 5a1057165667e384853cc9fc83e98b4c98377c2af41057cbe52427cd7a25b8fff99f50321435e4bab1645be97e2d989e026fe3ba85d0d825e53992d1d373ac3b
7
- data.tar.gz: 43019fbfa8dff77b956e62eba3750f63b4925eb179876348750414a77c91c0406892a12a3eb719d51e100b8e00e7274a7b41db0054c06d9a061a8887b4be807a
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
- VERBOSE [ boolean ]
27
- COSTS [ boolean ]
28
- SETTINGS [ boolean ]
29
- BUFFERS [ boolean ]
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
 
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordAnalyze
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
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.6.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-07 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails