Class: YeSQL::Query::TransformResult

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Common::Adapter
Defined in:
lib/yesql/query/transform_result.rb

Instance Method Summary collapse

Methods included from Common::Adapter

#adapter, #mysql?, #pg?

Constructor Details

#initialize(output:, result:) ⇒ TransformResult

Returns a new instance of TransformResult.



14
15
16
17
# File 'lib/yesql/query/transform_result.rb', line 14

def initialize(output:, result:)
  @output = output
  @result = result
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yesql/query/transform_result.rb', line 19

def call
  if rails_5? && mysql?
    return columns if columns?
    return rows_values if rows?
    return array_of_symbol_hashes if hash?
  end

  return result.public_send(output.to_sym) if columns? || rows?

  to_a.map(&:symbolize_keys)
end