Sha256: 60e7902db39d4d30ed7d751d26b7525734dea47669600d41089f928b0023a619

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

module DbMod
  module Statements
    module Configuration
      module Single
        # Wrapper for a statement or prepared method that returns
        # an array of the values from the first value of every row
        # returned by the SQL statement.
        #
        #  def_statement(:a, 'SELECT a FROM b').single(:column)
        #
        #  def do_stuff
        #    a # => ['a', 'b', 'c']
        #  end
        module Column
          # Enables this module to be passed to
          # {DbMod::Statements::Configuration.process_method_results} as the
          # +wrapper+ function, where it will return an array of the first
          # value from every row in the result set.
          #
          # @param results [Object] SQL result set
          # @return [Array<String>] an array of values from the first column
          def self.call(results)
            results.map { |row| row[row.keys.first] }
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
db_mod-0.0.4 lib/db_mod/statements/configuration/single/column.rb