Skip to content

Commit

Permalink
Merge pull request #11 from pocke/Write_README
Browse files Browse the repository at this point in the history
Write README
  • Loading branch information
pocke committed Mar 13, 2024
2 parents 72db4e4 + 00d32bc commit a85678c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# ActiveRecord::Originator

TODO: Delete this and the text below, and describe your gem
Add SQL comments to indicate the origin of the SQL.

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activerecord/originator`. To experiment with that code, run `bin/console` for an interactive prompt.
This gem adds SQL comments indicating the origin of the part of the query. This is useful for debugging large queries.

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
Rails tells us where the SQL is executed, but it doesn't tell us where the SQL is constructed.
This gem lets you know where the SQL is constructed! For example:

Install the gem and add to the application's Gemfile by executing:
```sql
Article Load (0.1ms) SELECT "articles".* FROM "articles" WHERE "articles"."status" = ? /* app/models/article.rb:3:in `published' */
AND "articles"."category_id" = ? /* app/controllers/articles_controller.rb:3:in `index' */
ORDER BY "articles"."created_at" DESC /* app/models/article.rb:4:in `order_by_latest' */
```

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
You can see where `.where` and `.order` methods are called without reading the source code. It is helpful if the query builder is complex.

If bundler is not being used to manage dependencies, install the gem by executing:
## Installation

$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
Install the gem and add to the application's Gemfile by executing:

## Usage
```console
$ bundle add activerecord-originator
```

TODO: Write usage instructions here
You do not need to do anything else. The gem will automatically add comments to the SQL.
Check the logs to see the comments.

## Development

Expand Down
4 changes: 2 additions & 2 deletions activerecord-originator.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
spec.authors = ["Masataka Pocke Kuwabara"]
spec.email = ["kuwabara@pocke.me"]

spec.summary = "Inject SQL comments to indicate the origin of the SQL."
spec.description = "This gem injects comments to the SQL to indicate where the SQL parts are constructed."
spec.summary = "Add SQL comments to indicate the origin of the SQL."
spec.description = "This gem adds comments to the SQL to indicate where the SQL parts are constructed."
spec.homepage = "https://github.com/pocke/activerecord-originator"
spec.required_ruby_version = ">= 3.1.0"

Expand Down

0 comments on commit a85678c

Please sign in to comment.