Class: ActiveRecord::ConnectionAdapters::Clickhouse::OID::Array

Inherits:
Type::Value
  • Object
show all
Defined in:
lib/active_record/connection_adapters/clickhouse/oid/array.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(sql_type) ⇒ Array

Returns a new instance of Array.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/active_record/connection_adapters/clickhouse/oid/array.rb', line 9

def initialize(sql_type)
  @subtype = case sql_type
             when /U?Int\d+/
               :integer
             when /DateTime/
               :datetime
             when /Date/
               :date
             else
               :string
  end
end

Instance Method Details

#deserialize(value) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_record/connection_adapters/clickhouse/oid/array.rb', line 26

def deserialize(value)
  if value.is_a?(::Array)
    value.map { |item| deserialize(item) }
  else
    return value if value.nil?
    case @subtype
      when :integer
        value.to_i
      when :datetime
        ::DateTime.parse(value)
      when :date
        ::Date.parse(value)
    else
      super
    end
  end
end

#serialize(value) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_record/connection_adapters/clickhouse/oid/array.rb', line 44

def serialize(value)
  if value.is_a?(::Array)
    value.map { |item| serialize(item) }
  else
    return value if value.nil?
    case @subtype
      when :integer
        value.to_i
      when :datetime
        DateTime.new.serialize(value)
      when :date
        Date.new.serialize(value)
    else
      super
    end
  end
end

#typeObject



22
23
24
# File 'lib/active_record/connection_adapters/clickhouse/oid/array.rb', line 22

def type
  @subtype
end