diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql')
3 files changed, 54 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb index e45a2f59d9..0a0a7fdbb3 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb @@ -48,6 +48,12 @@ module ActiveRecord end end + def ==(other) + other.is_a?(Array) && + subtype == other.subtype && + delimiter == other.delimiter + end + private def type_cast_array(value, method) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb index 3adfb8b9d8..2a5a59fbc6 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb @@ -7,7 +7,7 @@ module ActiveRecord class Range < Type::Value # :nodoc: attr_reader :subtype, :type - def initialize(subtype, type) + def initialize(subtype, type = :range) @subtype = subtype @type = type end @@ -40,6 +40,12 @@ module ActiveRecord end end + def ==(other) + other.is_a?(Range) && + other.subtype == subtype && + other.type == type + end + private def type_cast_single(value) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 464adb4e23..11114f32fe 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -65,6 +65,23 @@ module ActiveRecord type_map.lookup(column.oid, column.fmod, column.sql_type) end + def type_for_attribute_options( + type_name, + array: false, + range: false, + **options + ) + if array + subtype = type_for_attribute_options(type_name, **options) + OID::Array.new(subtype) + elsif range + subtype = type_for_attribute_options(type_name, **options) + OID::Range.new(subtype) + else + super(type_name, **options) + end + end + private def _quote(value) @@ -103,6 +120,30 @@ module ActiveRecord super end end + + def type_classes_with_standard_constructor + super.merge( + bit: OID::Bit, + bit_varying: OID::BitVarying, + binary: OID::Bytea, + cidr: OID::Cidr, + date: OID::Date, + date_time: OID::DateTime, + decimal: OID::Decimal, + enum: OID::Enum, + float: OID::Float, + hstore: OID::Hstore, + inet: OID::Inet, + json: OID::Json, + jsonb: OID::Jsonb, + money: OID::Money, + point: OID::Point, + time: OID::Time, + uuid: OID::Uuid, + vector: OID::Vector, + xml: OID::Xml, + ) + end end end end |