Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array::PG::TextEncoder::Array

Inherits:
Object
  • Object
show all
Defined in:
lib/arjdbc/postgresql/base/array_encoder.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, delimiter:) ⇒ Array

Returns a new instance of Array.



8
9
10
11
12
13
14
15
# File 'lib/arjdbc/postgresql/base/array_encoder.rb', line 8

def initialize(name:, delimiter:)
  @type = if name == 'string[]'.freeze
            'text'.freeze
          else
            base_type = name.chomp('[]'.freeze).to_sym
            ActiveRecord::Base.connection.native_database_types[base_type][:name]
          end
end

Instance Method Details

#encode(values) ⇒ Object



17
18
19
# File 'lib/arjdbc/postgresql/base/array_encoder.rb', line 17

def encode(values)
  ActiveRecord::Base.connection.jdbc_connection.create_array_of(@type, values.to_java).to_s
end