Module: DbMod::Statements::Configuration::Single::Column

Defined in:
lib/db_mod/statements/configuration/single/column.rb

Overview

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

Class Method Summary collapse

Class Method Details

.call(results) ⇒ Array<String>

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.

Parameters:

  • results (Object)

    SQL result set

Returns:

  • (Array<String>)

    an array of values from the first column



22
23
24
# File 'lib/db_mod/statements/configuration/single/column.rb', line 22

def self.call(results)
  results.map { |row| row[row.keys.first] }
end