diff options
| author | Alban Peignier | 2017-02-20 11:12:45 +0100 |
|---|---|---|
| committer | RobertDober | 2017-04-11 15:39:41 +0200 |
| commit | 2e90dd524049c7bd982bbcddf6e62c2c36635aa3 (patch) | |
| tree | 02c9b8fd0c1a6217dd5fc9b1fb4c66bb5fa3e7ec /config/initializers/postgresql_adapter_patch.rb | |
| parent | a25a143e277da4f29c0eef88e5aad67a414f6d22 (diff) | |
| download | chouette-core-2e90dd524049c7bd982bbcddf6e62c2c36635aa3.tar.bz2 | |
Update DateRange custom OID to Rails 4.2 API. Refs #2070
Diffstat (limited to 'config/initializers/postgresql_adapter_patch.rb')
| -rw-r--r-- | config/initializers/postgresql_adapter_patch.rb | 71 |
1 files changed, 20 insertions, 51 deletions
diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb index 3c6530bef..bb8dbe17b 100644 --- a/config/initializers/postgresql_adapter_patch.rb +++ b/config/initializers/postgresql_adapter_patch.rb @@ -1,54 +1,23 @@ -# module ::ArJdbc -# module PostgreSQL -# def quote_column_name(name) -# if name.is_a?(Array) -# name.collect { |n| %("#{n.to_s.gsub("\"", "\"\"")}") }.join(',') -# else -# %("#{name.to_s.gsub("\"", "\"\"")}") -# end -# end -# end -# end -# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:primary_key] = "bigserial primary key" +# Transform Wed, 22 Feb 2017...Fri, 24 Feb 201 into Wed, 22 Feb 2017..Thu, 23 Feb 201 +module ActiveRecord::ConnectionAdapters::PostgreSQL::OID + class DateRange < Range + def cast_value(value) + result = super value -# Add missing double-quote to write array of daterange in SQL query -# See #1782 + if result.respond_to?(:exclude_end?) && result.exclude_end? + ::Range.new(result.begin, result.end - 1, false) + else + result + end + end + end +end -# class ActiveRecord::ConnectionAdapters::PostgreSQLColumn +ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do + def initialize_type_map_with_daterange mapping + initialize_type_map_without_daterange mapping + mapping.register_type 3912, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateRange.new(mapping.lookup('date'), :daterange) + end -# def self.array_to_string(value, column, adapter) -# casted_values = value.map do |val| -# if String === val -# if val == "NULL" -# "\"#{val}\"" -# else -# quote_and_escape(adapter.type_cast(val, column, true)) -# end -# elsif Range === val -# casted_value = adapter.type_cast(val, column, true) -# "\"#{casted_value}\"" -# else -# adapter.type_cast(val, column, true) -# end -# end -# "{#{casted_values.join(',')}}" -# end - -# end - -# module ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID -# class DateRange < Range -# # Unnormalize daterange -# # [2016-11-19,2016-12-26) -> 2016-11-19..2016-12-25 -# def type_cast(value) -# result = super value - -# if result.respond_to?(:exclude_end?) && result.exclude_end? -# ::Range.new(result.begin, result.end - 1, false) -# else -# result -# end -# end -# end -# register_type 'daterange', DateRange.new(:date) -# end + alias_method_chain :initialize_type_map, :daterange +end |
