Module: Simple::SQL::Decoder
Overview
private
Defined Under Namespace
Modules: HStore Classes: MultiColumns, Record, SingleColumn
Instance Method Summary collapse
-
#decode_value(type, s) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength.
- #new(result, mode = nil, into: nil) ⇒ Object
Instance Method Details
#decode_value(type, s) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple/sql/decoder.rb', line 15 def decode_value(type, s) case type when :unknown then s when :"character varying" then s when :integer then Integer(s) when :bigint then Integer(s) when :numeric then Float(s) when :'integer[]' then s.scan(/-?\d+/).map { |part| Integer(part) } when :"character varying[]" then parse_pg_array(s) when :"text[]" then parse_pg_array(s) when :"timestamp without time zone" then ::Time.parse(s) when :hstore then HStore.parse(s) when :json then ::JSON.parse(s) when :jsonb then ::JSON.parse(s) else s # unknown value, we just return the string here. end end |
#new(result, mode = nil, into: nil) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/simple/sql/decoder.rb', line 5 def new(result, mode = nil, into: nil) if mode == :record then Record.new(result, into: into) elsif result.nfields == 1 then SingleColumn.new(result) else MultiColumns.new(result) end end |