aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-07-25 11:16:20 +0200
committerYves Senn <yves.senn@gmail.com>2014-07-25 11:16:30 +0200
commit1ec601b4e3a4f8dbad56185a7a4ae5a8cc598002 (patch)
treeea82bd6e10dc31ce6eac8f2bf236e68256ab6620 /activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
parent75eddfbca98bb17ae7569ec30a3094ae1c50cdd3 (diff)
parent99b82fdf03fcf6d6ca8e2d810ba35011723a5267 (diff)
downloadrails-1ec601b4e3a4f8dbad56185a7a4ae5a8cc598002.tar.gz
rails-1ec601b4e3a4f8dbad56185a7a4ae5a8cc598002.tar.bz2
rails-1ec601b4e3a4f8dbad56185a7a4ae5a8cc598002.zip
Merge pull request #16220 from pcreux/postgresql-jsonb-support
Add support for Postgresql JSONB
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