Module: DbMod::Statements::Configuration::Single::Value
- Defined in:
- lib/db_mod/statements/configuration/single/value.rb
Overview
Wrapper for a statement or prepared method that
returns the first column of the first returned row,
or nil if no rows are returned by the query.
def_statement(:a, 'SELECT 1').single(:value)
def do_stuff a # => '1' end
Class Method Summary collapse
-
.call(results) ⇒ String?
Enables this module to be passed to DbMod::Statements::Configuration.attach_result_processor as the
wrapperfunction, where it will return the first column of the first row of the result set, ornilif no results are returned.
Class Method Details
.call(results) ⇒ String?
Enables this module to be passed to
DbMod::Statements::Configuration.attach_result_processor as the
wrapper function, where it will return the first column of the
first row of the result set, or nil if no results are returned.
22 23 24 25 26 27 |
# File 'lib/db_mod/statements/configuration/single/value.rb', line 22 def self.call(results) return nil unless results.any? row = results[0] row[row.keys.first] end |