@@ -85,6 +85,7 @@ defmodule Postgrex.Protocol do
85
85
disconnect_on_error_codes = opts [ :disconnect_on_error_codes ] || [ ]
86
86
target_server_type = opts [ :target_server_type ] || :any
87
87
disable_composite_types = opts [ :disable_composite_types ] || false
88
+ parameters = opts [ :parameters ] || [ ]
88
89
89
90
{ ssl_opts , opts } =
90
91
case Keyword . pop ( opts , :ssl , false ) do
@@ -116,6 +117,25 @@ defmodule Postgrex.Protocol do
116
117
:unnamed -> :unnamed
117
118
end
118
119
120
+ parameters =
121
+ case opts [ :search_path ] do
122
+ path when is_list ( path ) ->
123
+ Logger . warning (
124
+ "the `:search_path` option is deprecated. Please use the `:parameters` option by " <>
125
+ "passing `:search_path` as a key and a comma delimited string as the value."
126
+ )
127
+
128
+ path = Enum . intersperse ( path , ", " )
129
+ Keyword . put ( parameters , :search_path , path )
130
+
131
+ nil ->
132
+ parameters
133
+
134
+ other ->
135
+ raise ArgumentError ,
136
+ "expected :search_path to be a list of strings, got: #{ inspect ( other ) } "
137
+ end
138
+
119
139
s = % __MODULE__ {
120
140
timeout: timeout ,
121
141
ping_timeout: ping_timeout ,
@@ -128,15 +148,14 @@ defmodule Postgrex.Protocol do
128
148
connect_timeout = Keyword . get ( opts , :connect_timeout , timeout )
129
149
130
150
status = % {
131
- opts: opts ,
151
+ opts: Keyword . put ( opts , :parameters , parameters ) ,
132
152
types_mod: types_mod ,
133
153
types_key: nil ,
134
154
types_lock: nil ,
135
155
prepare: prepare ,
136
156
messages: [ ] ,
137
157
ssl: ssl_opts ,
138
- target_server_type: target_server_type ,
139
- search_path: opts [ :search_path ]
158
+ target_server_type: target_server_type
140
159
}
141
160
142
161
connect_endpoints ( endpoints , sock_opts ++ @ sock_opts , connect_timeout , s , status , [ ] )
@@ -916,7 +935,7 @@ defmodule Postgrex.Protocol do
916
935
init_recv ( % { s | connection_id: pid , connection_key: key } , status , buffer )
917
936
918
937
{ :ok , msg_ready ( ) , buffer } ->
919
- set_search_path ( s , status , buffer )
938
+ check_target_server_type ( s , status , buffer )
920
939
921
940
{ :ok , msg_error ( fields: fields ) , buffer } ->
922
941
disconnect ( s , Postgrex.Error . exception ( postgres: fields ) , buffer )
@@ -930,68 +949,6 @@ defmodule Postgrex.Protocol do
930
949
end
931
950
end
932
951
933
- ## set search path on connection startup
934
-
935
- defp set_search_path ( s , % { search_path: nil } = status , buffer ) ,
936
- do: set_search_path_done ( s , status , buffer )
937
-
938
- defp set_search_path ( s , % { search_path: search_path } = status , buffer )
939
- when is_list ( search_path ) ,
940
- do: set_search_path_send ( s , status , buffer )
941
-
942
- defp set_search_path ( _ , % { search_path: search_path } , _ ) do
943
- raise ArgumentError ,
944
- "expected :search_path to be a list of strings, got: #{ inspect ( search_path ) } "
945
- end
946
-
947
- defp set_search_path_send ( s , status , buffer ) do
948
- search_path = Enum . intersperse ( status . search_path , "," )
949
- msg = msg_query ( statement: [ "set search_path to " | search_path ] )
950
-
951
- case msg_send ( s , msg , buffer ) do
952
- :ok ->
953
- set_search_path_recv ( s , status , buffer )
954
-
955
- { :disconnect , _ , _ } = dis ->
956
- dis
957
- end
958
- end
959
-
960
- defp set_search_path_recv ( s , status , buffer ) do
961
- case msg_recv ( s , :infinity , buffer ) do
962
- { :ok , msg_row_desc ( fields: fields ) , buffer } ->
963
- { [ @ text_type_oid ] , [ "search_path" ] , _ } = columns ( fields )
964
- set_search_path_recv ( s , status , buffer )
965
-
966
- { :ok , msg_data_row ( ) , buffer } ->
967
- set_search_path_recv ( s , status , buffer )
968
-
969
- { :ok , msg_command_complete ( ) , buffer } ->
970
- set_search_path_recv ( s , status , buffer )
971
-
972
- { :ok , msg_ready ( status: :idle ) , buffer } ->
973
- set_search_path_done ( s , status , buffer )
974
-
975
- { :ok , msg_ready ( status: postgres ) , _buffer } ->
976
- err = % Postgrex.Error { message: "unexpected postgres status: #{ postgres } " }
977
- { :disconnect , err , s }
978
-
979
- { :ok , msg_error ( fields: fields ) , buffer } ->
980
- err = Postgrex.Error . exception ( postgres: fields )
981
- { :disconnect , err , % { s | buffer: buffer } }
982
-
983
- { :ok , msg , buffer } ->
984
- s = handle_msg ( s , status , msg )
985
- set_search_path_recv ( s , status , buffer )
986
-
987
- { :disconnect , _ , _ } = dis ->
988
- dis
989
- end
990
- end
991
-
992
- defp set_search_path_done ( s , status , buffer ) ,
993
- do: check_target_server_type ( s , status , buffer )
994
-
995
952
## check_target_server_type
996
953
997
954
defp check_target_server_type ( s , % { target_server_type: :any } = status , buffer ) ,
0 commit comments