Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rubysamurai/query_count
SQL queries counter for Rails apps
https://github.com/rubysamurai/query_count
activerecord activerecord-queries query-counter rails sql-query
Last synced: about 1 month ago
JSON representation
SQL queries counter for Rails apps
- Host: GitHub
- URL: https://github.com/rubysamurai/query_count
- Owner: rubysamurai
- License: mit
- Created: 2020-05-21T15:23:53.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-13T12:09:01.000Z (over 2 years ago)
- Last Synced: 2024-09-15T16:36:08.065Z (about 2 months ago)
- Topics: activerecord, activerecord-queries, query-counter, rails, sql-query
- Language: Ruby
- Homepage:
- Size: 47.9 KB
- Stars: 44
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Query Count
[![Gem Version](https://badge.fury.io/rb/query_count.svg)](https://badge.fury.io/rb/query_count)
[![CI](https://github.com/rubysamurai/query_count/workflows/CI/badge.svg)](https://github.com/rubysamurai/query_count/actions?query=workflow%3ACI)A zero-configuration gem to count the number of SQL queries performed by the ActiveRecord.
Supports **Rails 4.2+** and **Ruby 2.0+** (the complete testing matrix is [here](.github/workflows/ci.yml)).## Installation
Add this line to your application's Gemfile:
```ruby
gem 'query_count'
```Run `bundle install`.
## Usage
The gem will automatically include the number of SQL queries to the default Rails log.
```
ActiveRecord: 34.0ms | SQL Queries: 8 (1 cached)
```This log example shows that the total number of queries was 8, and 1 was cached, which means the request hit the database 7 times.
`QueryCount::Counter` provides public methods `counter`, `counter_cache`, `reset_counter`, `reset_counter_cache`.
RSpec 3 example:
```ruby
it 'performs exactly 5 queries' do
QueryCount::Counter.reset_counter
5.times { User.last }
expect(QueryCount::Counter.counter).to eq 5
end
```## License
`query_count` © Dmitriy Tarasov. Released under the [MIT](LICENSE.txt) license.