Skip to content

Commit 60d767d

Browse files
prathamesh-sonpatkikares
authored andcommitted
In Rails 4.2, support for Jsonb datatype was added for postgres
Commit - rails/rails@99b82fd
1 parent 0efa046 commit 60d767d

File tree

1 file changed

+15
-0
lines changed
  • lib/arjdbc/postgresql/base

1 file changed

+15
-0
lines changed

lib/arjdbc/postgresql/base/oid.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ def accessor
343343
end
344344
end
345345

346+
class Jsonb < Json
347+
def type
348+
:jsonb
349+
end
350+
351+
def changed_in_place?(raw_old_value, new_value)
352+
# Postgres does not preserve insignificant whitespaces when
353+
# roundtripping jsonb columns. This causes some false positives for
354+
# the comparison here. Therefore, we need to parse and re-dump the
355+
# raw value here to ensure the insignificant whitespaces are
356+
# consistent with our encoder's output.
357+
raw_old_value = type_cast_for_database(type_cast_from_database(raw_old_value))
358+
super(raw_old_value, new_value)
359+
end
360+
end if ActiveRecord::VERSION.to_s >= '4.2'
346361
class Uuid < Type
347362
def type; :uuid end
348363
def type_cast(value)

0 commit comments

Comments
 (0)