Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondoc3 committed Mar 21, 2020
1 parent c32c186 commit dde6f21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ To start tracking, simply start your rails application server. When your server

`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.

### Tracking Using a Block

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.

```ruby
query_data = SqlTracker.track do
# Run some active record queries
end

query_data.values
# =>
# [{
# :sql=>"SELECT * FROM users",
# :count=>1,
# :duration=>1.0,
# :source=>["app/models/user.rb:12"]
# }]
```

## Reporting

Expand Down
4 changes: 2 additions & 2 deletions test/sql_tracker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_tracking_queries_with_a_block
instrument_query('SELECT * FROM comments')

assert_equal(
query_data.values.map { |v| v[:sql] },
expected_queries
expected_queries,
query_data.values.map { |v| v[:sql] }
)
end

Expand Down

0 comments on commit dde6f21

Please sign in to comment.