sufleR / sql_query

Ruby gem to load SQL queries from `.sql.erb` templates using ERB.
MIT License
159 stars 15 forks source link

New constructor #1

Closed fuCtor closed 9 years ago

fuCtor commented 9 years ago

Maybe make, some thing like this:

    def initialize(*attrs)
      fail 'options empty' if attrs.empty? || !attrs.last.is_a? Hash
      options = attrs.last
      case attrs[0]
      when String
        options[:sql_name] ||= name
      when Symbol
        options[:sql_name] ||= name
      end

      prepare_variables(options)
      @connection = ActiveRecord::Base.connection
    end

Use:

> query = SqlQuery.new(:get_player_by_email, email: 'e@mail.dev')
sufleR commented 9 years ago

Does this change fit your requirements?

https://github.com/sufleR/sql_query/commit/a7af8cf0175dea6795d712a4dcf5917ea146c493

Options hash may be empty. Not every query needs conditions.

I like idea for first argument as file name. with this change we can initialize SqlQuery with very similar way as we do with views

Example:

SqlQuery.new 'player/get_by_email', email: 'e@mail.dev'
sufleR commented 9 years ago

closing with release 0.2.0