aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
diff options
context:
space:
mode:
authorPhilippe Creux <pcreux@gmail.com>2014-07-24 10:39:39 -0700
committerPhilippe Creux <pcreux@gmail.com>2014-07-24 10:39:39 -0700
commit99b82fdf03fcf6d6ca8e2d810ba35011723a5267 (patch)
treec232bfff40548797590277a1bb2935343b162324 /activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
parent3f4e97f807eb475ac8c311e5baf138249a8a1ab2 (diff)
downloadrails-99b82fdf03fcf6d6ca8e2d810ba35011723a5267.tar.gz
rails-99b82fdf03fcf6d6ca8e2d810ba35011723a5267.tar.bz2
rails-99b82fdf03fcf6d6ca8e2d810ba35011723a5267.zip
Add support for Postgresql JSONB
[Philippe Creux, Chris Teague]
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
new file mode 100644
index 0000000000..34ed32ad35
--- /dev/null
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
@@ -0,0 +1,23 @@
+module ActiveRecord
+ module ConnectionAdapters
+ module PostgreSQL
+ module OID # :nodoc:
+ class Jsonb < Json # :nodoc:
+ def type
+ :jsonb
+ end
+
+ def changed_in_place?(raw_old_value, new_value)
+ # Postgres does not preserve insignificant whitespaces when
+ # roundtripping jsonb columns. This causes some false positives for
+ # the comparison here. Therefore, we need to parse and re-dump the
+ # raw value here to ensure the insignificant whitespaces are
+ # consitent with our encoder's output.
+ raw_old_value = type_cast_for_database(type_cast_from_database(raw_old_value))
+ super(raw_old_value, new_value)
+ end
+ end
+ end
+ end
+ end
+end