Sha256: 9846b099276090eecd2cd3e4e26766967da3238cbf7a547b127537a112319faa

Contents?: true

Size: 800 Bytes

Versions: 29

Compression:

Stored size: 800 Bytes

Contents

# frozen_string_literal: true

# This implements a basic encoder to work around ActiveRecord's dependence on the pg gem
module ActiveRecord::ConnectionAdapters::PostgreSQL::OID
  class Array < ActiveModel::Type::Value
    module PG
      module TextEncoder
        class Array

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

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

        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
activerecord-jdbc-alt-adapter-61.3.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-71.0.0.alpha2-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-71.0.0.alpha1-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-70.2.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-70.2-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-61.3-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-70.1.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-70.0.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-70.1-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-70.0.0.rc2-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-60.3.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-61.2.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-70.0.0.rc1-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-70.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-70.0.pre-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-61.2-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-60.2.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-alt-adapter-61.1.0-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-61.1-java lib/arjdbc/postgresql/base/array_encoder.rb
activerecord-jdbc-adapter-60.4-java lib/arjdbc/postgresql/base/array_encoder.rb