@@ -68,6 +68,9 @@ defmodule DBConnection do
68
68
require Logger
69
69
70
70
alias DBConnection.Holder
71
+
72
+ require Holder
73
+
71
74
defstruct [ :pool_ref , :conn_ref , :conn_mode ]
72
75
73
76
defmodule EncodeError do
@@ -1093,19 +1096,22 @@ defmodule DBConnection do
1093
1096
end
1094
1097
1095
1098
@ doc """
1096
- Returns connection module used by the given connection pool process .
1099
+ Returns connection module used by the given connection pool.
1097
1100
1098
- If the given process is not a connection pool, `:error` is returned .
1101
+ When given a process that is not a connection pool, returns an `:error`.
1099
1102
"""
1100
- @ spec connection_module ( pid ( ) | atom ( ) ) :: { :ok , module ( ) } | :error
1101
- def connection_module ( pool ) when is_pid ( pool ) or is_atom ( pool ) do
1102
- with pid when pid != nil <- GenServer . whereis ( pool ) ,
1103
+ @ spec connection_module ( conn ) :: { :ok , module } | :error
1104
+ def connection_module ( conn ) do
1105
+ with pid when pid != nil <- pool_pid ( conn ) ,
1103
1106
{ :dictionary , dictionary } <- Process . info ( pid , :dictionary ) ,
1104
1107
{ :ok , module } <- fetch_from_dictionary ( dictionary , @ connection_module_key ) ,
1105
1108
do: { :ok , module } ,
1106
1109
else: ( _ -> :error )
1107
1110
end
1108
1111
1112
+ defp pool_pid ( % DBConnection { pool_ref: Holder . pool_ref ( pool: pid ) } ) , do: pid
1113
+ defp pool_pid ( conn ) , do: GenServer . whereis ( conn )
1114
+
1109
1115
defp fetch_from_dictionary ( dictionary , key ) do
1110
1116
Enum . find_value ( dictionary , :error , fn
1111
1117
{ ^ key , value } -> { :ok , value }
0 commit comments