Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Just like the query_analyzer plugin, but logs to the db instead of the log file

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 benchmarks
Octocat-spinner-32 generators
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 GPL_LICENSE
Octocat-spinner-32 MIT_LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 TODO
Octocat-spinner-32 init.rb
README.rdoc

Enhanced Query Analyzer Rails Plugin (for MySQL)

Installation

Install it in vendor/plugins:

./script/plugin install git://github.com/smtlaissezfaire/enhanced_query_analyzer.git

Add the model and migration:

./script/generate enhanced_query_analyzer

Migrate:

rake db:migrate

Usage

All select queries will be logged to the query_logs table. You now have the ability to store historical data of all of your database access.

If you'd like finer grained control over logging, provide a block to EnhancedQueryAnalyzer.log_if:

EnhancedQueryAnalyzer.log_if { |query, time| <true | false> }

For instance, if you'd only like to log queries over a second:

EnhancedQueryAnalyzer.log_if { |_, time| time > 1 }

Or only log queries matching some regex:

EnhancedQueryAnalyzer.log_if { |query, time| query =~ /select.../ }

To turn off all logging:

EnhancedQueryAnalyzer.log_if { |_, _| false }

Or in everything but the test environment (this is recommended):

EnhancedQueryAnalyzer.log_if do |query, time|
  RAILS_ENV != "test"
end

You can also add the ability to dynamically run and log the explain of each query:

EnhancedQueryAnalyzer.explain_logging = true

Running Unit Tests

You'll need rspec and mysql. The database must be named 'query_analyzer_test'

Credits

Written by Scott Taylor <scott@railsnewbie.com>. Sponsored by Eastmedia (eastmedia.com).

License

Dual licensed under the MIT & GPL licenses.

Something went wrong with that request. Please try again.