No commit activity in last 3 years
No release in over 3 years
ActiveRecord::Commentator adds execute location (filename, line-number and method-name) as SQL comment that invokes SQL statement.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

 Project Readme

ActiveRecord::Commentator

ActiveRecord::Commentator adds caller_location (filename, line-number and method-name) as SQL comment that invokes SQL statement.

Installation

Add this line to your application's Gemfile:

gem 'activerecord-commentator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-commentator

Usage

in Rails app

# in config/initializers/commentator.rb
require "active_record/commentator"

ActiveRecord::Commentator::Configuration.paths = [
  /#{Rails.root.join("app").to_s}|#{Rails.root.join("lib").to_s}/
]
ActiveRecord::Base.connection.class.prepend(ActiveRecord::Commentator)

Start server and visit localhost:3000

bundle exec rails server

Rails application log

# execute sql at model
(0.3ms)  SELECT  `favorites`.`product_id` FROM `favorites` /* /Users/hisaichi5518/projects/github.com/sample/app/models/product.rb:28:in `block in <class:Product>' */

# execute sql at view
Info Load (0.5ms)  SELECT  `infos`.* FROM `infos` /* /Users/hisaichi5518/projects/github.com/sample/app/cells/infos/index.html.erb:3:in `_app_cells_infos_index_html_erb___2113458239111152552_70242821135200' */

Database slow log

# Time: 198723 23:21:34
# User@Host: ... @ localhost []
# Query_time: 1.90872  Lock_time: 0.90879 Rows_sent: 1  Rows_examined: 9802714
...
SELECT  `favorites`.`product_id` FROM `favorites` /* /Users/hisaichi5518/projects/github.com/sample/app/models/product.rb:28:in `block in <class:Product>' */

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hisaichi5518/activerecord-commentator.

See also