Sha256: fb160004fa2bf97082680e711909c144407ac3b967a81f2ae8b3e0a175256157

Contents?: true

Size: 967 Bytes

Versions: 2

Compression:

Stored size: 967 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.attach_result_processor} 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

2 entries across 2 versions & 1 rubygems

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