Sha256: 87d0335c0019e6993ef09030cb8daae2aeae25ca6dd6fb8a476185bc86ec2b90
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
module DbMod module Statements module Configuration module Single # Wrapper for a statement or prepared method that returns # only the first row of the result set as a hash, to save # manual unboxing. Raises an error unless exactly one row # is returned. # # def_statement(:a, 'SELECT a, b FROM foo').single(:row) # # def do_stuff # a # => { 'a' => '1', 'b' => '2' # end module RequiredRow # Enables this module to be passed to # {DbMod::Statements::Configuration.process_method_results} as the # +wrapper+ function, where it will return the first row of the # result set, or raise an exception if exactly one row is not # returned. # # @param results [Object] SQL result set # @return [Hash<String,String>] # the first row of the SQL result set returned by the query def self.call(results) fail DbMod::Exceptions::NoResults unless results.any? fail DbMod::Exceptions::TooManyResults if results.count > 1 results[0] 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/required_row.rb |