Module: DbMod::Statements::Configuration::Single::Row
- Defined in:
- lib/db_mod/statements/configuration/single/row.rb
Overview
Wrapper for a statement or prepared method that returns only the first row of the result set as a hash, to save manual unboxing. Returns nil
if the query returns no results.
def_statement(:a, 'SELECT a, b FROM foo').single(:row)
def do_stuff
a # => { 'a' => '1', 'b' => '2'
end
Class Method Summary collapse
-
.call(results) ⇒ Hash<String,String>?
Enables this module to be passed to DbMod::Statements::Configuration.attach_result_processor as the
wrapper
function, where it will return the first row of the result set, ornil
if the result set is empty.
Class Method Details
.call(results) ⇒ Hash<String,String>?
Enables this module to be passed to DbMod::Statements::Configuration.attach_result_processor as the wrapper
function, where it will return the first row of the result set, or nil
if the result set is empty.
24 25 26 27 28 |
# File 'lib/db_mod/statements/configuration/single/row.rb', line 24 def self.call(results) return nil unless results.any? results[0] end |