-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Add support for Postgresql JSONB #16220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👍 |
@@ -1,3 +1,7 @@ | |||
* Add support for Postgresql JSONB | |||
|
|||
Philippe Creux, Chris Teague |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*Philippe Creux*, *Chris Teague*
@@ -29,6 +29,22 @@ def accessor | |||
ActiveRecord::Store::StringKeyedHashAccessor | |||
end | |||
end | |||
|
|||
class Jsonb < Json # :nodoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this in its own file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
One minor comment, looks fine otherwise. |
@sgrif I've just added |
# 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this local variable change here recognized in super
? does super
share lexical scope with the subclass invoking it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Though IMO it's better to go with a more obviously-correct super(raw_old_value, new_value)
in situations like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@pcreux looking good. Added a few comments then we should be good to go. |
class PostgresqlJSONTest < ActiveRecord::TestCase | ||
include PostgresqlJSONSharedTestCases | ||
|
||
def column_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@senny I prefer defining the method column_type
over this:
def setup
@column_type = :json
super
end
I'm happy to use an instance variable instead if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method is fine.
@senny Rebased against master. Test are passing. It's ready for prime time! |
👍 |
[Philippe Creux, Chris Teague]
Add support for Postgresql JSONB
thanks guys 💛 |
Thanks for jsonb support 💙 |
This is the updated version of #15195 and #15950 by @pcreux and @chris-teague.
It is tested against postgresql-9.4beta.
Test cases shared between json and jsonb are extracted to a module called
PostgresqlJSONSharedTestCases
. I made my best to minimise the amount of lines impacted by this extraction.