sql_tracker 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -1
- data/README.md +18 -0
- data/lib/sql_tracker/handler.rb +15 -0
- data/lib/sql_tracker/version.rb +1 -1
- data/lib/sql_tracker.rb +10 -1
- data/sql_tracker.gemspec +2 -2
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 56c4c714a20db32a1617afa074c9d3e2f7986b53be0351b5a17a38733731d4e7
|
4
|
+
data.tar.gz: d7f77249ff127d6396aef49e9ba7aab123ee7a1fd84439e092e206112b5a1452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 290ace1cf7e19ebf5c8de2d3288f482d6159370cae8e3cedd5bf529864fe3b9bd7f4ee604776e40fd209a3e2ebd462013a1a6d6d9c666858011a33c1692f99e6
|
7
|
+
data.tar.gz: 7a758d0fd946e3392c618fbecf72fb200a2b9451fb3c4a1081f7b488002f820879076d1ec3ba68786b25e7badb6f0bafbef9e355c3026c3efbf323572f8ec2ec
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -29,6 +29,24 @@ To start tracking, simply start your rails application server. When your server
|
|
29
29
|
|
30
30
|
`sql_tracker` can also track sql queries when running rails tests (e.g. your controller or integration tests), it will dump the data after all the tests are finished.
|
31
31
|
|
32
|
+
### Tracking Using a Block
|
33
|
+
|
34
|
+
It is also possible to track queries executed within a block. This method uses a new subscriber to `sql.active_record` event notifications for each invocation. Results using this method are not saved to a file.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
query_data = SqlTracker.track do
|
38
|
+
# Run some active record queries
|
39
|
+
end
|
40
|
+
|
41
|
+
query_data.values
|
42
|
+
# =>
|
43
|
+
# [{
|
44
|
+
# :sql=>"SELECT * FROM users",
|
45
|
+
# :count=>1,
|
46
|
+
# :duration=>1.0,
|
47
|
+
# :source=>["app/models/user.rb:12"]
|
48
|
+
# }]
|
49
|
+
```
|
32
50
|
|
33
51
|
## Reporting
|
34
52
|
|
data/lib/sql_tracker/handler.rb
CHANGED
@@ -12,6 +12,21 @@ module SqlTracker
|
|
12
12
|
@data = {} # {key: {sql:, count:, duration, source: []}, ...}
|
13
13
|
end
|
14
14
|
|
15
|
+
def subscribe
|
16
|
+
@subscription ||= ActiveSupport::Notifications.subscribe(
|
17
|
+
'sql.active_record',
|
18
|
+
self
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def unsubscribe
|
23
|
+
return unless @subscription
|
24
|
+
|
25
|
+
ActiveSupport::Notifications.unsubscribe(@subscription)
|
26
|
+
|
27
|
+
@subscription = nil
|
28
|
+
end
|
29
|
+
|
15
30
|
def call(_name, started, finished, _id, payload)
|
16
31
|
return unless @config.enabled
|
17
32
|
|
data/lib/sql_tracker/version.rb
CHANGED
data/lib/sql_tracker.rb
CHANGED
@@ -8,11 +8,20 @@ module SqlTracker
|
|
8
8
|
|
9
9
|
config = SqlTracker::Config.apply_defaults
|
10
10
|
handler = SqlTracker::Handler.new(config)
|
11
|
-
|
11
|
+
handler.subscribe
|
12
12
|
@already_initialized = true
|
13
13
|
|
14
14
|
at_exit { handler.save }
|
15
15
|
end
|
16
|
+
|
17
|
+
def self.track
|
18
|
+
config = SqlTracker::Config.apply_defaults
|
19
|
+
handler = SqlTracker::Handler.new(config)
|
20
|
+
handler.subscribe
|
21
|
+
yield
|
22
|
+
handler.unsubscribe
|
23
|
+
handler.data
|
24
|
+
end
|
16
25
|
end
|
17
26
|
|
18
27
|
if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
|
data/sql_tracker.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = ['sql_tracker']
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency 'bundler'
|
23
|
-
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
25
25
|
spec.add_development_dependency 'activesupport', '>= 3.0.0'
|
26
26
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Yue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.5.1
|
112
|
+
rubygems_version: 3.0.6
|
114
113
|
signing_key:
|
115
114
|
specification_version: 4
|
116
115
|
summary: Rails SQL Query Tracker
|