From f5703b22150126a2bd9c02e23fc49bd8dd6eb67e Mon Sep 17 00:00:00 2001 From: Jun Hashimoto Date: Sun, 22 Oct 2017 15:02:38 +0900 Subject: [PATCH] fix to assign json_library via Application env --- README.md | 10 ++++++++++ lib/mariaex.ex | 1 - lib/mariaex/protocol.ex | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8be3a2b..ee80d34 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,13 @@ After you are done, run `mix deps.get` in your shell to fetch and compile Mariae Important configuration, which depends on used charset for support unicode chars, see `:binary_as` in `Mariaex.start_link/1` + +### JSON library + +As default, [Poison](https://github.com/devinus/poison) is used for JSON library in mariaex to support JSON column. + +If you want to use another library, please set `config.exs` like below. + +```elixir +config :mariaex, json_library: SomeLibrary +``` diff --git a/lib/mariaex.ex b/lib/mariaex.ex index 8ba66b9..9869f5a 100644 --- a/lib/mariaex.ex +++ b/lib/mariaex.ex @@ -66,7 +66,6 @@ defmodule Mariaex do in `GenServer.start_link/3`). * `:datetime` - How datetimes should be returned. `:structs` for Elixir v1.3 calendar types or `:tuples` for the backwards compatible tuples - * `:json_library` - JSON Library to parse json column. (default: `Poison`) ## Function signatures diff --git a/lib/mariaex/protocol.ex b/lib/mariaex/protocol.ex index 6a42dc5..50619ec 100644 --- a/lib/mariaex/protocol.ex +++ b/lib/mariaex/protocol.ex @@ -77,7 +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 + json_library = Application.get_env(:mariaex, :json_library, Poison) case apply(sock_mod, :connect, connect_opts) do {:ok, sock} ->