Skip to content

The Sequel extension which allow you to find all your 'SELECT * FROM ...' queries.

License

Notifications You must be signed in to change notification settings

danilobarion1986/sequel-asterisk-hunter

Repository files navigation

SequelAsteriskHunter

Maintainability

This extension hooks into Sequel::Dataset#fetch_rows method, doing some predefined action when an SELECT * statement is found.

Installation

Add this line to your application's Gemfile:

gem 'sequel-asterisk-hunter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sequel-asterisk-hunter

Usage

The extension needs to be initialized by the Sequel extension interface. The simplest way to configure it globally is by adding this line to the initializer:

Sequel.extension :asterisk_hunter

or

Sequel::Database.extension :asterisk_hunter

However, if you are using any framework (like Rails) where your Sequel::Database instance already exists, you should use DB.extension :asterisk_hunter, where DB is a reference to your Sequel::Database, like this:

Sequel::Model.db.extension :asterisk_hunter

You could define an action to be executed when any SELECT * statement is found. It must be any callable object.

Examples

With the default action:

DB[:my_table].all
  #=> "Find 'SELECT *' in query!"
  #=> [<All your objects and its attributes/columns>]

With some custom actions defined:

  • Raising an error:
action = -> { raise StandardError, "Find 'SELECT *' in query!" }
Sequel::Extensions::AsteriskHunter.define_action(action)

DB[:my_table].all
  #=> StandardError("Find 'SELECT *' in query!")
  # (Your query is not executed...)
  • Logging:
action = -> { Rails.logger.warn("Find 'SELECT *' in query!") }
Sequel::Extensions::AsteriskHunter.define_action(action)

DB[:my_table].all
  #=> "Find 'SELECT *' in query!"
  #=> [<All your objects and its attributes/columns>]

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

The Sequel extension which allow you to find all your 'SELECT * FROM ...' queries.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages