Skip to content
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

Add a native JSON data type support in MySQL #21110

Merged
merged 1 commit into from Aug 18, 2015

Conversation

@kamipo
Copy link
Member

@kamipo kamipo commented Aug 3, 2015

As of MySQL 5.7.8, MySQL supports a native JSON data type.

http://dev.mysql.com/doc/refman/5.7/en/json.html

Example:

create_table :json_data_type do |t|
  t.json :settings
end
@kamipo kamipo force-pushed the kamipo:mysql_json_support branch 6 times, most recently to 44d7786 Aug 3, 2015
@senny senny added the activerecord label Aug 14, 2015
@jeremy
Copy link
Member

@jeremy jeremy commented Aug 15, 2015

👍 nice @kamipo !

@sahin
Copy link

@sahin sahin commented Aug 18, 2015

+1

@@ -2,32 +2,7 @@ module ActiveRecord
module ConnectionAdapters

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 18, 2015
Member

We can remove this whole file and use Type::Json where we used OID::Json

This comment has been minimized.

@kamipo

kamipo Aug 18, 2015
Author Member

OID::Json is a base class of OID::Jsonb.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb#L5
Do I need to change to class Jsonb < Type::Json?

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 18, 2015
Member

Yeah, looks good.

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Aug 18, 2015

Awesome! Just remove the OID class and we can merge it.

@kamipo kamipo force-pushed the kamipo:mysql_json_support branch 4 times, most recently to ca1e4d3 Aug 18, 2015
@kamipo
Copy link
Member Author

@kamipo kamipo commented Aug 18, 2015

Removed OID::Json!

As of MySQL 5.7.8, MySQL supports a native JSON data type.

Example:

    create_table :json_data_type do |t|
      t.json :settings
    end
@kamipo kamipo force-pushed the kamipo:mysql_json_support branch from ca1e4d3 to 89d5d1c Aug 18, 2015
rafaelfranca added a commit that referenced this pull request Aug 18, 2015
Add a native JSON data type support in MySQL
@rafaelfranca rafaelfranca merged commit a316860 into rails:master Aug 18, 2015
@kamipo kamipo deleted the kamipo:mysql_json_support branch Aug 18, 2015
sgrif added a commit that referenced this pull request Aug 21, 2015
Several changes were made in #21110 which I am strongly opposed to.
(this is what I get for going on vacation. :trollface:) No type should
be introduced into the generic `ActiveRecord::Type` namespace, and
*certainly* should not be registered into the registry unconstrained
unless it is supported by *all* adapters (which basically means that it
was specified in the ANSI SQL standard).

I do not think `# :nodoc:` ing the type is sufficient, as it still makes
the code of Rails itself very unclear as to what the role of that class
is. While I would argue that this shouldn't even be a super class, and
that MySql and PG's JSON types are only superficially duplicated (they
might look the same but will change for different reasons in the
future).

However, I don't feel strongly enough about it as a point of contention
(and the biggest cost of harming the blameability has already occured),
so I simply moved the superclass into a namespace where its role is
absolutely clear.

After this change, `attribute :foo, :json` will once again work with
MySQL and PG, but not with Sqlite3 or any third party adapters.

Unresolved questions
--------------------

The types that and adapter publishes (at least those are unique to that
adapter, and not adding additional behavior like `MysqlString` should
probably be part of the adapter's public API. Should we standardize the
namespace for these, and document them?
@NeMO84
Copy link

@NeMO84 NeMO84 commented Dec 22, 2015

Thanks for adding this support!! Is this feature only available in the 5.x versions?

@sgrif
Copy link
Contributor

@sgrif sgrif commented Dec 22, 2015

Yes

@akshah123
Copy link

@akshah123 akshah123 commented Jun 8, 2016

@sgrif are there any plans to add JSON support in 4.x branch? If not, would there be any interest in a PR that does that?

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Jun 8, 2016

No. Like stated in our maintenance policy, new features are no applied to
stable releases.
On qua, 8 de jun de 2016 at 11:28 Ankit Shah notifications@github.com
wrote:

@sgrif https://github.com/sgrif are there any plans to add JSON support
in 4.x branch?


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#21110 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAC66IAsvgFFFQVVyA9GUq0TOAc9L_WBks5qJt-KgaJpZM4Fk0OL
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.