Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16220 from pcreux/postgresql-jsonb-support
Add support for Postgresql JSONB
- Loading branch information
Showing
6 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters