Skip to content

Commit fff14a4

Browse files
committed
refactor the dbconnection behaviour module
1 parent 3c10b37 commit fff14a4

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

lib/mongo.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ defmodule Mongo do
15041504
{:ok, BSON.document() | nil} | {:error, Mongo.Error.t()}
15051505
def exec_command_session(session, cmd, opts) do
15061506
with {:ok, conn, new_cmd} <- Session.bind_session(session, cmd),
1507-
{:ok, _cmd, response} <- DBConnection.execute(conn, %Query{action: :command}, [new_cmd], defaults(opts)),
1507+
{:ok, _cmd, response} <- DBConnection.execute(conn, %Query{action: {:command, new_cmd}}, [], defaults(opts)),
15081508
:ok <- Session.update_session(session, response, opts),
15091509
{:ok, {_flags, doc}} <- check_for_error(response, cmd, opts) do
15101510
{:ok, doc}
@@ -1518,7 +1518,7 @@ defmodule Mongo do
15181518
@spec exec_command(GenServer.server(), BSON.document(), Keyword.t()) ::
15191519
{:ok, {any(), BSON.document()} | nil} | {:error, Mongo.Error.t()}
15201520
def exec_command(conn, cmd, opts) do
1521-
with {:ok, _cmd, response} <- DBConnection.execute(conn, %Query{action: :command}, [cmd], defaults(opts)) do
1521+
with {:ok, _cmd, response} <- DBConnection.execute(conn, %Query{action: {:command, cmd}}, [], defaults(opts)) do
15221522
check_for_error(response, cmd, opts)
15231523
end
15241524
end
@@ -1536,7 +1536,7 @@ defmodule Mongo do
15361536
end
15371537

15381538
def exec_more_to_come(conn, opts) do
1539-
with {:ok, _cmd, response} <- DBConnection.execute(conn, %Query{action: :command}, [:more_to_come], defaults(opts)) do
1539+
with {:ok, _cmd, response} <- DBConnection.execute(conn, %Query{action: :more_to_come}, [], defaults(opts)) do
15401540
check_for_error(response, [:more_to_come], opts)
15411541
end
15421542
end

lib/mongo/event_handler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule Mongo.EventHandler do
2424

2525
def listen(opts) do
2626
receive do
27-
{:broadcast, :commands, %{command_name: cmd} = message} when cmd != :isMaster && cmd != :hello ->
27+
{:broadcast, :commands, %{command_name: cmd} = message} when cmd != :isMaster and cmd != :hello ->
2828
Logger.info("Received command: " <> inspect(message))
2929
listen(opts)
3030

lib/mongo/mongo_db_connection.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ defmodule Mongo.MongoDBConnection do
9595
end
9696

9797
@impl true
98-
def handle_execute(%Mongo.Query{action: action} = query, params, opts, original_state) do
98+
def handle_execute(%Mongo.Query{action: action} = query, _params, opts, original_state) do
9999
tmp_state = %{original_state | database: Keyword.get(opts, :database, original_state.database)}
100100

101-
with {:ok, reply, tmp_state} <- execute_action(action, params, opts, tmp_state) do
101+
with {:ok, reply, tmp_state} <- send_command(action, opts, tmp_state) do
102102
{:ok, query, reply, Map.put(tmp_state, :database, original_state.database)}
103103
end
104104
end
@@ -264,7 +264,7 @@ defmodule Mongo.MongoDBConnection do
264264
##
265265
# Executes a hello or the legacy hello command
266266
##
267-
defp execute_action({:exec_hello, cmd}, _params, opts, %{use_op_msg: true} = state) do
267+
defp send_command({:exec_hello, cmd}, opts, %{use_op_msg: true} = state) do
268268
db = opts[:database] || state.database
269269
timeout = Keyword.get(opts, :timeout, state.timeout)
270270
flags = Keyword.get(opts, :flags, 0x0)
@@ -297,7 +297,7 @@ defmodule Mongo.MongoDBConnection do
297297
##
298298
# Executes a more to come command
299299
##
300-
defp execute_action(:command, [:more_to_come], opts, %{use_op_msg: true} = state) do
300+
defp send_command(:more_to_come, opts, %{use_op_msg: true} = state) do
301301
event = %MoreToComeEvent{command: :more_to_come, command_name: opts[:command_name] || :more_to_come}
302302

303303
timeout = Keyword.get(opts, :timeout, state.timeout)
@@ -313,7 +313,7 @@ defmodule Mongo.MongoDBConnection do
313313
end
314314
end
315315

316-
defp execute_action(:command, [cmd], opts, %{use_op_msg: true} = state) do
316+
defp send_command({:command, cmd}, opts, %{use_op_msg: true} = state) do
317317
{command_name, data} = provide_cmd_data(cmd)
318318
db = opts[:database] || state.database
319319
cmd = cmd ++ ["$db": db]
@@ -350,7 +350,7 @@ defmodule Mongo.MongoDBConnection do
350350
end
351351
end
352352

353-
defp execute_action(:command, [cmd], opts, state) do
353+
defp send_command({:command, cmd}, opts, state) do
354354
[{command_name, _} | _] = cmd
355355

356356
event = %CommandStartedEvent{
@@ -376,7 +376,7 @@ defmodule Mongo.MongoDBConnection do
376376
end
377377
end
378378

379-
defp execute_action(:error, _query, _opts, state) do
379+
defp send_command(:error, _opts, state) do
380380
exception = Mongo.Error.exception("Test-case")
381381
{:disconnect, exception, state}
382382
end

0 commit comments

Comments
 (0)