sql_spy 0.3.0 → 0.4.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/Gemfile.lock +1 -1
- data/README.md +15 -6
- data/{sql-spy.gemspec → sql_spy.gemspec} +2 -2
- metadata +4 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7fe6bcb2e50a0d51ae186f60566422043ab6a8dbb159a1cc26221654954521f
|
4
|
+
data.tar.gz: 9ed63e719d938fdbc94c1f44d2f304532dcc5ee28bedaef449b92db8a5ab38ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c36e3858fd1dfdc83ab06538a245d0061721054bb2e17bcd5d9774a6fab23561cd7eedc0ae463f79c92eda415a52d2c430d4946dade83544fa8126382f1692f
|
7
|
+
data.tar.gz: d79894d45d4c62765e56bbd3b749a3d5f772366f4e91836eda77161bc45e6dab5cf6d7be91a48e5b6847faa1ffc4339261db72a17008109ab40e99c156b8a57d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,10 +4,19 @@
|
|
4
4
|
|
5
5
|
A gem to track all SQL queries performed inside a block of code.
|
6
6
|
|
7
|
-
|
7
|
+
With **SqlSpy** you can test:
|
8
|
+
|
9
|
+
- The total amount of queries performed by a piece of code
|
10
|
+
- The amount of queries performed on a specific table
|
11
|
+
- The type of these queries: *SELECT*, *INSERT*, *UPDATE*, *DELETE*
|
12
|
+
- The query duration
|
13
|
+
- The SQL produced by your *ActiveRecord* code
|
14
|
+
- N+1 queries
|
8
15
|
|
9
16
|
The implementation is inspired by how [ActiveRecord is tested](https://github.com/rails/rails/blob/6-0-stable/activerecord/test/cases/test_case.rb).
|
10
17
|
|
18
|
+
Check out [my blog post](https://lipanski.com/posts/activerecord-eager-loading#preventing-n1-regressions-with-tests) about writing controller tests with **SqlSpy** in order to prevent N+1 regressions.
|
19
|
+
|
11
20
|
## Usage
|
12
21
|
|
13
22
|
Add the gem to your `Gemfile`:
|
@@ -16,7 +25,7 @@ Add the gem to your `Gemfile`:
|
|
16
25
|
gem "sql_spy"
|
17
26
|
```
|
18
27
|
|
19
|
-
|
28
|
+
Install it:
|
20
29
|
|
21
30
|
```sh
|
22
31
|
bundle install
|
@@ -42,7 +51,7 @@ The `SqlSpy.track` method will return **an array containing all the queries perf
|
|
42
51
|
- `#update?`: Is this an *UPDATE* query?
|
43
52
|
- `#delete?`: Is this a *DELETE* query?
|
44
53
|
|
45
|
-
Here are some **ideas**
|
54
|
+
Here are some **ideas** of how you could use this:
|
46
55
|
|
47
56
|
```ruby
|
48
57
|
# Expect less than 5 queries
|
@@ -57,7 +66,7 @@ assert_equal 2, queries.select { |query| query.model_name == "Post" }.size
|
|
57
66
|
# None of the queries should be slower than 100ms
|
58
67
|
assert queries.none? { |query| query.duration > 100 }
|
59
68
|
|
60
|
-
# Fail on N+1 queries: expect
|
69
|
+
# Fail on N+1 queries: expect at most 1 query per table
|
61
70
|
queries_by_model = queries.group_by(&:model_name)
|
62
71
|
assert queries_by_model.none? { |model_name, queries| queries.count > 1 }
|
63
72
|
```
|
@@ -69,7 +78,7 @@ The gem is tested with Postgres 9.6 and SQLite 3.
|
|
69
78
|
To run tests with SQLite:
|
70
79
|
|
71
80
|
```sh
|
72
|
-
|
81
|
+
rake
|
73
82
|
```
|
74
83
|
|
75
84
|
To run tests with Postgres:
|
@@ -78,7 +87,7 @@ To run tests with Postgres:
|
|
78
87
|
# Create a test database
|
79
88
|
cretedb sql_spy_test
|
80
89
|
|
81
|
-
DATABASE_URL=postgres:///sql_spy_test
|
90
|
+
DATABASE_URL=postgres:///sql_spy_test rake
|
82
91
|
```
|
83
92
|
|
84
93
|
## License
|
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "sql_spy"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.4.0"
|
4
4
|
spec.authors = ["Florin Lipan"]
|
5
5
|
spec.email = ["florinlipan@gmail.com"]
|
6
6
|
|
7
|
-
spec.summary = %q{A gem to track SQL queries
|
7
|
+
spec.summary = %q{A gem to track all SQL queries performed inside a block of code}
|
8
8
|
spec.homepage = "https://github.com/lipanski/sql-spy"
|
9
9
|
spec.license = "MIT"
|
10
10
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florin Lipan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -24,10 +24,8 @@ files:
|
|
24
24
|
- LICENSE.txt
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
|
-
- bin/console
|
28
|
-
- bin/setup
|
29
27
|
- lib/sql_spy.rb
|
30
|
-
-
|
28
|
+
- sql_spy.gemspec
|
31
29
|
homepage: https://github.com/lipanski/sql-spy
|
32
30
|
licenses:
|
33
31
|
- MIT
|
@@ -53,5 +51,5 @@ requirements: []
|
|
53
51
|
rubygems_version: 3.1.2
|
54
52
|
signing_key:
|
55
53
|
specification_version: 4
|
56
|
-
summary: A gem to track SQL queries
|
54
|
+
summary: A gem to track all SQL queries performed inside a block of code
|
57
55
|
test_files: []
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "sql/spy"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|