aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-02-15 14:21:01 -0700
committerSean Griffin <sean@thoughtbot.com>2015-02-15 14:23:17 -0700
commit265dcb779dd4bfd9745e0131f585749d7034c3c7 (patch)
treeb522ffcf5a29bf0a260d811a0d1cbcb84f2262bb /activerecord/lib/active_record/connection_adapters
parent8c837e5fcc2a3ac639b3b93b0024bd2c20d3b6ed (diff)
downloadrails-265dcb779dd4bfd9745e0131f585749d7034c3c7.tar.gz
rails-265dcb779dd4bfd9745e0131f585749d7034c3c7.tar.bz2
rails-265dcb779dd4bfd9745e0131f585749d7034c3c7.zip
Register adapter specific types with the global type registry
We do this in the adapter classes specifically, so the types aren't registered if we don't use that adapter. Constants under the PostgreSQL namespace for example are never loaded if we're using mysql.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb21
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb5
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb38
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb19
4 files changed, 21 insertions, 62 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 947e11c7bf..1ac909da2e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -144,29 +144,8 @@ module ActiveRecord
binds.map(&:value_for_database)
end
- def type_for_attribute_options(type_name, **options)
- klass = type_classes_with_standard_constructor.fetch(type_name, Type::Value)
- klass.new(**options)
- end
-
private
- def type_classes_with_standard_constructor
- {
- big_integer: Type::BigInteger,
- binary: Type::Binary,
- boolean: Type::Boolean,
- date: Type::Date,
- date_time: Type::DateTime,
- decimal: Type::Decimal,
- float: Type::Float,
- integer: Type::Integer,
- string: Type::String,
- text: Type::Text,
- time: Type::Time,
- }
- end
-
def types_which_need_no_typecasting
[nil, Numeric, String]
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 0a9e599c3c..84bfab43bb 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -942,9 +942,8 @@ module ActiveRecord
end
end
- def type_classes_with_standard_constructor
- super.merge(string: MysqlString)
- end
+ ActiveRecord::Type.register(:string, MysqlString, adapter: :mysql)
+ ActiveRecord::Type.register(:string, MysqlString, adapter: :mysql2)
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
index b8d0e26f85..b7755c4593 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -67,23 +67,6 @@ 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)
@@ -122,27 +105,6 @@ 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_time: OID::DateTime,
- decimal: OID::Decimal,
- enum: OID::Enum,
- hstore: OID::Hstore,
- inet: OID::Inet,
- json: OID::Json,
- jsonb: OID::Jsonb,
- money: OID::Money,
- point: OID::Point,
- uuid: OID::Uuid,
- vector: OID::Vector,
- xml: OID::Xml,
- )
- end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 6d7e1075d7..6d25b53b21 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -813,6 +813,25 @@ module ActiveRecord
return unless coder_class
coder_class.new(oid: row['oid'], name: row['typname'])
end
+
+ ActiveRecord::Type.add_modifier({ array: true }, OID::Array, adapter: :postgresql)
+ ActiveRecord::Type.add_modifier({ range: true }, OID::Range, adapter: :postgresql)
+ ActiveRecord::Type.register(:bit, OID::Bit, adapter: :postgresql)
+ ActiveRecord::Type.register(:bit_varying, OID::BitVarying, adapter: :postgresql)
+ ActiveRecord::Type.register(:binary, OID::Bytea, adapter: :postgresql)
+ ActiveRecord::Type.register(:cidr, OID::Cidr, adapter: :postgresql)
+ ActiveRecord::Type.register(:date_time, OID::DateTime, adapter: :postgresql)
+ ActiveRecord::Type.register(:decimal, OID::Decimal, adapter: :postgresql)
+ ActiveRecord::Type.register(:enum, OID::Enum, adapter: :postgresql)
+ ActiveRecord::Type.register(:hstore, OID::Hstore, adapter: :postgresql)
+ ActiveRecord::Type.register(:inet, OID::Inet, adapter: :postgresql)
+ ActiveRecord::Type.register(:json, OID::Json, adapter: :postgresql)
+ ActiveRecord::Type.register(:jsonb, OID::Jsonb, adapter: :postgresql)
+ ActiveRecord::Type.register(:money, OID::Money, adapter: :postgresql)
+ ActiveRecord::Type.register(:point, OID::Point, adapter: :postgresql)
+ ActiveRecord::Type.register(:uuid, OID::Uuid, adapter: :postgresql)
+ ActiveRecord::Type.register(:vector, OID::Vector, adapter: :postgresql)
+ ActiveRecord::Type.register(:xml, OID::Xml, adapter: :postgresql)
end
end
end