提交 59d32a6e 编写于 作者: R Ryuta Kamizono

Refactor around sql_type metadata and column

* remove useless `@type_metadata` and `@array`
* move the compatibility code (for array) into column
* etc.
上级 3bd53428
......@@ -10,12 +10,11 @@ class TypeMetadata < DelegateClass(SqlTypeMetadata) # :nodoc:
def initialize(type_metadata, extra: "")
super(type_metadata)
@type_metadata = type_metadata
@extra = extra
end
def ==(other)
other.is_a?(MySQL::TypeMetadata) &&
other.is_a?(TypeMetadata) &&
__getobj__ == other.__getobj__ &&
extra == other.extra
end
......
......@@ -4,8 +4,7 @@ module ActiveRecord
module ConnectionAdapters
module PostgreSQL
class Column < ConnectionAdapters::Column # :nodoc:
delegate :array, :oid, :fmod, to: :sql_type_metadata
alias :array? :array
delegate :oid, :fmod, to: :sql_type_metadata
def initialize(*, serial: nil, **)
super
......@@ -15,6 +14,15 @@ def initialize(*, serial: nil, **)
def serial?
@serial
end
def array
sql_type_metadata.sql_type.end_with?("[]")
end
alias :array? :array
def sql_type
super.sub(/\[\]\z/, "")
end
end
end
PostgreSQLColumn = PostgreSQL::Column # :nodoc:
......
......@@ -675,7 +675,7 @@ def fetch_type_metadata(column_name, sql_type, oid, fmod)
precision: cast_type.precision,
scale: cast_type.scale,
)
PostgreSQLTypeMetadata.new(simple_type, oid: oid, fmod: fmod)
PostgreSQL::TypeMetadata.new(simple_type, oid: oid, fmod: fmod)
end
def sequence_name_from_parts(table_name, column_name, suffix)
......
......@@ -3,39 +3,34 @@
module ActiveRecord
# :stopdoc:
module ConnectionAdapters
class PostgreSQLTypeMetadata < DelegateClass(SqlTypeMetadata)
undef to_yaml if method_defined?(:to_yaml)
module PostgreSQL
class TypeMetadata < DelegateClass(SqlTypeMetadata)
undef to_yaml if method_defined?(:to_yaml)
attr_reader :oid, :fmod, :array
attr_reader :oid, :fmod
def initialize(type_metadata, oid: nil, fmod: nil)
super(type_metadata)
@type_metadata = type_metadata
@oid = oid
@fmod = fmod
@array = /\[\]$/.match?(type_metadata.sql_type)
end
def sql_type
super.gsub(/\[\]$/, "")
end
def initialize(type_metadata, oid: nil, fmod: nil)
super(type_metadata)
@oid = oid
@fmod = fmod
end
def ==(other)
other.is_a?(PostgreSQLTypeMetadata) &&
__getobj__ == other.__getobj__ &&
oid == other.oid &&
fmod == other.fmod &&
array == other.array
end
alias eql? ==
def ==(other)
other.is_a?(TypeMetadata) &&
__getobj__ == other.__getobj__ &&
oid == other.oid &&
fmod == other.fmod
end
alias eql? ==
def hash
PostgreSQLTypeMetadata.hash ^
__getobj__.hash ^
oid.hash ^
fmod.hash ^
array.hash
def hash
TypeMetadata.hash ^
__getobj__.hash ^
oid.hash ^
fmod.hash
end
end
end
PostgreSQLTypeMetadata = PostgreSQL::TypeMetadata
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册