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 json column support mysql(5.7~) #201

Merged
merged 11 commits into from
Nov 8, 2017

Conversation

hashijun
Copy link
Contributor

fixes #119 . (This pull request is re-creation for #176 .)

Encode and decode library for json can choose by opts[:json_library] (Default set to Poison).

@coveralls
Copy link

coveralls commented Oct 17, 2017

Coverage Status

Coverage decreased (-0.2%) to 65.854% when pulling decc63a on hashijun:work/add_json_support_on_v0.8.3 into 59d7ae0 on xerions:master.

Copy link
Contributor

@fishcakez fishcakez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I added a few comments to tidy up some minor details.

It's unfortunate that can't encode a parameter as JSON. I imagine this is the same scenario as #198 (comment), where we would need to use types sent by the database on prepare. I have not got to looking at that yet but perhaps someone else will before I get chance.

mix.exs Outdated
@@ -22,7 +22,8 @@ defmodule Mariaex.Mixfile do
[{:decimal, "~> 1.0"},
{:db_connection, "~> 1.1"},
{:coverex, "~> 1.4.10", only: :test},
{:ex_doc, ">= 0.0.0", only: :dev}]
{:ex_doc, ">= 0.0.0", only: :dev},
{:poison, "~> 2.1", optional: true}]
Copy link
Contributor

@fishcakez fishcakez Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set version as >= 0.0.0 to prevent overrides being required. Many users will be on either ~>2.0 or ~> 3.0 and perhaps soon ~> 4.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing consideration. I fixed via 0a88aea .

@@ -83,4 +101,13 @@ defmodule TextQueryTest do
{:ok, %{rows: rows}} = Mariaex.query(pid, "SELECT dt FROM test_text_query_table", [], query_type: :text)
assert(rows == [[{{1,1,1}, {0,0,0,0}}], [{{1,1,1}, {0,0,1,0}}]])
end

if System.get_env("JSON_SUPPORT") === "true" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use @tag to skip tests so we can see when tests are skipped, and it allows more flexibility when testing outside CI. This can be done by adding @tag :json to the test and exclude: [json: System.get_env("JSON_SUPPORT") != "true"] to the ExUnit.start/1 call in test/test_helper.exs.

Any setup can be done in the test as there is only a single test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed via cb8a783 .

@@ -76,6 +77,7 @@ defmodule Mariaex.Protocol do
connect_opts = [host, opts[:port], opts[:socket_options], opts[:timeout]]
binary_as = opts[:binary_as] || :field_type_var_string
datetime = opts[:datetime] || :structs
json_library = opts[:json_library] || Poison
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please allow setting the default value via Application.get_env so json library can be set in one place, with the default (Poison) set in the mix.exs :env entry.

Copy link
Contributor Author

@hashijun hashijun Oct 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed via f5703b2 .

@@ -685,4 +685,21 @@ defmodule QueryTest do
assert :ok = query("REPLACE INTO test_replace VALUES (1, 'Old', '2014-08-20 18:47:00');", [])
assert :ok = query("REPLACE INTO test_replace VALUES (1, 'New', ?);", [timestamp])
end

if System.get_env("JSON_SUPPORT") === "true" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See text_query_test.exs comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed via cb8a783 .

@hashijun
Copy link
Contributor Author

@fishcakez

Thanks for your comment! I'll fix my code based on review.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 65.854% when pulling f5703b2 on hashijun:work/add_json_support_on_v0.8.3 into 59d7ae0 on xerions:master.

1 similar comment
@coveralls
Copy link

coveralls commented Oct 22, 2017

Coverage Status

Coverage decreased (-0.2%) to 65.854% when pulling f5703b2 on hashijun:work/add_json_support_on_v0.8.3 into 59d7ae0 on xerions:master.

@hashijun
Copy link
Contributor Author

hashijun commented Nov 3, 2017

@fishcakez

I fixed my changeset based on your review. Is there anything to improve?

@mgwidmann
Copy link

waiting on this to release 👍

@fishcakez
Copy link
Contributor

@hashijun I think you addressed my points nicely but I am not a maintainer of this repo, and am unsure how I feel about supporting JSON in rows but not in parameters.

@liveforeverx liveforeverx merged commit 9b99297 into xerions:master Nov 8, 2017
@liveforeverx
Copy link
Member

Thank you! @hashijun and @fishcakez

@hashijun hashijun deleted the work/add_json_support_on_v0.8.3 branch November 9, 2017 01:21
@m-koepke
Copy link

m-koepke commented Nov 9, 2017

@hashijun How would writing the JSON work? If I understand correctly I need to pass an already JSON encoded String? The original PR also supported encoding JSON: https://github.com/xerions/mariaex/pull/197/files#diff-cd3b88763eeb706bf700cab0689dc94cR103

@hashijun
Copy link
Contributor Author

@m-koepke That would be further problem (also noted in #204). I'll try in the near future, but it's advanced task so it may take long time.

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

Successfully merging this pull request may close these issues.

Support for JSON data type
6 participants