Sha256: ec13e97403d912903bf8916e8534e1ba4d8bb928e67d0714f827cde60aecea01

Contents?: true

Size: 1.49 KB

Versions: 17

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/object/blank"

module ActiveRecord
  module ConnectionAdapters
    module PostgreSQL
      class Column < ConnectionAdapters::Column # :nodoc:
        delegate :oid, :fmod, to: :sql_type_metadata

        def initialize(*, serial: nil, generated: nil, **)
          super
          @serial = serial
          @generated = generated
        end

        def serial?
          @serial
        end

        def virtual?
          # We assume every generated column is virtual, no matter the concrete type
          @generated.present?
        end

        def has_default?
          super && !virtual?
        end

        def array
          sql_type_metadata.sql_type.end_with?("[]")
        end
        alias :array? :array

        def enum?
          type == :enum
        end

        def sql_type
          super.delete_suffix("[]")
        end

        def init_with(coder)
          @serial = coder["serial"]
          @generated = coder["generated"]
          super
        end

        def encode_with(coder)
          coder["serial"] = @serial
          coder["generated"] = @generated
          super
        end

        def ==(other)
          other.is_a?(Column) &&
            super &&
            serial? == other.serial?
        end
        alias :eql? :==

        def hash
          Column.hash ^
            super.hash ^
            serial?.hash
        end
      end
    end
    PostgreSQLColumn = PostgreSQL::Column # :nodoc:
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.8.7/lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.8.7 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.8.6 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.8.5 lib/active_record/connection_adapters/postgresql/column.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/connection_adapters/postgresql/column.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/column.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/column.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.8.4 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.8.1 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.8 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.7.2 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.7.1 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.7 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.6 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.5.1 lib/active_record/connection_adapters/postgresql/column.rb
activerecord-7.0.5 lib/active_record/connection_adapters/postgresql/column.rb