Class: DbMod::Statements::Configuration::As::Json
- Inherits:
-
Object
- Object
- DbMod::Statements::Configuration::As::Json
- Defined in:
- lib/db_mod/statements/configuration/as/json.rb
Overview
Coercer which converts an SQL result set into a string formatted as a JSON array. May be enabled for a prepared method or statement method using .as(:json):
def_statement(:a, 'SELECT a, b FROM foo') { as(:json) }
def_prepared(:b, 'SELECT b, c FROM bar') { as(:json) }
def do_stuff
a # => '[{"a":"x","b":"y"},...]'
end
Class Method Summary collapse
-
.call(results) ⇒ String
Formats the SQL results as a JSON object.
Class Method Details
.call(results) ⇒ String
Formats the SQL results as a JSON object.
21 22 23 24 25 26 |
# File 'lib/db_mod/statements/configuration/as/json.rb', line 21 def self.call(results) # For compatibility with single(:row) return results.to_json if results.is_a? Hash results.to_a.to_json end |