@@ -85,6 +85,7 @@ defmodule Postgrex.Protocol do
8585 disconnect_on_error_codes = opts [ :disconnect_on_error_codes ] || [ ]
8686 target_server_type = opts [ :target_server_type ] || :any
8787 disable_composite_types = opts [ :disable_composite_types ] || false
88+ parameters = opts [ :parameters ] || [ ]
8889
8990 { ssl_opts , opts } =
9091 case Keyword . pop ( opts , :ssl , false ) do
@@ -116,6 +117,25 @@ defmodule Postgrex.Protocol do
116117 :unnamed -> :unnamed
117118 end
118119
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+
119139 s = % __MODULE__ {
120140 timeout: timeout ,
121141 ping_timeout: ping_timeout ,
@@ -128,15 +148,14 @@ defmodule Postgrex.Protocol do
128148 connect_timeout = Keyword . get ( opts , :connect_timeout , timeout )
129149
130150 status = % {
131- opts: opts ,
151+ opts: Keyword . put ( opts , :parameters , parameters ) ,
132152 types_mod: types_mod ,
133153 types_key: nil ,
134154 types_lock: nil ,
135155 prepare: prepare ,
136156 messages: [ ] ,
137157 ssl: ssl_opts ,
138- target_server_type: target_server_type ,
139- search_path: opts [ :search_path ]
158+ target_server_type: target_server_type
140159 }
141160
142161 connect_endpoints ( endpoints , sock_opts ++ @ sock_opts , connect_timeout , s , status , [ ] )
@@ -916,7 +935,7 @@ defmodule Postgrex.Protocol do
916935 init_recv ( % { s | connection_id: pid , connection_key: key } , status , buffer )
917936
918937 { :ok , msg_ready ( ) , buffer } ->
919- set_search_path ( s , status , buffer )
938+ check_target_server_type ( s , status , buffer )
920939
921940 { :ok , msg_error ( fields: fields ) , buffer } ->
922941 disconnect ( s , Postgrex.Error . exception ( postgres: fields ) , buffer )
@@ -930,68 +949,6 @@ defmodule Postgrex.Protocol do
930949 end
931950 end
932951
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-
995952 ## check_target_server_type
996953
997954 defp check_target_server_type ( s , % { target_server_type: :any } = status , buffer ) ,
0 commit comments