From 555a14badba19720a510d957c70fc263aceb2864 Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Wed, 27 May 2020 10:43:17 +0200 Subject: [PATCH 1/5] Updated db_connection to v2 and made relevant changes to codebase --- lib/grakn.ex | 32 +++++++++++++++++++++++++++++--- lib/grakn/channel.ex | 14 +++++++------- lib/grakn/protocol.ex | 18 ++++++++++++++---- mix.exs | 5 ++--- mix.lock | 8 ++++---- 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/lib/grakn.ex b/lib/grakn.ex index 53e1281..3ea0e6e 100644 --- a/lib/grakn.ex +++ b/lib/grakn.ex @@ -48,6 +48,13 @@ defmodule Grakn do @spec query(conn(), Grakn.Query.t(), Keyword.t()) :: any() def query(conn, query, opts \\ []) do DBConnection.execute(get_conn(conn), query, [], with_transaction_config(opts)) + |> case do + {:ok, _query, result} -> + {:ok, result} + + otherwise -> + otherwise + end end @doc """ @@ -57,11 +64,30 @@ defmodule Grakn do @spec query!(conn(), Grakn.Query.t(), Keyword.t()) :: any() def query!(conn, %Grakn.Query{} = query, opts \\ []) do DBConnection.execute!(get_conn(conn), query, [], with_transaction_config(opts)) + |> case do + {:ok, _query, result} -> + {:ok, result} + + otherwise -> + otherwise + end end @spec command(conn(), Grakn.Command.t(), Keyword.t()) :: any() def command(conn, %Grakn.Command{} = command, opts \\ []) do - DBConnection.execute(get_conn(conn), command, [], with_transaction_config(opts)) + DBConnection.execute( + get_conn(conn), + command, + [], + with_transaction_config(opts) + ) + |> case do + {:ok, _command, result} -> + {:ok, result} + + otherwise -> + otherwise + end end @doc """ @@ -170,14 +196,14 @@ defmodule Grakn do defp with_start_config(opts) do opts |> Keyword.put_new(:pool_size, get_config(:pool_size, 4)) - |> Keyword.put_new(:pool, DBConnection.Poolboy) + |> Keyword.put_new(:pool, DBConnection.ConnectionPool) end defp with_transaction_config(opts) do opts_with_defaults = opts |> Keyword.put_new(:pool_size, get_config(:pool_size, 4)) - |> Keyword.put_new(:pool, DBConnection.Poolboy) + |> Keyword.put_new(:pool, DBConnection.ConnectionPool) |> Keyword.put_new(:pool_timeout, get_config(:pool_timeout, 30_000)) |> Keyword.put_new(:timeout, get_config(:timeout, @default_timeout)) |> Keyword.put_new(:queue, get_config(:queue, true)) diff --git a/lib/grakn/channel.ex b/lib/grakn/channel.ex index 5f05fb6..f8be72a 100644 --- a/lib/grakn/channel.ex +++ b/lib/grakn/channel.ex @@ -93,12 +93,12 @@ defmodule Grakn.Channel do @spec command(t(), Grakn.Command.command(), keyword(), keyword()) :: {:ok, any()} | {:error, any()} - def command(channel, :get_keyspaces, _, opts) do + def command(channel, %Grakn.Command{command: :get_keyspaces} = cmd, _, opts) do request = Keyspace.Keyspace.Retrieve.Req.new() case Keyspace.KeyspaceService.Stub.retrieve(channel, request, opts) do {:ok, %Keyspace.Keyspace.Retrieve.Res{names: names}} -> - {:ok, names} + {:ok, cmd, names} {:error, reason} -> {:error, reason} @@ -108,25 +108,25 @@ defmodule Grakn.Channel do end end - def command(channel, :create_keyspace, [name: name], opts) do + def command(channel, %Grakn.Command{command: :create_keyspace} = cmd, [name: name], opts) do request = Keyspace.Keyspace.Create.Req.new(name: name) case Keyspace.KeyspaceService.Stub.create(channel, request, opts) do - {:ok, %Keyspace.Keyspace.Create.Res{}} -> {:ok, nil} + {:ok, %Keyspace.Keyspace.Create.Res{}} -> {:ok, cmd, nil} error -> error end end - def command(channel, :delete_keyspace, [name: name], opts) do + def command(channel, %Grakn.Command{command: :delete_keyspace} = cmd, [name: name], opts) do request = Keyspace.Keyspace.Delete.Req.new(name: name) case Keyspace.KeyspaceService.Stub.delete(channel, request, opts) do - {:ok, %Keyspace.Keyspace.Delete.Res{}} -> {:ok, nil} + {:ok, %Keyspace.Keyspace.Delete.Res{}} -> {:ok, cmd, nil} error -> error end end - def command(channel, :close_session, [session_id: session_id], opts) do + def command(channel, %Grakn.Command{command: :close_session}, [session_id: session_id], opts) do close_session(channel, session_id, opts) end diff --git a/lib/grakn/protocol.ex b/lib/grakn/protocol.ex index 98d59a7..838d281 100644 --- a/lib/grakn/protocol.ex +++ b/lib/grakn/protocol.ex @@ -77,11 +77,11 @@ defmodule Grakn.Protocol do {:error, Error.exception("Cannot commit if transaction is not open"), state} end - def handle_execute(%{graql: graql}, _params, opts, %{transaction: tx} = state) + def handle_execute(%{graql: graql} = query, _params, opts, %{transaction: tx} = state) when transaction_open?(tx) do case Transaction.query(tx, graql, opts) do {:ok, result} -> - {:ok, result, state} + {:ok, query, result, state} {:error, reason} -> message = @@ -96,9 +96,9 @@ defmodule Grakn.Protocol do {:error, Error.exception("Cannot execute a query before starting a tranaction"), state} end - def handle_execute(%Grakn.Command{command: command, params: params}, _, opts, state) do + def handle_execute(%Grakn.Command{params: params} = cmd, _, opts, state) do state.channel - |> Channel.command(command, params, timeout: opts[:timeout]) + |> Channel.command(cmd, params, timeout: opts[:timeout]) |> handle_result(state) end @@ -120,9 +120,19 @@ defmodule Grakn.Protocol do {:ok, nil, %{state | transaction: nil}} end + @doc """ + DBConnection callback + """ + def handle_status(_, %{transaction_status: status} = state) do + {status, state} + end + defp handle_result({:ok, result}, state), do: {:ok, result, state} + defp handle_result({:ok, _, result}, state), do: {:ok, result, state} defp handle_result({:error, error}, state), do: {error_status(error), error, state} + def ping(state), do: {:ok, state} + defp error_status(%GRPC.RPCError{message: message}) when is_binary(message) do if message =~ ~r/noproc|shutdown/, do: :disconnect, else: :error end diff --git a/mix.exs b/mix.exs index ee0df1a..6b707d0 100644 --- a/mix.exs +++ b/mix.exs @@ -44,15 +44,14 @@ defmodule GraknElixir.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:db_connection, "~> 1.1.0"}, + {:db_connection, "~> 2.2.0"}, {:multix, github: "taxfix/multix"}, {:ex2ms, "~> 1.6"}, - {:poolboy, "~> 1.5.1"}, {:grpc, github: "elixir-grpc/grpc", ref: "6edfd9cb9ce8f19dabd8a3ae68ecd48149d36c2a"}, {:protobuf, "~> 0.5.3"}, {:ex_doc, ">= 0.0.0", only: :dev}, {:earmark, ">= 0.0.0", only: :dev}, - {:dialyxir, "~> 1.0.0-rc.6", only: [:dev], runtime: false}, + {:dialyxir, "~> 1.0.0", only: [:dev], runtime: false}, {:credo, "~> 1.0", only: [:dev, :test], runtime: false}, {:benchee, "~> 0.13", only: :dev} ] diff --git a/mix.lock b/mix.lock index 213094f..ad11fb1 100644 --- a/mix.lock +++ b/mix.lock @@ -5,11 +5,11 @@ "cowboy": {:git, "https://github.com/elixir-grpc/cowboy.git", "db1b09fb06038415e5c643282554c0b9f8e6a976", [tag: "grpc-2.6.3"]}, "cowlib": {:git, "https://github.com/elixir-grpc/cowlib.git", "1cc32e27d917bfe615da6957006fd9f8d6e604bd", [tag: "grpc-2.7.3"]}, "credo": {:hex, :credo, "1.2.2", "f57faf60e0a12b0ba9fd4bad07966057fde162b33496c509b95b027993494aab", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8f2623cd8c895a6f4a55ef10f3fdf6a55a9ca7bef09676bd835551687bf8a740"}, - "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm", "5f0a16a58312a610d5eb0b07506280c65f5137868ad479045f2a2dc4ced80550"}, + "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, "deep_merge": {:hex, :deep_merge, "0.2.0", "c1050fa2edf4848b9f556fba1b75afc66608a4219659e3311d9c9427b5b680b3", [:mix], [], "hexpm", "e3bf435a54ed27b0ba3a01eb117ae017988804e136edcbe8a6a14c310daa966e"}, - "dialyxir": {:hex, :dialyxir, "1.0.0-rc.6", "78e97d9c0ff1b5521dd68041193891aebebce52fc3b93463c0a6806874557d7d", [:mix], [{:erlex, "~> 0.2.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "49496d63267bc1a4614ffd5f67c45d9fc3ea62701a6797975bc98bc156d2763f"}, + "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"}, "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm", "b42a23e9bd92d65d16db2f75553982e58519054095356a418bb8320bbacb58b1"}, - "erlex": {:hex, :erlex, "0.2.4", "23791959df45fe8f01f388c6f7eb733cc361668cbeedd801bf491c55a029917b", [:mix], [], "hexpm", "4a12ebc7cd8f24f2d0fce93d279fa34eb5068e0e885bb841d558c4d83c52c439"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm"}, "ex2ms": {:hex, :ex2ms, "1.6.0", "f39bbd9ff1b0f27b3f707bab2d167066dd8965e7df1149b962d94c74615d0e09", [:mix], [], "hexpm", "0d1ab5e08421af5cd69146efb408dbb1ff77f38a2f4df5f086f2512dc8cf65bf"}, "ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "dc87f778d8260da0189a622f62790f6202af72f2f3dee6e78d91a18dd2fcd137"}, "grpc": {:git, "https://github.com/elixir-grpc/grpc.git", "6edfd9cb9ce8f19dabd8a3ae68ecd48149d36c2a", [ref: "6edfd9cb9ce8f19dabd8a3ae68ecd48149d36c2a"]}, @@ -19,7 +19,7 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, "multix": {:git, "https://github.com/taxfix/multix.git", "43848163fa59033328bee2ea691ab3f3fae71a0a", []}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, - "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm", "8f7168911120e13419e086e78d20e4d1a6776f1eee2411ac9f790af10813389f"}, + "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"}, "protobuf": {:hex, :protobuf, "0.5.4", "2e1b8eec211aff034ad8a14e3674220b0158bfb9a3c7128ac9d2a1ed1b3724d3", [:mix], [], "hexpm", "994348a4592408bc99c132603b0fdb686a2b5df0321a8eb1a582ec2bd3495886"}, "ranch": {:git, "https://github.com/ninenines/ranch", "3190aef88aea04d6dce8545fe9b4574288903f44", [ref: "1.7.1"]}, } From 8c39fef91c8e99b49c0c60a832e661d2faa5796a Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Wed, 27 May 2020 12:16:18 +0200 Subject: [PATCH 2/5] Migrated code base to use db_connection v2 --- lib/grakn/concept/attribute.ex | 7 +++++++ lib/grakn/concept/schema_concept.ex | 21 +++++++++++++++++++++ lib/grakn/concept/thing.ex | 7 +++++++ lib/grakn/protocol.ex | 12 ++++++------ mix.lock | 6 +++--- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib/grakn/concept/attribute.ex b/lib/grakn/concept/attribute.ex index e58f563..e6cf87b 100644 --- a/lib/grakn/concept/attribute.ex +++ b/lib/grakn/concept/attribute.ex @@ -11,6 +11,13 @@ defmodule Grakn.Concept.Attribute do def value(%{id: concept_id} = concept, conn, opts \\ []) do with :ok <- assert_is_attribute(concept) do DBConnection.execute(conn, Action.attribute_value(), [concept_id], opts) + |> case do + {:ok, _query, result} -> + {:ok, result} + + otherwise -> + otherwise + end end end diff --git a/lib/grakn/concept/schema_concept.ex b/lib/grakn/concept/schema_concept.ex index b79b445..4a75cc8 100644 --- a/lib/grakn/concept/schema_concept.ex +++ b/lib/grakn/concept/schema_concept.ex @@ -9,16 +9,37 @@ defmodule Grakn.Concept.SchemaConcept do @spec get(String.t(), DBConnection.t(), keyword()) :: {:ok, Concept.t()} | {:error, any()} def get(label, conn, opts \\ []) do DBConnection.execute(conn, Action.get_schema_concept(), [label], opts) + |> case do + {:ok, _query, result} -> + {:ok, result} + + otherwise -> + otherwise + end end @spec label(Concept.t(), DBConnection.t(), keyword()) :: {:ok, String.t()} | {:error, any()} def label(%{id: concept_id}, conn, opts \\ []) do DBConnection.execute(conn, Action.concept_label(), [concept_id], opts) + |> case do + {:ok, _query, result} -> + {:ok, result} + + otherwise -> + otherwise + end end @spec attribute_types(Concept.t(), DBConnection.t(), keyword()) :: {:ok, [Concept.t()]} | {:error, any()} def attribute_types(%{id: concept_id}, conn, opts \\ []) do DBConnection.execute(conn, Action.get_attribute_types(), [concept_id], opts) + |> case do + {:ok, _query, result} -> + {:ok, result} + + otherwise -> + otherwise + end end end diff --git a/lib/grakn/concept/thing.ex b/lib/grakn/concept/thing.ex index ea58bbb..0be371d 100644 --- a/lib/grakn/concept/thing.ex +++ b/lib/grakn/concept/thing.ex @@ -14,6 +14,13 @@ defmodule Grakn.Concept.Thing do def get_attributes(%{id: concept_id} = concept, attribute_types, conn, opts \\ []) do with :ok <- assert_is_thing(concept) do DBConnection.execute(conn, Action.attributes_by_type(), [concept_id, attribute_types], opts) + |> case do + {:ok, _query, result} -> + {:ok, result} + + otherwise -> + otherwise + end end end diff --git a/lib/grakn/protocol.ex b/lib/grakn/protocol.ex index 838d281..e0951a4 100644 --- a/lib/grakn/protocol.ex +++ b/lib/grakn/protocol.ex @@ -99,17 +99,17 @@ defmodule Grakn.Protocol do def handle_execute(%Grakn.Command{params: params} = cmd, _, opts, state) do state.channel |> Channel.command(cmd, params, timeout: opts[:timeout]) - |> handle_result(state) + |> handle_result(cmd, state) end # Handle internal concept actions - def handle_execute(%Grakn.Concept.Action{name: action_name}, params, _, state) + def handle_execute(%Grakn.Concept.Action{name: action_name} = query, params, _, state) when is_atom(action_name) and is_list(params) do %{transaction: tx} = state Transaction |> apply(action_name, [tx | params]) - |> handle_result(state) + |> handle_result(query, state) end def handle_rollback(_opts, %{transaction: tx} = state) do @@ -127,9 +127,9 @@ defmodule Grakn.Protocol do {status, state} end - defp handle_result({:ok, result}, state), do: {:ok, result, state} - defp handle_result({:ok, _, result}, state), do: {:ok, result, state} - defp handle_result({:error, error}, state), do: {error_status(error), error, state} + defp handle_result({:ok, result}, query, state), do: {:ok, query, result, state} + defp handle_result({:ok, _, result}, query, state), do: {:ok, query, result, state} + defp handle_result({:error, error}, _query, state), do: {error_status(error), error, state} def ping(state), do: {:ok, state} diff --git a/mix.lock b/mix.lock index ad11fb1..0ed6111 100644 --- a/mix.lock +++ b/mix.lock @@ -5,11 +5,11 @@ "cowboy": {:git, "https://github.com/elixir-grpc/cowboy.git", "db1b09fb06038415e5c643282554c0b9f8e6a976", [tag: "grpc-2.6.3"]}, "cowlib": {:git, "https://github.com/elixir-grpc/cowlib.git", "1cc32e27d917bfe615da6957006fd9f8d6e604bd", [tag: "grpc-2.7.3"]}, "credo": {:hex, :credo, "1.2.2", "f57faf60e0a12b0ba9fd4bad07966057fde162b33496c509b95b027993494aab", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8f2623cd8c895a6f4a55ef10f3fdf6a55a9ca7bef09676bd835551687bf8a740"}, - "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, + "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, "deep_merge": {:hex, :deep_merge, "0.2.0", "c1050fa2edf4848b9f556fba1b75afc66608a4219659e3311d9c9427b5b680b3", [:mix], [], "hexpm", "e3bf435a54ed27b0ba3a01eb117ae017988804e136edcbe8a6a14c310daa966e"}, - "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"}, + "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm", "b42a23e9bd92d65d16db2f75553982e58519054095356a418bb8320bbacb58b1"}, - "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex2ms": {:hex, :ex2ms, "1.6.0", "f39bbd9ff1b0f27b3f707bab2d167066dd8965e7df1149b962d94c74615d0e09", [:mix], [], "hexpm", "0d1ab5e08421af5cd69146efb408dbb1ff77f38a2f4df5f086f2512dc8cf65bf"}, "ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "dc87f778d8260da0189a622f62790f6202af72f2f3dee6e78d91a18dd2fcd137"}, "grpc": {:git, "https://github.com/elixir-grpc/grpc.git", "6edfd9cb9ce8f19dabd8a3ae68ecd48149d36c2a", [ref: "6edfd9cb9ce8f19dabd8a3ae68ecd48149d36c2a"]}, From 0d56d0e5f68ddeb25bfe8f0543163b7b75bd1a7c Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Wed, 27 May 2020 12:19:52 +0200 Subject: [PATCH 3/5] updated mix.lock --- mix.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/mix.lock b/mix.lock index 0ed6111..884f147 100644 --- a/mix.lock +++ b/mix.lock @@ -19,7 +19,6 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, "multix": {:git, "https://github.com/taxfix/multix.git", "43848163fa59033328bee2ea691ab3f3fae71a0a", []}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, - "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"}, "protobuf": {:hex, :protobuf, "0.5.4", "2e1b8eec211aff034ad8a14e3674220b0158bfb9a3c7128ac9d2a1ed1b3724d3", [:mix], [], "hexpm", "994348a4592408bc99c132603b0fdb686a2b5df0321a8eb1a582ec2bd3495886"}, "ranch": {:git, "https://github.com/ninenines/ranch", "3190aef88aea04d6dce8545fe9b4574288903f44", [ref: "1.7.1"]}, } From ca1ec974e97217419341772f9e27b44ba7fbfe36 Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Wed, 27 May 2020 12:42:35 +0200 Subject: [PATCH 4/5] Responded to comments and updated dialyzer --- lib/grakn.ex | 28 +++++++--------------------- lib/grakn/channel.ex | 4 ++-- lib/grakn/concept/attribute.ex | 10 +++------- lib/grakn/concept/schema_concept.ex | 9 +++------ lib/grakn/concept/thing.ex | 15 ++++++++------- 5 files changed, 23 insertions(+), 43 deletions(-) diff --git a/lib/grakn.ex b/lib/grakn.ex index 3ea0e6e..f02f70c 100644 --- a/lib/grakn.ex +++ b/lib/grakn.ex @@ -47,13 +47,9 @@ defmodule Grakn do """ @spec query(conn(), Grakn.Query.t(), Keyword.t()) :: any() def query(conn, query, opts \\ []) do - DBConnection.execute(get_conn(conn), query, [], with_transaction_config(opts)) - |> case do - {:ok, _query, result} -> - {:ok, result} - - otherwise -> - otherwise + case DBConnection.execute(get_conn(conn), query, [], with_transaction_config(opts)) do + {:ok, _query, result} -> {:ok, result} + otherwise -> otherwise end end @@ -63,25 +59,15 @@ defmodule Grakn do """ @spec query!(conn(), Grakn.Query.t(), Keyword.t()) :: any() def query!(conn, %Grakn.Query{} = query, opts \\ []) do - DBConnection.execute!(get_conn(conn), query, [], with_transaction_config(opts)) - |> case do - {:ok, _query, result} -> - {:ok, result} - - otherwise -> - otherwise + case DBConnection.execute!(get_conn(conn), query, [], with_transaction_config(opts)) do + {:ok, _query, result} -> {:ok, result} + otherwise -> otherwise end end @spec command(conn(), Grakn.Command.t(), Keyword.t()) :: any() def command(conn, %Grakn.Command{} = command, opts \\ []) do - DBConnection.execute( - get_conn(conn), - command, - [], - with_transaction_config(opts) - ) - |> case do + case DBConnection.execute(get_conn(conn), command, [], with_transaction_config(opts)) do {:ok, _command, result} -> {:ok, result} diff --git a/lib/grakn/channel.ex b/lib/grakn/channel.ex index f8be72a..fc76895 100644 --- a/lib/grakn/channel.ex +++ b/lib/grakn/channel.ex @@ -91,8 +91,8 @@ defmodule Grakn.Channel do end end - @spec command(t(), Grakn.Command.command(), keyword(), keyword()) :: - {:ok, any()} | {:error, any()} + @spec command(t(), %Grakn.Command{}, keyword(), keyword()) :: + {:ok, %Grakn.Command{}, any()} | {:error, any()} def command(channel, %Grakn.Command{command: :get_keyspaces} = cmd, _, opts) do request = Keyspace.Keyspace.Retrieve.Req.new() diff --git a/lib/grakn/concept/attribute.ex b/lib/grakn/concept/attribute.ex index e6cf87b..91e2ed3 100644 --- a/lib/grakn/concept/attribute.ex +++ b/lib/grakn/concept/attribute.ex @@ -10,13 +10,9 @@ defmodule Grakn.Concept.Attribute do @spec value(Concept.t(), DBConnection.t()) :: {:ok, any()} | {:error, any()} def value(%{id: concept_id} = concept, conn, opts \\ []) do with :ok <- assert_is_attribute(concept) do - DBConnection.execute(conn, Action.attribute_value(), [concept_id], opts) - |> case do - {:ok, _query, result} -> - {:ok, result} - - otherwise -> - otherwise + case DBConnection.execute(conn, Action.attribute_value(), [concept_id], opts) do + {:ok, _query, result} -> {:ok, result} + otherwise -> otherwise end end end diff --git a/lib/grakn/concept/schema_concept.ex b/lib/grakn/concept/schema_concept.ex index 4a75cc8..14114f1 100644 --- a/lib/grakn/concept/schema_concept.ex +++ b/lib/grakn/concept/schema_concept.ex @@ -8,8 +8,7 @@ defmodule Grakn.Concept.SchemaConcept do @spec get(String.t(), DBConnection.t(), keyword()) :: {:ok, Concept.t()} | {:error, any()} def get(label, conn, opts \\ []) do - DBConnection.execute(conn, Action.get_schema_concept(), [label], opts) - |> case do + case DBConnection.execute(conn, Action.get_schema_concept(), [label], opts) do {:ok, _query, result} -> {:ok, result} @@ -20,8 +19,7 @@ defmodule Grakn.Concept.SchemaConcept do @spec label(Concept.t(), DBConnection.t(), keyword()) :: {:ok, String.t()} | {:error, any()} def label(%{id: concept_id}, conn, opts \\ []) do - DBConnection.execute(conn, Action.concept_label(), [concept_id], opts) - |> case do + case DBConnection.execute(conn, Action.concept_label(), [concept_id], opts) do {:ok, _query, result} -> {:ok, result} @@ -33,8 +31,7 @@ defmodule Grakn.Concept.SchemaConcept do @spec attribute_types(Concept.t(), DBConnection.t(), keyword()) :: {:ok, [Concept.t()]} | {:error, any()} def attribute_types(%{id: concept_id}, conn, opts \\ []) do - DBConnection.execute(conn, Action.get_attribute_types(), [concept_id], opts) - |> case do + case DBConnection.execute(conn, Action.get_attribute_types(), [concept_id], opts) do {:ok, _query, result} -> {:ok, result} diff --git a/lib/grakn/concept/thing.ex b/lib/grakn/concept/thing.ex index 0be371d..6db1c8f 100644 --- a/lib/grakn/concept/thing.ex +++ b/lib/grakn/concept/thing.ex @@ -13,13 +13,14 @@ defmodule Grakn.Concept.Thing do {:ok, any()} | {:error, any()} def get_attributes(%{id: concept_id} = concept, attribute_types, conn, opts \\ []) do with :ok <- assert_is_thing(concept) do - DBConnection.execute(conn, Action.attributes_by_type(), [concept_id, attribute_types], opts) - |> case do - {:ok, _query, result} -> - {:ok, result} - - otherwise -> - otherwise + case DBConnection.execute( + conn, + Action.attributes_by_type(), + [concept_id, attribute_types], + opts + ) do + {:ok, _query, result} -> {:ok, result} + otherwise -> otherwise end end end From 76aecd52a7bc3063782895ff43d309a1c3bec337 Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Wed, 27 May 2020 12:59:47 +0200 Subject: [PATCH 5/5] Resolved dialyzer issues --- lib/grakn/protocol.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/grakn/protocol.ex b/lib/grakn/protocol.ex index e0951a4..28a9b31 100644 --- a/lib/grakn/protocol.ex +++ b/lib/grakn/protocol.ex @@ -127,6 +127,21 @@ defmodule Grakn.Protocol do {status, state} end + @impl DBConnection + def handle_prepare(query, opts, state), do: {:ok, query, state} + + @impl DBConnection + def handle_fetch(query, cursor, opts, state), do: {:cont, "", state} + + @impl DBConnection + def handle_declare(query, params, opt, state), do: {:ok, query, "", state} + + @impl DBConnection + def handle_deallocate(query, cursor, opts, state), do: {:ok, "", state} + + @impl DBConnection + def handle_close(query, opts, state), do: {:ok, "", state} + defp handle_result({:ok, result}, query, state), do: {:ok, query, result, state} defp handle_result({:ok, _, result}, query, state), do: {:ok, query, result, state} defp handle_result({:error, error}, _query, state), do: {error_status(error), error, state}